Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Computer Science (083)

Assignment : Conditional Statements(1)

ASSIGNMENT: if..else and switch..case..default Q 1.Rewrite following code segment using if-else only Q.2.Rewrite following code Q 3. Rewrite following code segment segment using switch..case using switch..case only only

char code; cin>>code; if (ch = =E) if (ch = =N) eastern=eastern+1; cout <<NEHRU HOUSE; if (ch = =W) else western=western+1; if (ch = =V) if (ch = =N) cout <<VIVEKANAND; northern =northern+1; else if (ch = =S) if (ch = =I || ch = =i) southern=southern+1; cout <<INDIRA HOUSE; else else unknown=unknown+; if (ch = =T) cout <<TILAK HOUSE; else cout << NO HOUSE Q6.Answer the following questions Q4. What will be the output of Q5.What will be the output giving examples: the following code segment if of the following code when the input given is input is a) 2000 a) A b) 1900 b) C c) 1971 c) D d) F switch (x) { case 1: cout << "x is 1"; break; case 2: cout << "x is 2"; break; default: cout << " x is unknown"; } int year; cin >> year; if (year % 100==0) if ( year%400==0) cout <<Leap year else cout <<Not century Year; cin>> ch; switch (ch) { case A: cout <<Grade A\n; case B: cout <<Grade B\n; case C: cout <<Grade C\n; case D: cout <<Grade D\n; default : cout <<Grade F\n; } a) Q. What is the significance of break statement in a switch statement? What is the effect of absence of break statement in a switch statement? b) Q. What is Fall through? What is the significance of default clause nin a switch statement?

By Nita Arora, PGT Comp. Sc.

You might also like