Programming Techniques 3

  • Uploaded by: rvasu8
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Programming Techniques 3 as PDF for free.

More details

  • Words: 4,571
  • Pages: 120
DEVELOPMENT OF PROGRAMMING LANGUAGES MACHINE LANGUAGE PROGRAMS ASSEMBLY LANGUAGES HIGH LEVEL LANGUAGES 1. FORTRAN 1952 2. COBOL 1953 3. BASIC 1965 4. PASCAL 1976 5. C 1977 SPECIAL PURPOSE SOFTWARES WORDSTAR SPREAD SHEETS DATA BASES DESK TOP PUBLICATION AUTOCAD

MACROS CAMCORDER IMAGE PROCESSING OPTICAL CHARACTER RECOGNITION OPTICAL MARK READER IMAGE ENHANCEMENTS DIGITAL PHOTOGRAPHS VOICE RECOGNITION ENTERPRISE RESOURCE PLANNING PROGRAMMING LOGIC CONTROLLERS DISTRIBUTED CONTROL SYSTEMS MICRO PROCESSORSz

SPECIAL PURPOSE SOFTWARES PAINT POWER POINT PRESENTATION VISUAL BASIC WINDOWS PROGRAMMING INTERNET HTML WEB DESIGN JAVA PICTURES ( JPG, BMP, GIF, TIF ) SOUNDS ANIMATION, FLASH VIDEOS OBJECT LINKED ENVIRONMENT

. Net Open sourcing Linux jsp Snagit

FACILITIES OF A PROGRAMMING LANGUAGE HEADER DECLARATIONS VARIABLES , ARRAYS CALCULATIONS STORED INSTRUCTIONS (PROGRAMS ) DECISION (IF, DO CASE ) LOOPS ( FOR, DO WHILE ) FUCTIONS SUBROUTINES

PROGRAMMING TECHNIQUES 1. SUMMATION TECHNIQUE 2. PRODUCT TECHNIQUE 3. INTERCHANGE TECHNIQUE 4. QUOTIENT 5. REMINDER 6. DIVISIBILITY 7. ROUNDING TO 3 DIGIT ACCURACY

8.

ISOLATING THE LAST DIGIT

9.

ISOLATING THE FIRST DIGIT

10. ISOLATING THE LAST CHARACTER 11. ISOLATING THE FIRST CHARACTER 12. ADDING THE DIGIT TO THE REAR 13. ADDING THE DIGIT TO THE FRONT 14. ADDING THE CHARACTER TO THE REAR 15. ADDING THE CHARACTER TO THE FRONT

16. REVERSING THE STRINGS, ARRAYS, 17. TRANSPOSE OF 2 DIMENSIONAL ARRAY 18. FINDING THE MAXIMUM / MINIMUM 19. SORTING 20. MERGING 21. SEARCHING 22. FORCEFUL ADDITIONS 23. SERIES IDENTIFICTION 23. SERIES SUMMATION ( SIN ) 24. STARS & TABLES 25. RANDOM NUMBERS 26. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

27. PRE ASSIGNMENT 28. CHANGING CENTURY 29. SELF INDEXING AND CUMULATING 30. SIMPLIFIED DATA ENTRY 31. CORRECTING THE ENTERED DATA 32. PROGRAMMING S001, S002, S003 (1000+N) 33. UNIQUE NUMBER BUILDING SYSTEM 34. NARROWED DOWN SEARCH PROGRAM 35. APPLICATION OF DEMORGANS LAW

PROGRAMMING TECHNIQUES 1. SUMMATION TECHNIQUE 2. PRODUCT TECHNIQUE 3. INTERCHANGE TECHNIQUE

1.SUMMATION TECHNIQUES FIND THE NUMBER OF STUDENTS SECURING FAIL MARKS M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8)

= = = = = = = =

50 70 23 87 76 68 12 90

1.SUMMATION TECHNIQUES FIND THE SUM OF THE MARKS SECURED BY THE STUDENTS SECURING PASS MARKS and also their number M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8)

= = = = = = = =

50 70 23 87 76 68 12 90

PASSMARKS = 35 SUM = 0 nopass=0 FOR I = 1 TO 8 IF M(I) >= PASSMARKS SUM = SUM + M(I) nopass=nopass+1 ENDIF NEXT I PRINT “ TOTAL MARKS = ” ; SUM

SUMMATION TECHNIQUE IS USED BOTH FOR 1. COUNTING 2. SUMMING HAVING 1. SOME CONDITIONS 2. WITH NO CONDITIONS

FIND THE NUMBER OF VOWELS IN THE FOLLOWOING SENTENCE “ A KNOWLEDGE OF COMPUTER USAGE IS HIGHLY DESIRABLE FOR STUDENTS OF ALL DISCIPLINES ”

novovel=0 st=“ A KNOWLEDGE OF COMPUTER USAGE IS HIGHLY DESIRABLE FOR STUDENTS OF ALL DISCIPLINES ” ll = len(st) for j= 1 to ll alp= substr(st, j, 1 ) if alp=“A” or alp=“E” or alp=“I” or alp=“O” or alp=“U” novovel=novovel+1 endif next j ? “no of vovels =” , novovel

INTEGRATE X^2 – 3*X +7 BETWEEN THE LIMITS X=1 AND X=3 X^3 / 3 - 3*X^2 /2 + 7*X + C (9 – 13.5 + 21 +C ) - (1/3 – 3/2 + 7 + C )

(AT X =3) (AT X = 1 )

(16.5 + C ) - (5.8333 + C) = 10.6667

y1

y2 delta

1

3

AREA OF TRAPHEZIUM = ( Y1 + Y2 ) / 2 * DELTA

/* INTEGRATION */ #include <stdio.h> void main() { int n; float ul, ll,delta,x1,y1,x2,y2,sum,func(); clrscr(); sum = 0; ul = 3; ll = 1; delta = (ul - ll)/100; x1 = ll; y1 = func(x1);

}

for(n=1; n<=100; n++) { x2=x1+delta; y2= func(x2); sum=sum + (y1 + y2 )/2 * delta; x1 = x2; y1 = y2; } printf("The integral between the limits %g and %g is %g ", ul,ll,sum ); getch();

float func ( x ) float x; { return ( x * x - 3 * x +7 ); }

AREA AS PER INTEGRATION FORMULA 10.6667 AREA AS PER SUMMATION OF TRAPHEZIUMS 10.6668

2.PRODUCT TECHNIQUE FIND FACTORIAL 7 1*2*3*4*5*6*7

F=1 FOR J = 1 TO 7 F=F*J NEXT J PRINT “FACTORIAL =” ; F

3. INTERCHANGE TECHNIQUE A GLASS TUMBLER CONTAINS MANGO JUICE A STEEL TUMBLER HAS APPLE JUICE I WANT MANGO JUICE IN STEEL TUMBLER AND THE APPLE JUICE IN GLASS TUMBLER. HOW TO ACHIEVE THAT ?

A=5 B=3 A=B B=A A = B (A IS ASSIGNED THE VALUE OF B – 3 LATEST VALUE OF A IS 3 AND THE VALUE OF B WAS NOT CHANGED , (3) B=A

A=5 B=3 T=A A=B B=T

SAW TOOTH INTERCHANGE

A B C D

= = = =

9 6 7 8

A B C D

TO TO TO TO

X=A A=B B=C C=D D=X

A GET GET GET GET

B’S C’S D’S A’S

VALUE VALUE VALUE VALUE

6 7 D 8 8 9

9 6B 7 C

TO INTERCHANGE A & B WITHOUT USING T A=5 B=3 Start with + A B A B A

= = = = =

5 3 A +B A–B A–B

A 5 B 3

8 5 3 8 5

3

A=5 B=3 You can start with – or * A B A B A

= = = = =

5 3 A-B A+B B–A

A 5 B 3

2 5

3 2 5

3

A=5 B=3 Start with * A B A B A

= = = = =

5 3 A*B A/B A/B

A 5 B 3

15 5

3 15 5

3

A=5 B=3 You cannot begin truncation error A=5 B=3 A=A/B B=A*B A=B/A

with / due to 1.66666 4.99999 3

A 5 1.6666 3 B 3 4.9999 B is 4.9999 instead of 5. Hence Never start with / You can start with +, -, *

PROGRAMMING TECHNIQUES 1. SUMMATION TECHNIQUE 2. PRODUCT TECHNIQUE 3. INTERCHANGE TECHNIQUE 4. QUOTIENT 5. REMINDER 6. DIVISIBILITY 7. ROUNDING TO 3 DIGIT ACCURACY

4. QUOTIENT 23/10 quotient 2 Remainder 3 A/B Quotient = int (A/B) Some languages may have div function (Pascal) Some may have integer div function A/B ( ‘C’ language) All languages will have int function

5. REMINDER 23/10

quotient 2 ,

remainder 3 R (A/B) = A – int(A/B)*B Some may have mod(A/B) Or A % B (modulo of Division)

6. DIVISIBILITY Is 47 divisible by 10 ? Technique 1 Is the remainder Zero ? If mod(47/10)=0 If (47 % 10)=0 If 47 – int(47/10)* 10 = 0 Better Technique 2 If ( A/B) = int (A/B)

6. DIVISIBILITY After printing every 5 names to leave a blank line for i=1 to 100 print name(i) if (i/5) = int(i/5) Print endif next i

6. DIVISIBILITY To find whether 47 is prime If any number 2 to 46 (upto n1) divides then not a prime A better technique If any number 2 to sqrt(47) divides then not a prime ( 2 to 6 = 5 numbers instead of 2 to 46 (45) numbers )

7. ROUNDING TO 3 DIGIT ACCURACY Round off to nearest digit ( not truncate) 3.4 3 3.7 4 Int (x+0.5) Int(3.9) = 3 Int (4.2) = 4

7. ROUNDING TO 3 DIGIT ACCURACY Round off to 3 digit accuracy 3.4123578 3.412 3.7865432 3.787 Int (x*10^3 + 0.5) 3412.8578 = 3412 3787.0432 = 3787 Int (x*10^3 + 0.5)/ 10^3 For n digit accuracy Int (x*10^n) / 10^n

7. ROUNDING TO nearest 100 Rs 478523 = 478500 478583 = 478600 Int( x*10^(-2) +0.5 ) / 10^(-2) Or int(x/10^2+0.5) * 10^2

7. QUOTIENT 8. REMINDER 9. DIVISIBILITY 10. ROUNDING TO 3 DIGIT ACCURACY

8.

ISOLATING THE LAST DIGIT

9.

ISOLATING THE FIRST DIGIT

10. ISOLATING THE LAST CHARACTER 11. ISOLATING THE FIRST CHARACTER 12. ADDING THE DIGIT TO THE REAR 13. ADDING THE DIGIT TO THE FRONT 14. ADDING THE CHARACTER TO THE REAR 15. ADDING THE CHARACTER TO THE FRONT

8. ISOLATING THE LAST DIGIT 4783 n – int (n/10) * 10 Isolating the last 2 digits n- int(n/100) * 100 Another method is to convert the number as string and isolating the last character

9.ISOLATING THE FIRST DIGIT 4783 log(n) 10 = 3.*** integer portion of log10 will give number of digits - 1 int (log(n) 10 ) = 3 d = 10^ int(log(n) 10 )

= 10^3

n – n/ int(log(n) 10 ) * int(log(n) 10 n – int(n/d) * d

10. ISOLATING THE LAST CHARACTER ll = len(st) substr ( st, ll, 1 )

11. ISOLATING THE FIRST CHARACTER xx= substr( st,1,1)

8.

ISOLATING THE LAST DIGIT

9.

ISOLATING THE FIRST DIGIT

10. ISOLATING THE LAST CHARACTER 11. ISOLATING THE FIRST CHARACTER 12. ADDING THE DIGIT TO THE REAR 13. ADDING THE DIGIT TO THE FRONT 14. ADDING THE CHARACTER TO THE REAR 15. ADDING THE CHARACTER TO THE FRONT

12. ADDING THE DIGIT TO THE REAR T0 add 7 to 834 n= 834 d=7 n=n*10+d = 8347 To add 2 digits 67 to 834

13. ADDING THE DIGIT TO THE FRONT To add any number n to d n can be of 2,3, or any digits To add 567 to 3 k=log10(n)+1

14. ADDING THE CHARACTER TO THE REAR Adding ‘n’ to vasudeva addchr = “n” base = “vasudeva” base=trim(base) + addchr you can use & instead of + in some languages

15. ADDING THE CHARACTER TO THE FRONT Adding “R” to “amasamy” front=“R” rear = “amasamy”

16. REVERSING THE STRINGS, ARRAYS, str = “VASUDEVAN” reversed str = “NAVEDUSAV ” ll = len (str) for n = 1 to ll / 2 f = substr (str, n,1) r = substr (str, ll+1 – n , 1) substr( str, n,1) = r substr ( str, ll+1 – n,1) = f

16. REVERSING THE STRINGS, ARRAYS, for i = 1 to n / 2 t = a(i) a(i) = a(n+1- i) a (n+1 – i ) = t

17. TRANSPOSE OF 2 DIMENSIONAL ARRAY 18. FINDING THE MAXIMUM / MINIMUM 19. SORTING 20. MERGING 21. SEARCHING 22. FORCEFUL ADDITIONS 23. SERIES IDENTIFICTION 23. SERIES SUMMATION ( SIN ) 24. STARS & TABLES 25. RANDOM NUMBERS 26. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

17. TRANSPOSE OF 2 DIMENSIONAL ARRAY 18. FINDING THE MAXIMUM / MINIMUM 19. SORTING 20. MERGING 21. SEARCHING 22. FORCEFUL ADDITIONS 23. SERIES IDENTIFICTION 24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

17. TRANSPOSE OF 2 DIMENSIONAL ARRAY for i = 1 to m for j = 1 to n b( j, i ) = a( i, j ) next i next j Here we use another ‘b’ array

17. TRANSPOSE OF 2 DIMENSIONAL ARRAY Jor a square array of m * m transpose can be done in situ The diagonal array will remain unaltered a( 1, 2 ) will become a (2, 1 ) for i = 1 to m-1 for j = i+1 to m t = a(I , j ) a(I,j) = a(j,i) a(j,i) = t next i next j Here we do not use another ‘b’ array

18. FINDING THE MAXIMUM / MINIMUM FIND MAXIMUM OF THE MARKS SECURED BY THE STUDENTS M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8)

= = = = = = = =

50 70 23 87 76 68 12 90

18. FINDING THE MAXIMUM / MINIMUM FIND MAXIMUM OF THE MARKS SECURED BY THE STUDENTS Assume the first value in array as maximum Some people assume 0 as maximum, which is to be avoided If all the values in the array are negative, the logic will fail

18. FINDING THE MAXIMUM / MINIMUM

max= m(1) for i = 2 to n if m(i) > max max = m(i) endif next I print “maximum = ”, max

19. SORTING (bubble sort ) for I = 1 to n-1 for j = i+1 to n if a(j) < a(i) t=a(i) a(i)=a(j) a(j)=t endif next j next I order of sort is n*(n-1) very slow sort

19. SORTING binary sort is a fast sort order n * log 2 n Assume n arrays each with only one element and hence they are sorted arrays merge 2 sorted arrays and create a new array 8 , 7 7 8

13, 5

4, 12

5 13

9,21

4 12

6, 1 9

21

1 6

8 , 7

13, 5

7

5

8

13

4, 12

9

1

12

21

6

4

1

7

9

6

8

12 21

6, 1

4

5

13

9,21

5

4

1

7

9

6

8

12

13

21

4

1

5

6

7 8 9 12 13 21

4

1

5

6

7 8 9 12 13 21 1 4 5 6 7 8 9 12 13 21

TO SORT FILES IN DESCENDING ORDER FOX PRO DOESNOT HAVE DESCENDING INDEX FOR NUMERICAL VALUES INDEX ON MINUS NUMBER FOR ALPHABETICAL VALUES, INDEX ASCENDING BUT PROCESS THE FILS FROM END OF FILE TO BOF

20. MERGING ( with forced addition of maxint) a(m+1) = maxint b(n+1) = maxint i=1 j=1 for k = 1 to m+n if a(i) < b(j) c(k) = a(i) I = i+1 else c(k) = b(j) j=j+1 endif

21. SEARCHING In searching we find the position of the searched number. If not present, the same has to be indicated. The array is sorted

M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 18 M(5) = 21 M(6) = 68 M(7) = 71 M(8) = 90 What is the position of 68, 20, 500

21. SEARCHING ( Binary Search ) (order log 2 n ) check whether the searched value is within the range or the end values low value l = a(1) high value h = a(n) mid value m = a( (n+1)/2 ) low value array index = 1

high value array index = n mid value array index = (n+1)/2 ………. If value is higher than m

21. SEARCHING In searching we find the position of the searched number. If not present, the same has to be indicated. The array is sorted

M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 18 M(5) = 21 M(6) = 68 M(7) = 71 M(8) = 90 What is the position of 68, 20, 500

M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 18 M(5) = 21 M(6) = 68 M(7) = 71 M(8) = 90 What is the position of 68 lvai = 1; hvai = 8, mvai = (8+1)/2=4 68 > (M(4) – 18); lvai = 4; hvai-lvai=8-4 =4 >1 68 = ( M(6) -68 ) Yes ; position is 6

M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 18 M(5) = 21 M(6) = 68 M(7) = 71 M(8) = 90 What is the position of 20 lvai = 1; hvai = 8, mvai = (8+1)/2=4 20 > (M(4) – 18); lvai = 4; hvai-lvai=8-4 =4 >1 20 not > ( M(6) -68 ); hvai =6 hvailvai=2 20 not > ( M(5) -21 ); hvai =5 hvailvai=1

21. SEARCHING Range detection

M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 18 M(5) = 21 M(6) = 68 M(7) = 71 M(8) = 90 What is the position of 68, 90, 500 { (68-5)*(68-90) } is negative – within the range { (90-5)*(90-90) } is zero – edge value

21. SEARCHING Hashing is a powerful searching technique

M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8)

= = = = = = = =

5 7 12 18 21 68 71 90

hashing table can have about 50 % more size 1.5 * 8 = 12

H(12)

Building Hash table– expected position v mod 12+1

M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8)

= = = = = = = =

5 7 12 19 21 68 71 90

(5 mod 12 ) + 1 = 6 ; H(6) = 5 (7 mod 12 )+ 1 = 8 ; H(8) = 7 (12 mod 12 ) + 1 = 1 ; H(1) = 12 (19 mod 12 ) +1 = 8; H(8) already filled –

M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8)

= = = = = = = =

5 7 12 19 – clash H(8); H(9) = 19 27 68 71 90

1 2 3 4 5 6 7 8 9 10 11 12 12 - - 27 - 5 90 7 19 68 71

Searching the Hash Table M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 19 M(5) = 27 M(6) = 68 M(7) = 71 M(8) = 90

1 2 3 4 5 6 7 8 9 10 11 12 12 - - 27 - 5 90 7 19 68 - 71 Is 32 in the table Expected Positn = 9 H9; No H10; No H11– blank – Not in table Is 71 in table Expected Position 12 Yes

Searching the Hash Table M(1) = 5 M(2) = 7 M(3) = 12 M(4) = 19 M(5) = 27 M(6) = 68 M(7) = 71 M(8) = 90

