slides pst 2a

67
1

Upload: thebhas1954

Post on 19-Jul-2016

3 views

Category:

Documents


1 download

DESCRIPTION

Viewing of components in rdbms

TRANSCRIPT

Page 1: Slides Pst 2a

1

Page 2: Slides Pst 2a

2

Page 3: Slides Pst 2a

3

Page 4: Slides Pst 2a

4

Page 5: Slides Pst 2a

5

Page 6: Slides Pst 2a

6

Page 7: Slides Pst 2a

7

Page 8: Slides Pst 2a

8

Page 9: Slides Pst 2a

9

Page 10: Slides Pst 2a

10

Page 11: Slides Pst 2a

11

Some examples :-

int iN1,iN2,iN3 ,iN =0;

iN1=1,iN2=2,iN3=3;

1) if(iN > iN2)

printf(“iN1 is larger”);

else

printf(“iN2 is larger”);

2) if(iN1 > iN2)

printf(“iN1 is larger”);

else if(iN1 < iN2)

printf(“iN2 is larger”);

else

printf(“Both iN1 and iN2 are equal”);

Page 12: Slides Pst 2a

12

3) if(iN==1) /* prints iN is not one*/

printf(“iN is one”);else

printf(“iN is not one”);4) if(iN=1) /* prints iN1 is one*/

printf(“iN is one”);else

printf(“iN1 is not-one”);In the above example the expr that’s evaluated is an assignment expr and not a conditional expr. (becoz of = and not ==). The expr will assign a non-zero value to iN and then iN is evaluated. Since it contains a non-zero value (indicating true evaluation) the if part is executed5) if(iN1=0) /*prints iN1 is non-zero*/

printf(“iN1 is zero”);else

printf(“iN1 is non-zero”);In the above example the expr that’s evaluated is an assignment expr and not a conditional expr. (becoz of = and not ==). The expr will assign a zero value to iN1 and then iN1 is evaluated. Since it contains a zero value (indicating false evaluation) the else part is executed6) if(5) /*prints true.*/

printf(“True’); /*becoz expr evaluates to a non-zero value.*/

else printf(“false”);

Page 13: Slides Pst 2a

13

7) if(0) /*prints false*/printf(“True”); /* becoz the expr evaluates to zero value*/

elseprintf(“False”);

8) if(iN==3); /*gives a compilation as if terminates after expr.*/printf(“true”); /* this means there is no matching if for the else below*/

else /* hence a error at compilation time is reported*/printf(“false”);

9) if(iN1==1 && iN2 <3) /*prints true as the expr evaluates to true – T && T*/printf(“True”);else

printf(“false”);10) if(!4) /* not of a non zero value is zero hence false is printed*/

printf(“true”);elseprintf(“false”);

Page 14: Slides Pst 2a

14

Page 15: Slides Pst 2a

15

Guidelines while writing if statements:

(1)Write the nominal path first then write the exceptions- put the nominal case in the if part rather than in the else part.

(2)Make sure that you branch correctly on equality-using > instead of >= makes an off-by-one error.

(3)Follow the if clause with a meaningful statement - Do not use if statement as shown below:

Ex: if (somecondition) ;

else

/* do something*/

Instead use:

if ( ! Somecondition)

/* do something */

Page 16: Slides Pst 2a

16

Page 17: Slides Pst 2a

17

Page 18: Slides Pst 2a

18

Page 19: Slides Pst 2a

19

Page 20: Slides Pst 2a

20

Page 21: Slides Pst 2a

21

Page 22: Slides Pst 2a

22

Page 23: Slides Pst 2a

23

Page 24: Slides Pst 2a

24

•The switch statement is a multi directional conditional control statement.

•Whenever a choice is to be made among a of alternatives, we use switch statement.

•The switch block is used as an alternative to if construct when the value in a variable needs to be matched against a set to values.

•The expression needs to be of integral type only. All case values need to be unique. number

•The switch control construct helps in controling complex conditional and branching operations. The expr value is matched against all case values. If a match is found the case block executes and the control comes out of the switch . In absence of a break statement the execution continues with the next case block till it encounters a break / the switch block terminates .

•If expression does not match with any of the listed case values then the default block executes. The default is an optional statement and need not be at the end of switch.

•This is one of the code tuning techniques in which we place cases according to the frequency in which they occur to reduce the number of comparisons. More about this we discuss in code tuning techniques in the later day slides

The break statement has two uses:

•To terminate the case in the switch statement (refer to switch slides)

•To termination a loop. More on this we discuss in looping constructs in the later slides

Page 25: Slides Pst 2a

25

Page 26: Slides Pst 2a

26

Page 27: Slides Pst 2a

27

Page 28: Slides Pst 2a

28

Page 29: Slides Pst 2a

29

Page 30: Slides Pst 2a

30

Page 31: Slides Pst 2a

31

When to use what?

1. If there are simple and small number of comparison statements then using if construct is a good idea

2. If there is a list of values against which a variable has to be compared then using a switch construct is a good idea

3. If there are expressions against which comparisons are to be made and there are many comparisons to be done , and if..else if construct can be used

Page 32: Slides Pst 2a

32

Page 33: Slides Pst 2a

33

Page 34: Slides Pst 2a

34

Page 35: Slides Pst 2a

35

Page 36: Slides Pst 2a

36

Page 37: Slides Pst 2a

37

Page 38: Slides Pst 2a

38

Page 39: Slides Pst 2a

39

Page 40: Slides Pst 2a

40

Page 41: Slides Pst 2a

41

Page 42: Slides Pst 2a

42

Page 43: Slides Pst 2a

system(cls) is used for clearing the screen by invoking an OS command cls. This is present in stdlib.h header file. The getch() is used for waiting for a key press. This is present in conio.h header file. Both the cls and getch() run on windows platform

43

Page 44: Slides Pst 2a

44

Page 45: Slides Pst 2a

45

Page 46: Slides Pst 2a

46

Page 47: Slides Pst 2a

47

Page 48: Slides Pst 2a

48

Page 49: Slides Pst 2a

49

Page 50: Slides Pst 2a

50

Page 51: Slides Pst 2a

51

Page 52: Slides Pst 2a

52

break statement:

A break statement can be used inside a loop or a switch case construct. We havealready seen the use of break statement inside the switch case construct.

When a break statement is encountered inside a loop the execution of the loop stops.

Page 53: Slides Pst 2a

53

Page 54: Slides Pst 2a

54

Page 55: Slides Pst 2a

55

Page 56: Slides Pst 2a

56

Page 57: Slides Pst 2a

57

Page 58: Slides Pst 2a

58

Page 59: Slides Pst 2a

59

Page 60: Slides Pst 2a

60

Page 61: Slides Pst 2a

61

Page 62: Slides Pst 2a

62

Page 63: Slides Pst 2a

63

1. for loop2. A do..while loop as the menu has to be shown atleast once and then depending on the choice of the user appropriate

action can be taken3. Yes For example: for(iNum=0;iNum<10;iNum++);4. Only the inner loop is terminated 5. while(1) or for(;;) or do -- while(1)

Page 64: Slides Pst 2a

64

Page 65: Slides Pst 2a

65

Page 66: Slides Pst 2a

66

Page 67: Slides Pst 2a

67