CPS 150 Final Exam Study Questions From Test #2

50 Questions | Total Attempts: 27

SettingsSettingsSettings
CPS Quizzes & Trivia

Next Set of Questions continued from the first test


Questions and Answers
  • 1. 
    What is the output from the following fragment?z = 15 ;while (z <= 20)     z = z + 2 ;cout << z << endl ;
    • A. 

      15

    • B. 

      17

    • C. 

      19

    • D. 

      20

    • E. 

      21

  • 2. 
    Which of the following program fragments is an infinite loop?/* fragment P */z = 10 ;while (z <= 20)  z = z + 1 ;/* fragment Q */z = 30 ;while (z <= 20)  z = z - 1 ;/* fragment R */z = 10 ;while (z <= 20) ;z = z + 1 ;
    • A. 

      Only P

    • B. 

      Only Q

    • C. 

      Only R

    • D. 

      P and Q

    • E. 

      P and R

  • 3. 
    Which of the following statements about value parameters is true?
    • A. 

      The argument is never modified by execution of the called function

    • B. 

      The parameter is never modified by execution of the called function

    • C. 

      The argument must be a variable

    • D. 

      The argument can not have a Boolean value

    • E. 

      Both a and b

  • 4. 
    Which of the following statements about const value parameters is true?
    • A. 

      The argument is never modified by execution of the called function

    • B. 

      The parameter is never modified by execution of the called function

    • C. 

      The argument must be a variable

    • D. 

      The argument can not have a Boolean value

    • E. 

      Both a and b

  • 5. 
    A program contains the line x = x + y ; inside a loop. What is the best description of variable x?
    • A. 

      Counter

    • B. 

      Loop control variable

    • C. 

      Accumulator

    • D. 

      Undeclared variable

    • E. 

      Uninitialized variable

  • 6. 
    A program contains the line x = y ;This is the first mention of variable x in the program. What is the best description of variable x?
    • A. 

      Counter

    • B. 

      Loop control variable

    • C. 

      Accumulator

    • D. 

      Undeclared variable

    • E. 

      Uninitialized variable

  • 7. 
    A program contains the line int x ; The variable x does not appear anywhere else in the program. What is the best description of variable x?
    • A. 

      Counter

    • B. 

      Loop control variable

    • C. 

      Accumulator

    • D. 

      Undeclared variable

    • E. 

      Uninitialized variable

  • 8. 
    How many lines are printed by this program segment?for (J = 1 ; J <= 5 ; J++) ;for (K = 13 ; K >= 11 ; K--)    cout << "Hello\n" ;
    • A. 

      8

    • B. 

      5

    • C. 

      15

    • D. 

      3

    • E. 

      Infinite

  • 9. 
    The function prototype     double mySqrt( int x ) ;
    • A. 

      Declares a function called mySqrt which takes an integer as an argument and returns a double

    • B. 

      Defines a function called double which calculates square roots

    • C. 

      Defines a function called mySqrt which takes an argument of type x and returns a double

    • D. 

      Declares a function called mySqrt which takes a double as an argument and returns an integer

  • 10. 
    Using the following function definition layout :A B( C ) {     D}the parameter list is represented by?
    • A. 

      A

    • B. 

      B

    • C. 

      C

    • D. 

      D

  • 11. 
    Which of the following is an advantage of using functions in writing programs?
    • A. 

      We could use many parameters

    • B. 

      We could write programs that are bigger than necessary

    • C. 

      We could write programs that are difficult to understand

    • D. 

      We could make writing programs a complicated task

    • E. 

      We could use the same functions in different programs

  • 12. 
    What is the output from this program fragment?for (K = 4 ; K >= 1 ; K--) {   sum = 0 ;   sum = sum + K ;} // end forcout << sum << endl ;
    • A. 

      1

    • B. 

      2

    • C. 

      3

    • D. 

      4

    • E. 

      None of the above

  • 13. 
    A function that does not return a value to the calling statement has a special return type called?
    • A. 

      Null

    • B. 

      Void

    • C. 

      Prototype

    • D. 

      Bool

    • E. 

      Int

  • 14. 
    Consider the program given below with the inputs in the order they would be entered into the program.#include <iostream>using namespace std ;void main () {    int m, n ;    cin >> n ;    m = n ;    while (n > 0) {         if (n < m)            m = n ;         cin >> n ;    } // end while    cout << m << endl ;} // end mainInput:3941443612554100What is the value displayed by the cout statement?
    • A. 

      41

    • B. 

      0

    • C. 

      39

    • D. 

      5

    • E. 

      54

  • 15. 
    Consider the program given below with the inputs in the order they would be entered into the program.#include <iostream>using namespace std ;void main () {    int m, n ;    cin >> n ;    m = n ;    while (n > 0) {         if (n < m)            m = n ;         cin >> n ;    } // end while    cout << m << endl ;} // end mainInput:3941443612554100How many times is the variable m assigned a value within the loop?
    • A. 

      0

    • B. 

      1

    • C. 

      2

    • D. 

      3

    • E. 

      4 or more

  • 16. 
    What is the output from this program fragment?for (int j = 0 ; j < 3 ; j ++) {   for (int k = j ; k < 3 ; k ++) cout << ' * ' ;   for (int k = 0 ; k < j ; k ++) cout << '   ' ;   cout << endl ;} // end for j
    • A. 

      *** *** ***

    • B. 

      *** ** *

    • C. 

      * ** ***

    • D. 

      * ** ***

    • E. 

      *** ** *

  • 17. 
    What is the value returned by the function sum for this call?sum (67.58, 50.94)The code for function sum is given below:int sum( int num1, int num2 ) {     return( num1 + num2 ) ;} // end sum
    • A. 

      118

    • B. 

      118.52

    • C. 

      119

    • D. 

      117

    • E. 

      None of the above

  • 18. 
    Which of the following program fragment(s) calculate(s) the sum1 + 2 + 3 + ...10 correctly?/* fragment P */sum = 10 ;x = 1 ;while (x < 11) {    sum = sum + x ;    x = x + 1 ;}/* fragment Q */sum = 10 ;x = 1 ;while (x <= 10) {    sum = sum + x ;    x = x + 1 ;}/* fragment R */sum = 10 ;for (x = 1 ; x < 10 ; x++)   sum = sum + x
    • A. 

      Only P

    • B. 

      Only Q

    • C. 

      Only R

    • D. 

      All of those

    • E. 

      None of those

  • 19. 
    You want to write a loop to read a large number of data values.The end of input os to be signaled by a sentinel value.Which of the following is a true statement?
    • A. 

      Sentinel must be a very large number

    • B. 

      Sentinel must be zero

    • C. 

      Sentinel can be anything that does not appear in the actual input, but only at its end

    • D. 

      Sentinel value must appear several times within the actual input and also at the end

    • E. 

      Sentinel must be negative

  • 20. 
    How many lines are printed by the program segment?(*Note two values on one line count only as one line)for (J = 1 ; J <= 5 ; J ++)   for (K = 13 ; K >= 11 ; K --)       cout << J << '   ' << K << endl ;
    • A. 

      8

    • B. 

      5

    • C. 

      15

    • D. 

      3

    • E. 

      Infinite

  • 21. 
    A function (other than main) can call another function.
    • A. 

      True

    • B. 

      False

  • 22. 
    The function that appears first within the program is the first one to be activated.
    • A. 

      True

    • B. 

      False

  • 23. 
    A program must contain another function in addition to the one called main.
    • A. 

      True

    • B. 

      False

  • 24. 
    The arguments must never have the same names as the parameters.
    • A. 

      True

    • B. 

      False

  • 25. 
    A function must have a return statement.
    • A. 

      True

    • B. 

      False

Back to Top Back to top