1

2 3 4 5 6 7 8 9 10 11 12 12 - - 27 - 5 90 7 19 68 - 71 Is 19, 40, 25 in table ?

21. SEARCHING 22. FORCEFUL ADDITIONS 23. SERIES IDENTIFICTION 24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

22. FORCEFUL ADDITIONS We already saw forceful addition in merging

a(m+1) = maxint b(n+1) = maxint i=1 j=1 for k = 1 to m+n if a(i) < b(j) c(k) = a(i) I = i+1 else c(k) = b(j) j=j+1 endif next k

22. FORCEFUL ADDITIONS This is done to simplify programming and avoiding so many other checks. Otherwise one table would have exhausted and then processing has to be different. Copy the reminder

22. FORCEFUL ADDITIONS st=“ 12 , 356 , 43 , 56” To isolate the numbers scan every 1 character. If ‘,’ the strings upto the ‘,’ can be selected and then shorten the st without that

22. FORCEFUL ADDITIONS st=“ 12 , 356 , 43 , 56” for j = 1 to ll if substr(st,j,1) =“,” wd = substr(st,1,j-1) st = substr(st, j+1) ll = len(st)

22. FORCEFUL ADDITIONS st=“ 12 , 356 , 43 , 56” After forceful addition of “, ” st = st+ “, ” st=“ 12 , 356 , 43 , 56, - ” for j = 1 to ll if substr(st,j,1) =“,” wd = substr(st,1,j-1) st = substr(st, j+1) ll = len(st)

23. SERIES IDENTIFICTION 5, 7, 9, 11 1, 4, 9, 16, 25 100, 99, 97, 94, 90, 85 1, 6, 15, 28, 45, 66 Write the next 2 numbers

100, 99, 97, 94, 90, 85 1

2

3

4

5

1, 6, 15, 28, 45, 66 81 5

9 4

13 17 21 25 4

4

4

4

Write the next 2 numbers

