Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 30 pages
Exam (elaborations)

CPS 150 Final Exam Study toughest Questions From Test #2 and correct answers

Document preview thumbnail
Preview 3 out of 30 pages

This study guide for CPS 150 compiles the most difficult questions from Test #2, complete with accurate answers to aid final exam preparation. Topics include programming fundamentals, algorithm logic, control structures, and data handling, as covered in the second major exam. Ideal for computer science students seeking a focused review of the most challenging material.

Content preview

CPS 150 Final Exam Study toughest
Questions From Test #2 and correct
answers
Start

About This Quiz

This quiz assesses understanding of C++ programming concepts such as loops, value parameters, and
variable roles. It's designed to prepare students for the CPS 150 final exam, testing their ability to
analyze and predict code behavior.



CPS 150 Final Exam Study Questions From Test #2 - Quiz

Quiz Preview



1/50 Questions

Complete the program fragment using while statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.int number = _____ ;while (number <= 19) { cout
<< number << endl ; number = number + 3 ;} // end while

2.

Complete the program fragment using while statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.int number = 1 ;while (___________) { cout <<
number << endl ; number = number + 3 ;} // end while

Explanation

The while loop condition should be "number

Rate this question:



3.

Complete the program fragment using while statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.int number = 1 ;while (number <= 19) { cout <<
________ << endl ; number = number + 3 ;} // end while

Explanation

The variable "number" is being outputted on each line using the "cout" statement.

,Rate this question:



4.

Complete the program fragment using while statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.int number = 1 ;while (number <= 19) { cout <<
number << _______ ; number = number + 3 ;} // end while

Explanation

The correct answer is "endl" because it is used to insert a new line character after each number is
displayed, ensuring that each number is printed on a separate line.

Rate this question:



5.

Complete the program fragment using while statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.int number = 1 ;while (number <= 19) { cout <<
number << endl ; _________________;} // end while

Explanation

The correct answer is "number = number + 3" or "number = (number + 3)". These statements increment
the value of the variable "number" by 3 in each iteration of the while loop. This ensures that the loop
continues until the value of "number" reaches or exceeds 19.

Rate this question:



6.

Complete the program fragment using a for statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.for (int number = 1 ;____________; number =
number + 3) cout << number << endl ;

Explanation

The missing condition in the for statement should be "number

Rate this question:



7.

Complete the program fragment using a for statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.for (int number = 1 ; number <= 19 ;
_______________) cout << number << endl ;

, Explanation

The correct answer is "number = number + 3" or "number = (number + 3)". These statements increment
the value of the variable "number" by 3 in each iteration of the for loop. This ensures that the program
will display the numbers 1 to 19 in steps of 3, as required by the question.

Rate this question:



8.

Complete the program fragment using a for statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.for (int number = 1 ; number <= 19 ; number =
number + 3) cout <<__________<< endl ;

Explanation

The given correct answer is "number". In the for loop, the variable "number" is being incremented by 3
in each iteration, starting from 1 and ending at 19. So, when we print the value of "number" in each
iteration, it will display the numbers 1, 4, 7, ..., 19.

Rate this question:



9.

Complete the program fragment using a for statement that will display the numbers 1 to 19 ( in steps of
3, i.e. 1, 4, 7, ..., 19) with one number per output line.for (int number = 1 ; number <= 19 ; number =
number + 3) cout << number <<______ ;

Explanation

The "endl" statement is used to insert a new line after each number is displayed. This ensures that each
number is printed on a separate line, as required by the question.

Rate this question:



10.

Complete the following partially written program which is supposed to read 10 integer values using a
loop, and find the sum total of those numbers.void 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 ;} // end main

Explanation

The correct answer is "k = 1" because the program is using a while loop to iterate 10 times and read 10
integer values. The variable "k" is used as a counter to keep track of the number of iterations. By setting
"k = 1" initially, the loop will run 10 times as long as "k" is less than or equal to 10.

Document information

Uploaded on
May 23, 2025
Number of pages
30
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$11.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TUTOROUINE
3.1
(10)
Sold
50
Followers
0
Items
1666
Last sold
2 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions