From Test #1 with correct answers
Start
About This Quiz
This quiz focuses on foundational C++ concepts, essential for the CPS 150 final exam. It covers keywords,
identifiers, data types, syntax for comments and output operations, assessing readiness and deepening
understanding of C++ programming.
CPS 150 Final Exam Study Questions From Test #1 - Quiz
Quiz Preview
1/50 Questions
Determine the final value of the int variable angle when 0 is input.cout << "Enter angle: " ; cin >> angle
;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle
- 15 ;else angle = angle +100 ;
2.
Determine the final value of the int variable angle when 5 is input.cout << "Enter angle: " ; cin >> angle
;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle
- 15 ;else angle = angle +100 ;
Explanation
The final value of the int variable angle will be 10. This is because the input value of 5 satisfies the
condition in the first if statement (angle >= 5), so the value of angle is increased by 5. Since none of the
other conditions are met, the value remains unchanged.
Rate this question:
3.
Determine the final value of the int variable angle when 1 is input.cout << "Enter angle: " ; cin >> angle
;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle
- 15 ;else angle = angle +100 ;
Explanation
,The final value of the int variable angle is 101. This is because the input value of 1 satisfies the condition
of the last "else" statement, which adds 100 to the angle. Therefore, the value of angle is 1 + 100 = 101.
Rate this question:
4.
Determine the final value of the int variable angle when 15 is input.cout << "Enter angle: " ; cin >> angle
;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle
- 15 ;else angle = angle +100 ;
5.
Determine the final value of the int variable angle when -5 is input.cout << "Enter angle: " ; cin >> angle
;if (angle >= 5) angle = angle + 5 ;else if (angle > 2) angle = angle + 10 ;else if (angle <= 0) angle = angle
- 15 ;else angle = angle +100 ;
Explanation
The value of the variable angle is -5. Since -5 is less than 0, the condition of the third else if statement is
true. Therefore, the value of angle will be -5 - 15 = -20.
Rate this question:
6.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ...,
20) with one number per output line.int number = ____________ ;while (number <= 20) { cout <<
number << endl ; number = (number +2) ;} // end while
Explanation
The blank should be filled with "2" because the program starts with the number 2 and then increments
it by 2 in each iteration of the while loop. This allows the program to display the numbers 2 to 20 in
steps of two.
Rate this question:
7.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ...,
20) with one number per output line.int number = 2 ;while (_______________) { cout << number <<
endl ; number = (number +2) ;} // end while
Explanation
The blank should be filled with "number
,Rate this question:
1
8.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ...,
20) with one number per output line.int number = 2 ;while (number <= 20) { cout << _________<< endl
; number = (number +2) ;} // end while
Explanation
The blank should be filled with "number" because the variable "number" is being printed in each
iteration of the loop, and it is incremented by 2 in each iteration to display the numbers 2 to 20 in steps
of two.
Rate this question:
9.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ...,
20) with one number per output line.int number = 2 ;while (number <= 20) { cout << number <<
________ ; number = (number +2) ;} // end while
Explanation
The correct answer is "endl" because using "endl" in the code will insert a new line after each number is
displayed, resulting in one number per output line.
Rate this question:
10.
Fill in the blank that will allow the program to display the numbers 2 to 20 in steps of two (i.e. 2,4,6, ...,
20) with one number per output line.int number = 2 ;while (number <= 20) { cout << number << endl ;
__________________ ;} // end while
Explanation
The correct answer is "number = number + 2" or "number = (number + 2)". These statements increment
the value of the variable "number" by 2 in each iteration of the while loop, allowing the program to
display the numbers 2 to 20 in steps of two.
Rate this question:
11.
, The following program is supposed to read 10 integer values using a loop, and find the sum total of
those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ;
__________; while (k <= 10) { cout << "Enter a number: " ; cin >> number ; sum = sum +
number ; k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Explanation
The variable "k" is initialized with a value of 1. This is important because it determines the condition for
the while loop. The loop will continue as long as the value of "k" is less than or equal to 10. By setting "k"
to 1, the loop will execute 10 times, allowing the program to read 10 integer values and calculate their
sum.
Rate this question:
12.
The following program is supposed to read 10 integer values using a loop, and find the sum total of
those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ;
k = 1 ; while (_________) { cout << "Enter a number: " ; cin >> number ; sum = sum +
number ; k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Explanation
The blank should be filled with "k
Rate this question:
13.
The following program is supposed to read 10 integer values using a loop, and find the sum total of
those numbers. Fill in the blank to complete the program.int main () { int k, number ; int sum = 0 ;
k = 1 ; while (k <= 10) { cout << "Enter a number: " ; ____________; sum = sum + number ;
k = k + 1 ; } // end while cout << "Result = " << sum << endl ; return 0;} //end main
Explanation
The blank should be filled with "cin >> number" because it is the statement that allows the user to input
a number into the "number" variable. This statement is inside the while loop, which means it will be
executed 10 times, allowing the user to input 10 integer values. The "number" variable is then added to
the "sum" variable to calculate the total sum of the numbers.
Rate this question:
14.