You are on page 1of 2

1.

A video rental shop uses the following type of classification scheme for movie video CD’s:

Type Code Movie Category


A Action and adventure
C Comedy
D Drama
F Family
H Horror and Science Fiction
M Musicals

Any other type code is considered an error.

a. Write an if ..else statement that tests the value of the type code, increments the number of
videos of the appropriate category by one and computes the total number of videos in the
inventory. Your code should print a warning message if the type code value is in error.

b. Write a switch statement instead to solve the given problem.

IF STATEMENT SWITCH STATEMENT


char code == ‘A’; char code == ‘A’;

cout << “Enter code: “; cout << “Enter code: “;


cin >> code; cin >> code;

if (code == ‘A’) switch (code)


cout << “Action and adventure”; {
else if (code == ‘C’) case ‘A’:
cout << “Comedy”; cout << “Action and adventure”;
else if (code == ‘D’) break;
cout << “Drama”; case ‘C’:
else if (code == ‘F’) cout << “Comedy
cout << “Family”; break;
else if (code == ‘H’) case ‘D’:
cout << “Horror and Science Fiction”; cout << “Drama”;
else if (code == ‘M’) break;
cout << “Musicals”; case ‘F’:
else cout << “Family”;
cout << “Wrong code”; break;
case ‘H’:
cout << “Horror and Science
Fiction”;
break;
case ‘M’:
cout << “Musicals”;
break;
default:
cout << “Wrong code”;
}
2. Construct a flowchart which reads two different integer values to determine the bigger value
between the two numbers and display a message whether the number is odd or even.

Input : 3 7
Output : 7 is an odd number and is bigger
Input : 8 2
Output: 8 is an even number and is bigger

You might also like