Page 51 - Modular_V1.1_Flipbook
P. 51
5. Complete the following C++ program:
void main(){
switch (draw){
case 'R' : cout << "Draw rectangle";
break;
case 'C' : cout << "Draw circle";
break;
case 'E' : cout << "Draw ellipse";
break;
case 'P' : cout << "Draw polygon";
break;
default : cout << "Wrong choice";
}
}
6. Find the error in the following code and rewrite the correct code:
int time = 08;
if(time < 12] {
cout>>"Good morning.";
} else if(time > 20) {
cout<<"Good night.";
} else {
cout<<"Good evening.";
}
Experiential Learning
In the lab
Write a program to:
accept a number from the user and check whether it is positive or negative.
accept number of day from the week and display the day of the week.
calculate the grade of an employee with the following conditions using switch statement.
5667 A
6443 C
3546 E
4535 B
check whether the year entered by the user is a leap year or not. An year is a leap year if it is
divisible by 4 and not divisible by 100 for a century year. The century year is a leap year only if
it is perfectly divisible by 400.
accept three numbers from the user, then print ‘You Won’ if the sum of input numbers is
greater than 1000.
Teacher's Corner
1. Discuss all the conditional statements provided by C++ with the students.
2. Explain the difference between switch and if…else…if ladder to the students.
Conditional Statements 49

