Friday, 1 February 2013

Switch - 1

Points to remember:
1.  switch,case and default  in small letters
2. After switch , the  constant must be either  integer or character constant.
3. If the input doesnot match any given choices , the default will be executed.
4.break statement is compulsory, otherwise all the cases will be executed.
5. After case and the constant , there is a colon(:)
6. After switch there is no semi colon.
7. No two cases can have the same value.

Section A
1. What is the function of default in switch statement?
                                                                                      [ICSE 2005]
2. Write down the syntax of switch case.                [ICSE 2007]
3. What is the purpose of break statement?
4. Re write the following using switch case
int n=0,ch;
if(ch==1)
{
n++;
System.out.println(n);
}
if(ch==2)
{
n+=2;
System.out.println(n);
}
if(ch==3)
{
n+=3;
System.out.println(n);
}

Section B
1. Write a menu driven program to find the area of an equlateral triangle(ET) , a right angled triangle (RT), a scalene triangle (ST)respectively.
2. Write a menu driven program to calculate the area of
circle =p*r*r
square = side * side
rectangle = length * breadth                                 [ICSE 2005]
Display the menu to output the area as per the user's choice. For an incorrect input, appropriate message should be displayed.