Name: _______________________Section: ____ ID: _________________
Which of the following is a program control instruction?
If x contains the value 3 before the following instruction is executed, what is the value of x after the instruction: x *= 5; is executed?
Which of the following is not a legal variable name?
Which numeric data type has the largest range?
Suppose we want to store the value 1.5 into a double variable d. Which of the following would not work?
Consider the following code fragment carefully, then answer the question: how many times will the cout statement execute:
for (i = 0; i < 5; i++); cout << i;
What are the three basic control structures used in programming?
A loop exit condition must
If the logic of your program at some point requires you to do one thing or another, which instruction would you use to implement this decision?
Suppose you have a point on a plane represented by the variables ptX and ptY (its x and y coordinates). Suppose you also have a rectangle, whose upper left corner is represented by the variables left and top, and whose bottom right corner is represented by the variables right and bot. Using the standard graphics coordinate system, in which y increases from top to bottom and x increases from left to right, which of the following conditions will test if the point is outside the rectangle?
The force of gravitational attraction, F, of two bodies is given by a formula in which a constant, G, is multiplied by the product of the two masses (m1 and m2). This is then divided by the square of the distance, d, between the two bodies. Assuming these variables are declared, and have proper initial values where necessary, which of the following C++ statements correctly expresses this formula?
Write one statement to display the first 3 letters of your first name, one per line.
Write a statement to display a double in a field 10 characters wide using two decimal places.
Rank the order in which arithmetic statements are evaluated (place numbers 1, 2, ... in the space provided. If a rule is given that is not a correct rule, do not place a number next to it.
___ exponentiation
___ addition and subtraction, left to right
___ addition and subtraction, right to left
___ sub-expressions in parenthesis
___ multiplication and division, left to right
___ multiplication and division, right to left
Consider the following:
int x; double n1 = 5, n2 = 2; x = n1/n2;
What value is in x? __________
a. What symbol in C++ is used to express a logical "or"? __________
b. What symbol in C++ is used to express a logical "and"?__________
A ball is thrown up in the air. Its height above the ground is given by the formula h = 3 + 10t – t2 where t is the time in seconds after it is thrown. For example, at
Time t = 0, h = 3 + 0 - 0 = 3
Time t = 2, h = 3 + 20 – 4 = 19
When the ball hits the ground, h becomes negative. Write a fragment of C++ code to print out the height, h, once every second, starting a t = 0, and continuing until h becomes negative (meaning the ball has hit the ground). (Do not print the negative value.) Include all necessary data declarations and initializations.
In many cases when we want to find the average of a set of numbers, we throw away the extreme values, either because they
Write a complete program to read a series of numbers from the keyboard. Use an end-of-input signal value of –99. Calculate and print the average of the numbers between 32 and 212. Any number below 32 or above 212 should not be included in the average calculations, but you should keep a count of them and print that at the end of the program. A run of the program should resemble the following:
Enter a number (-99 to quit): 22
Enter a number (-99 to quit): 44
...
Enter a number (-99 to quit): -99
Average is: 45.45
There were 3 extreme values