23. SERIES IDENTIFICTION 24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

23. SERIES IDENTIFICTION Find the first difference if no clue second difference if no clue third

24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

24. SERIES SUMMATION ( SIN ) sin x = x –x^3/ 3! +x^5/5! – x^7/7! …….. If you want the answer to 6 digit accuracy stop the summation when the value of the abs(last term added) is less than

24. SERIES SUMMATION ( SIN ) sin x = x –x^3/ 3! +x^5/5! – x^7/7! …….. If the last term added is - 40 It is not insignificant, but less than 0.000001 But abs(- 40) is not less than 0.000001

24. SERIES SUMMATION ( SIN ) sin x = x –x^3/ 3! +x^5/5! – x^7/7! take a term x^5/5! split into as many elements sign + Numerator x^5 Bottom number 5 bottom factorial 5!

24. SERIES SUMMATION ( SIN ) sin x = x –x^3/ 3! +x^5/5! – x^7/7! take a term x^5/5! Get every term from previous term

sign +

sign=-sign

Numerator x^5

nu=nu* x^2

Bottom number 5 bn = bn + 2

24. SERIES SUMMATION ( SIN ) sin x = x –x^3/ 3! +x^5/5! – x^7/7! take a term x^5/5! Initialise the first term + x^1/1!

sign + Numerator x^1 = x Bottom number 1 bott factorial 1!

=1

initialisation sum=0 sign = 1 nu=x bn=1 bf=1 t = sign * nu / bn loop begins do while abs(term) < 0.000001

loop begins do while abs(term) < 0.000001 sign=-sign nu=nu* x^2 bn = bn+2 bf = bf * (bn-1) * bn t =sign * nu / bf sum = sum + t enddo

24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

25. STARS & TABLES Split into as many variables as possible 1

7

12 11 10 9

8 8

12 11 10 9

8 1 2 1 2 3

9 9 9

12

11 10 1 2 3 4

10 10 10 10

12

11 1 2 3 4 5

11 11 11 11 11 * *

*

12

25. STARS & TABLES 7 8 8 9 9 9 10 10 10 10 11 11 11 11 11 5 rows

row 1 4 blanks no 7

1 time

row 2 3 blanks no 8

2 time

row 3 2 blanks no 9

3 time

row 4 1 blanks no 10

4 time

row 5 0 blanks no 11

5 time

7 8 8 9 9 9 10 10 10 10 11 11 11 11 11

row 1 4 blanks no 7

1 time

row 2 3 blanks no 8

2 time

row 3 2 blanks no 9

3 time

row 4 1 blanks no 10

4 time

row 5 0 blanks no 11

5 time

R 5-R try to link to R

6+R R

for r = 1 to 5 for bl= 1 to 5-r print “ ” next bl v= 6+r for va= 1 to r print str(v) + “ “ next va next r 7 8 8 9 9 9 10 10 10 10 11 11 11 11 11

26. RANDOM NUMBERS Helps to select randomly like lottery ticket random number is generally in the range 0.000000 to 0.999999 but never 1 Hence (h-l+1)* rand will select a random number between l to h inclusive. Ignore any repeat selection In the line 3 lines before, three gaps

27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR ) val(“73”) = 73 len(“Vasu”) = 4 str(7+3) = “10” substr( “vasu”, 2,2) = “as” instr(“vasu”,4,1) = “e” “vasu” will change to “vase” instr fuction can be in the left as

18. FINDING THE MAXIMUM / MINIMUM 19. SORTING 20. MERGING 21. SEARCHING 22. FORCEFUL ADDITIONS 23. SERIES IDENTIFICTION 24. SERIES SUMMATION ( SIN ) 25. STARS & TABLES 26. RANDOM NUMBERS 27. STRING MANIPULATIONS (VAL, LEN, STR, SUBSTR , INSTR )

