COMP 122 DeVry Midterm Exam

Downloading is very simple, you can download this Course here:

http://wiseamerican.us/product/comp-122-devry-midterm-exam/

Or

Contact us at:

SUPPORT@WISEAMERICAN.US

COMP 122 DeVry Midterm Exam

COMP122

COMP 122 DeVry Midterm Exam

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

  • GPD*7
  • payRate-2
  • ID_1
  • 3rdVar

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

  • Assembler
  • Compiler
  • Preprocessor
  • Linker

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

int a = 9, b = 4, c = -1;

c -= a % b;

  • -1
  • -2
  • -3
  • 1

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

int a = 9, b = 4, c = -1;

c += b++ * a;

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

  • the insertion operator.
  • the equality operator.
  • the assignment operator.
  • None of the above

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

  • 10
  • 5
  • 5.6
  • 6

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

int var1 = 20;

cout << var1–;

cout << var1++;

  • 1920
  • 1921
  • 2020
  • 2019

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

  • c = a++ / b + 5;
  • a++
  • a / b
  • b + 5
  • assignment to c

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

  • the insertion operator
  • the extraction operator
  • the assignment operator
  • None of the above

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

  • cin >> input;
  • cin.getline(input);
  • getline(cin, input);
  • cin << input;

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

  • cout << 6chars << 3digits << 1.234;
  • cout << fixed << setprecision(3) << 1.234;
  • cout << setprecision(3) << setw(6) << 1.2345678;
  • cout >> setprecision(3) >> 6chars >> 1.234;

* Times are displayed in (GMT-07:00) Mountain Time (US & Canada)

  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?

int x, y;

double z;

cin >> x;

cin >> y;

cin >> z;

  • x = 37, y = 86.56, z = 32
  • x = 37, y = 86, z = 32
  • x = 37, y = 86, z = 0.56
  • x = 37, y = 86, z = 32.56

Question 2. Question : (TCO 10) For readability, all statements inside an if statement body should be

  • indented the same distance as the if statement.
  • surrounded by an open and closing parenthesis.
  • indented by one additional tab stop more than the if statement.
  • written on the same line.

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

// comment

comment

/* comment * comment

*/

/* comment

*/ comment

comment

comment

Question 4. Question : (TCO 3) Based on input of a single digit code, your program must output the full name of a US state plus other information about the state based on its population category. The best selection structure to use to program this situation is _______.

  • a SWITCH statement
  • multiple IF statements
  • nested IF statements
  • multiple IF ELSE statements

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

  • if(keepgoing = ‘a’ || keepgoing = ‘A’)
  • if(keepgoing = ‘a’ || ‘A’)
  • if(keepgoing == ‘a’ && keepgoing == ‘A’)
  • if(keepgoing == ‘a’ || keepgoing == ‘A’) :

Question 6. Question : (TCO 3) Which of the following values of the variable code will produce the same output for the two code fragments?

if(code < 1) if(code < 1)

cout << “First”; cout << “First”;

if(code < 2) else if(code < 2)

cout << “Second”; cout << “Second”;

if(code < 3) else

cout << “Third”; cout << “Third”;

  • 0
  • 1
  • 2
  • None of the above

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

int beta;

cin >> beta;

switch(beta)

{ case 3:

beta += 3;

break;

case 1:

beta++;

case 4:

beta += 4;

break; case 5:

beta += 5; }

  • 2
  • 6
  • 11
  • 1

Question 8. Question : (TCO 4) Which looping construct would be best suited when a program must repeat a set of tasks until a specific condition occurs? It is possible that the set of tasks will not need to execute at all if the specific conditions exists initially.

  • for
  • do while
  • while
  • Any of the above

Question 9. Question : (TCO 4) How many times does the following loop body execute?

int count = 52;

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

{ cout << count << endl; –count; }

  • 26
  • 52
  • 25
  • None of the above

Question 10. Question : (TCO 4) When the _______ statement executes in a loop body, control immediately exits from the loop.

  • break
  • continue
  • exit
  • done

Question 11. Question : (TCO 4) Which of the following expressions is correct if you want to end a while-loop when the character variable answer is anything other than the character ‘y’ in either upper or lower case?

while(answer == ‘y’ && answer == ‘Y’)

while(answer == “y” && answer == “Y”)

while(answer == ‘y’ || answer == ‘Y’)

while(answer == “y” || answer == “Y”)

int sum = 0;

for ( int i = 1; i % 2 != 0; i++) { sum += i; i++; } cout << sum << endl;

Question 2. Question : (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.

Question 3. Question : (TCO 3) Write a short program that gets three integer values from the user and outputs the largest number. Make sure you include everything you need, and declare all the variables you need.

Question 4. Question : (TCO 3) Write a complete C++ console mode program (#includes, etc., but no prologue) that solves a simple DC circuit problem. Given a DC voltage source of some magnitude, find the voltage drops across the 2 resistors. The user will provide the values for the voltage source and the 2 resistor values. The formula that you will need is:

VRx = Vsupply * Rx / (Rx + Ry) // Voltage Divider rule

  • ?????????Use appropriate data types.
  • ?????????Valid input is any positive real number. If the user input is zero or negative, your program should print an error message and not try to compute any results.
  • ?????????Be sure to display explanatory text to make the input and output clear to the user. Results should be output with 3 digits following the decimal point.

Question 5. Question : (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.

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

  1. Use a do-while loop. Explicitly ask the user if they have more data to enter. Use their answer to decide when the loop is done.
  2. 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)
  3. The output from the loop should explain what values are being displayed and display the interest with 2 digits after the decimal point.
  4. 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.
  5. 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.
  6. Declare all needed variables using appropriate data types. Initialize as needed.