I. Convert from pseudo-English to C++:
Example: if total is more than or equal to 100 then Beep();
Answer: if (total>=100) Beep();
if Answer is 'Y' and x is not 2 then Beep();
if z is less than 7.2 AND either m is 2 or k is 5 then Beep();
if q is between 0 and 100 then Beep();
What's the problem with converting the following:
if y is 9 or y is 1 and x is 5 then Beep();
II. Consider the following "switch" statement:
switch (ch) {
case 'a': cout << "alpha"; break;
case 'b':
case 'c': cout << "beta"; break;
case 'd': cout << "delta";
case 'e': cout << "epsilon"; break;
case '0': cout << "naught"; break;
default: cout << "don't know"; break;
}
What output is produced when the value of ch
is as given?
1) ch == 'e'
2) ch == 'b'
3) ch == '3'
4) ch == 'd'
III. Trace through the following loop, keeping track of the
values of the variables.
int k, total=0;
k=3;
while (k<8)
{
total=total+k;
k=k+2;
}
IV. Trace through the following loop, keeping track of the
values of the variables.
int m=3, A=1;
do { --m; A=A*m; } while (m>0);