Misr International University
Faculty of Engineering
Department of Electronics & Communications
Structured Programming CSE250
Fall 2015
Tutorial Session 1
Section: 7/9/2015 Gr.4 from 4:00PM-6:00PM
Question 1:
State whether the following are valid switch statements. If not, explain why. Assume that n and digit
are int variables. (20 min)
A)
switch (n <= 2)
{
case 0:
cout << "Draw." << endl;
break;
case 1:
cout << "Win." << endl;
break;
case 2:
cout << "Lose." << endl;
break;
}
B)
switch (digit / 4)
{
case 0,
case 1:
cout << "low." << endl;
break;
case 1,
case 2:
cout << "middle." << endl;
break;
case 3:
cout << "high." << endl;
}
C)
switch (n % 10)
{
case 2:
case 4:
case 6:
case 8:
cout << "Even";
break;
case 1:
case 3:
case 5:
case 7:
cout << "Odd";
break;
Misr International University
Faculty of Engineering
Department of Electronics & Communications
Structured Programming CSE250
Fall 2015
Question 2
Suppose the input is 5. What is the val
ue of alpha after the following C++ code executes? (10 min)
cin >> alpha;
switch (alpha)
{
case 1:
case 2:
alpha = alpha + 2;
break;
case 4:
alpha++;
case 5:
alpha = 2 * alpha;
case 6:
alpha = alpha + 5;
break;
default:
alpha--;
}
Question 3
Suppose the input is 3. What is the value of beta after the following C++ code executes? (10
min)
cin >> beta;
switch (beta)
{
case 3:
beta = beta + 3;
case 1:
beta++;
break;
case 5:
beta = beta + 5;
case 4:
beta = beta + 4;
}
Question 4
Write a sentinel controlled while loop that allows the user to enter integer numbers ended
by -1. The sum and the average of the entered numbers should be displayed. (15 min)
Question 5 (Bonus)
Write nested for loops that shows on the screen the following figure
A
AA
AAA
AAAA
AAAAA
AAAA
AAA
AA
A