27. PRE ASSIGNMENT 28. CHANGING CENTURY 29. SELF INDEXING AND CUMULATING 30. SIMPLIFIED DATA ENTRY 31. CORRECTING THE ENTERED DATA 32. PROGRAMMING S001, S002, S003 (1000+N 33. UNIQUE NUMBER BUILDING SYSTEM 34. NARROWED DOWN SEARCH PROGRAM

27. PREASSIGNMENT Pre Assignment helps in simplifying programming. If only a few students are likely to fail, preassign all as “PASS” Then change those who have failed Result = “PASS” If marks < 35 Result= “FAIL” endif

28. CHANGING CENTURY SOME TIMES LARGE DATA ON DATE MAY HAVE THE PREVIOUS CENTURY – 1904 INSTEAD OF 2004 IN THOSE CASES ADD 36525 DATE=DATE+36525 27-OCT-2004 MINUS 27-OCT-1904 =36525 DAYS

29. SELF INDEXING How many are in age group 1-9, 10-19, 20-29 Ages 23,8,17,24,15,6,8,9,28 Int(age/10)+1 will put in group 1,2,3 Group(Int(age/10)+1 )=Group(Int(age/10)+1 )+1 Will add to groups Total (Int(age/10)+1 ) = Total (Int(age/10)+1 )+Age Will add the ages of groups Average(1) = total (1) / group(1)

30. SIMPLIFIED DATA ENTRY The entered short data must be unique, so that a program or a conversion table should give the correct expanded data If regno are 310073, 310087, 310456 Where 310 will be common Correct Data = short data+310000 If short data=73, it will become 310073 M-male F-female

31. CORRECTING THE ENTERED DATA Date (Brit) entered in Excel Convert in another column as Text B2=text(A2, “mm/dd/yy”) 7/4/04 we meant 7 th Apr. But by text(A2, “mm/dd/yy”), it thinks as July 4 th 04 which is a valid date. Hence it will convert to american date 07/04/04, but as a text “07/04/04” Had it been 27 th Apr (27/04/04), in text(A2, “mm/dd/yy”), since month cannot be 27, it assumes the data as text and converts as simple text. The original data entry is retained as such for dates <= 12 and also for >12

31. CORRECTING THE ENTERED DATA Date (Brit) entered in Excel Convert in another column as Text B2=text(A2, “mm/dd/yy”) Convert the excel into a Database file Open a new field date and set date brit Replace date with ctod(B2) use add modi stru ( ADD DATE FIELD) set date brit repl all date with ctod(dt) brow

31. CORRECTING THE ENTERED DATA Shifting the initials to rear Names are to be entered first and initials and Mr. Mrs, Dr etc in the rear If not If second character is ‘.’ push to rear. Do it three times If Third character is ‘.’ push to rear ( Mr., dr. ). Do it three times If fourth character is ‘.’ push to rear ( Mrs., ). Do it three times

For jj=2 to 4 For nn=1 to 3 nm= trim(&FLD) if substr(nm,jj,1)="." NW= substr(nm,jj+1)+" "+substr(nm,1,jj-1) REPL &FLD WITH NW Endif Next nn Next jj JJ – DOT MARK IN 2,3,4TH POSITIONS NN – CORRECTING THRICE (N.P.K. RAMACHANDRAN)

32 To build numbers like S001, S002,S003 S320 For n= 1 to 320 j= 1000+n s= str(j,4) k=“S” +substr(s,2,3) next n

1 1001 “1001” “S001”

33 Unique Number Building System Point yes no 1 1 0 2 2 0 3 4 0 4 8 0 5 16 0 If total is 13 It is possible only as 8+4+1 No other combination is possible Every possible combination builds up to a unique number

Boys were in a hall- The correction in Q 13 was not announced in that hall If it is boy from science group and belongs to 2004-06 batch and if he has not answered Q 13 give him 5 additional marks Yes No Boy 2004-06 Batch Science Group Not Answered Q 13

1 2 4 8

0 0 0 0

If total is 15 that condition is satisfied

34 NARROWED DOWN SEARCH PROGRAM WHILE SEARCHING ON KEY WORDS, IT WILL BE NECESSARY TO NARROW DOWN THE SEARCH AS IN GOOGLE SEARCH OPEN A COLUMN NO IN THE DATA BASE FOR THE FIRST SEARCH N= N+1. AND SO ON THE ONE WITH THE MAXIMUM NUMBER IS THE NARROWED DOWN SEARCH

34 NARROWED DOWN SEARCH PROGRAM ACCN NO

TITLE

NO

DO THE NARROWED DOWN SEARCH WITH FOLLOWING KEY WORDS PROJECT, BIOMASS, GASIFIER 7O WITH PROJECT, 120 WITH GASIFIER, 80 WITH BIOMASS ONLY 2 WITH “ PROJECT ON BIOMASS GASIFIER”

Related Documents


More Documents from ""