Loading... Please wait...


(TCO 1) Which of these is a legal identifier in C++?

  • COMP 122 Structured Programming with Lab  Week 4 Midterm Answers

Product Description


1. (TCO 1) Which of these is a legal identifier in C++?

2. TCO 1) Which of the following identifies syntax errors in programs written in a high-level language?

3. (TCO 1) For the values given, what will c contain after executing the following?

4. TCO 1) For the values given, what will c contain after executing the following?

5. (TCO 1) A single equal sign is called

6. (TCO 1) What is the result of 56 % 10?

7. (TCO 1) What is the output for the following code fragment?

8. (TCO 1) Which operation in the following expression will be performed first?

9. (TCO 2) When used with cout, << is called

10. (TCO 2) Which of the following would you add to your program to read an entire line of input into a string variable named input?

11. (TCO 2) Which statement outputs a double value in a field of six characters with three digits after the decimal point?

1. (TCO 2) What are the values of the variables after the code fragment below executes if the input data is 37 86.56 32?

2. (TCO 10) For readability, all statements inside a loop body should be

3. (TCO 10) Which of the following lines correctly adds a multiline comment?

4. (TCO 3) A program needs to output the cost of shipping a package based on the weight of the package. Information is available that associates specific weight ranges with specific costs. For example, a package weighing between 1 and 2 pounds costs $2.50 to ship. The best selection structure to use to program this situation is _______.

5. (TCO 3) Which statement correctly tests char variable keepgoing for the upper or lower case letter A?


(TCO 3) What is the output of the following code snippet?

int a = 9, b = 4, c = -1;
if (a > b || (c = a) > 0)
cout << "TRUE" << a << b << c;
} else {
cout << "FALSE" << a << b << c;



(TCO 3) What is the value of beta after the following code executes if the input is 1?



int beta;

cin >> beta;



case 3:

beta += 3;


case 1:


case 4:

beta += 4;


case 5:

beta += 5;



8. (TCO 4) Your program must repeat a set of tasks exactly 15 times. Which looping construct is best suited for this situation?


(TCO 4) How many times does the following loop body execute?


int count = 52;

for(int i = 0; i > 26; i++)


      cout << count << endl;



10. (TCO 4) When the ________ statement is executed in a loop body, the remaining statements in the loop body are skipped and control proceeds with the next iteration of the loop.

11. (TCO 4) Which of the following expressions is correct if you want to end a while-loop when the character variableanswer is the character 'n' in either upper or lower case?


1. (TCO 4) What is the output from the following loop if the input is 5  10  2  3  -1 ?

2. (TCO 3) A program has a char variable gender that has been assigned a value.  Write a switch statement that outputs "Male" if the variable contains lower or upper case 'm', "Female" if it contains lower or upper case 'f', or "Invalid Input" for any other value.

3. (TCO 3) Create a complete C++ program that prompts the user to enter his or her height in inches and outputs the following:

Output "Height is six feet or more." when the user's height is 6 feet or more.

Output "Height is less than five feet." when the user's height is less than 5 feet.

Output "Height is at least five feet but less than 6 feet" otherwise.

4. (TCO 3) Write a complete C++ console mode program (#includes, etc., but no prologue) to ask the user to enter the radius (any positive real number) of a circle. Your program should display the area of a circle with that radius, and the volume of a sphere with that radius. (area = PI * radius2 and volume = PI * 4/3 * radius3 ). The result should be displayed with accuracy to 3 decimal digits (ie. 1.234). Make sure you include all the header files needed to support the operations you use.


a. Use appropriate data types.

b. Make the value of PI (3.14159) a constant in your program.

c. Valid input is any positive real number and zero. If the user input is negative, your program should print an error message and not try to compute any results.

d. Be sure to display explanatory text to make the input and output clear to the user.

5. (TCO 4) Create a C++ program that uses a do-while-loop to display the multiples of 5 (5, 10, 15, 20…)  from 75 to 190, including 75 and 190. The numbers should be displayed one per line.

6. (TCO 4) Write a complete C++ program that meets the following criteria:


a. Use a while loop. Explicitly ask the user if they have more data to enter. Use their answer to decide when the loop is done.

b. The purpose of the loop is to calculate and display the amount of interest for one year given an initial deposit and an interest rate. (interest = deposit * rate) 

c. The output from the loop should explain what values are being displayed and display the interest with 2 digits after the decimal point.

d. The loop must ask the user to input the values for the initial deposit and the interest rate. Both values should be treated as real numbers.

e. If either input value is negative, your program should output a message indicating that the input values must be positive numbers. The interest amount should not be displayed in this case.

f. Declare all needed variables using appropriate data types. Initialize as needed.

Products by Category

Add to Wish List

Click the button below to add the (TCO 1) Which of these is a legal identifier in C++? to your wish list.

You Recently Viewed...