These questions are meant to be representative or typical of those that will be on the test. They are meant to show the kind of questions that will be on the test and the general level of difficulty. These particular questions may or may not be on the test. There may be some other kinds of questions on the test.
1. The % operator always takes
2. The three basic control structures used to build programs are:
In the next three questions, assume n is an integer. What is the value stored in n?
3. n = 8/5;
4. n = 6 / 6 * 3;
5. n = 6 + 2 * 6 / 3 * 3;
6. We call the pieces of information passed to a function which it uses to do its task ___________.
7. The condition used in an if or while statement (i.e. the code inside the (..)) must evaluate to ___________.
8. A const (as we have used it) associates a constant _________________ with a ________________.
9. If a loop body has more than 1 instruction, the set of instructions must be enclosed in ___________.
10. Write a function (call it getAns()) that prompts the user to enter a single letter from "a" to "d". It will return that letter to the calling function. It will not return anything but "a" through "d". If the user enters anything else, it will display and error message and ask the user to re-enter.
11. Write a single statement that will both call getAns() and display the value returned.
12. What is the output of the following code:
for (i = 0; i < 10; i += 2)
{
if ((i * 2) > 10)
cout << "1st output: " << i << '\n';
else
cout << "2nd output: " << i << '\n';
}
13. Write a complete program to find and display the sum of the first n integers. (That is, the sum of the first 3 is 1 + 2 + 3 = 6; the sum of the first 4 is 1 + 2 + 3 + 4 = 10, etc.) Prompt the user to enter n, and use that value in your calculation. Assume that the result will not exceed the maximum integer value. Assume the entered value is valid. Do not do any error checking.
14. Write three code fragments to display the first 5 integers, using the three different loop instructions we have studied.