Professional Documents
Culture Documents
Name: _________________________________
Output = ____________________________
Output = ____________________________ 6. (2 points) What is printed by these statements? Write "infinite" if it never stops. Write "nothing" if it doesn't print anything.
for (int j=0; j<4; j++) { cout << j << " "; }
Output = ____________________________ 7. (2 points) What is printed by these statements? Write "infinite" if it never stops. Write "nothing" if it doesn't print anything.
for (int j=5; j<0; j--) { cout << j << " "; }
Output = ____________________________ 8. (2 points) What is printed by these statements? Write "infinite" if it never stops. Write "nothing" if it doesn't print anything.
for (int j=5; j>=5; j--) { cout << j << " "; }
Output = ____________________________ 9. (2 points) What is printed by these statements? Write "infinite" if it never stops. Write "nothing" if it doesn't print anything.
for (int j=1; j<10; j*=2) { cout << j << " "; }
Output = ____________________________
10. (3 points) What is printed by these statements? Write "infinite" if it never stops. Write "nothing" if it doesn't print anything.
int n = 0; for (int j=0; j<4; j++) { cout << "/"; if (j % 3 >= 2) { break; }else{ cout << j << " "; } cout << "$"; }
Output = ____________________________ 11. (4 points) What is printed by these statements? Write "infinite" if it never stops. Write "nothing" if it doesn't print anything.
for (int j=0; j<4; cout << " j = " for (int k=j+1; cout << k << } } j++) { << j << " k = "; k<4-1; k++) { " ";
. . . switch (xx) { case 1: cout << "Hello"; break; case 3: cout << "Goodbye"; break; default: cout << "Never mind."; } . . .
3. (5 points) Write a program that reads two numbers from the input and prints their sum. You don't need a loop for this. Assume there are always two numbers. 4. (10 points) Write a program to read a sequence of integers, ignoring all numbers that are less than 1. Count how many even and odd numbers there are, and print these counts. For example, with input 7 25 100 2 -6 1 0 3, the output should be
Even = 2, odd = 4
There were two even numbers (100 and 2), four odd numbers (7, 25, 1, and 3), and two numbers were ignored (-6 and 0). Your program should work for any input, not just this example. 5. (15 points) A toll booth needs a program that tells how much to charge drivers. The charge is based on how many people are in the vehicle. To encourage car-pooling, the cost is lower for more people. The cost is $6.00 for one person, 1/2 of that ($3.00) for two people, 1/3 ($2.00) for three people, and in general 6/n for n people. Write a program that reads the number of people in the vehicle and prints the cost. Print "ERROR" if a number less than 1 is entered. It continues reading input in a loop.