CPS 150 Final Exam Study Questions From Test #1

50 Questions | Total Attempts: 58

SettingsSettingsSettings
CPS Quizzes & Trivia

A compilation of previous test questions and their answers.


Questions and Answers
  • 1. 
    Which of the following is a C++ keyword?
    • A. 

      Number

    • B. 

      Integer

    • C. 

      Main

    • D. 

      Double

    • E. 

      Single

  • 2. 
    Which of the following about C++ identifiers is false?
    • A. 

      'Sales' and 'sales' are considered different identifiers

    • B. 

      An identifier cannot start with a digit

    • C. 

      'the average' is a valid identifier

    • D. 

      A keyword cannot be used as an identifier

    • E. 

      An identifier must be declared by the programmer or in an #included library

  • 3. 
    If you want to have a variable which can hold a number with a fractional part (such as 8.67) you should declare it to be of what type?
    • A. 

      Char

    • B. 

      Double

    • C. 

      Int

    • D. 

      String

    • E. 

      Bool

  • 4. 
    In C++, a (single line) comment begins with?
    • A. 

      \ \

    • B. 

      / /

    • C. 

      !

    • D. 

      *

    • E. 

      (*

  • 5. 
    To display the message Welcome ! the following can be used in C++
    • A. 

      Cout

    • B. 

      Cout >> "Welcome !" ;

    • C. 

      Cin

    • D. 

      Cout

    • E. 

      Cin >> Welcome ! ;

  • 6. 
    Which of the following will produce the output Hello World ?
    • A. 

      Cout

    • B. 

      Cout

    • C. 

      Cout

    • D. 

      Cout

    • E. 

      Cout

  • 7. 
    Which of the following is NOT a valid assignment statement?
    • A. 

      X = 15;

    • B. 

      X = y;

    • C. 

      15 = y;

    • D. 

      Y = x;

    • E. 

      Y = 15;

  • 8. 
    Which arithmetic operator will be performed first in calculating the value of a + b * c - d / e % f ?
    • A. 

      +

    • B. 

      -

    • C. 

      *

    • D. 

      /

    • E. 

      %

  • 9. 
    Which arithmetic operator will be performed last in calculating the value ofa + b * c - d / e % f ?
    • A. 

      +

    • B. 

      -

    • C. 

      *

    • D. 

      /

    • E. 

      %

  • 10. 
    The arithmetic expression a+b is written C++ as?                                      c+d
    • A. 

      (a+b) / c+d

    • B. 

      A+b / c+d

    • C. 

      A + (b/c) +d

    • D. 

      A+b/(c+d)

    • E. 

      (a+b) / (c+d)

  • 11. 
    For the expression x%y to be valid, data types of x and y should be (respectively)?
    • A. 

      Float and double

    • B. 

      Int and int

    • C. 

      Double and int

    • D. 

      Char and float

    • E. 

      Float and bool

  • 12. 
    Which pair of operators has the same precedence?
    • A. 

      + and *

    • B. 

      - and /

    • C. 

      + and /

    • D. 

      + and -

    • E. 

      - and *

  • 13. 
    Which of the following is not a relational operator in C++?
    • A. 

    • B. 

    • C. 

      >

    • D. 

      >=

    • E. 

      =

  • 14. 
    Which expression has the value true when someone's income is at least 15000 but less than 50000; and has the value false otherwise?
    • A. 

      15000

    • B. 

      (15000

    • C. 

      (15000 > income) && (income < 50000)

    • D. 

      (15000 50000)

    • E. 

      (15000 > income) || (income < 50000)

  • 15. 
    What is the output from the following program fragment?if ((2 + 2) == 4)   cout << "Ha Ha\n" ;else   cout << "Hee Hee\n" ;
    • A. 

      Ha Ha

    • B. 

      Hee Hee

    • C. 

      'Ha Ha' on one line followed by 'Hee Hee' on the next line

    • D. 

      No output because there is a syntax error

    • E. 

      No output, but there is no syntax error

  • 16. 
    For which values of number will this program display Hello on the output screen?if ((number % 2) == 0)   cout << "Hello" ;
    • A. 

      For any value in number

    • B. 

      For no value

    • C. 

      For positive numbers

    • D. 

      For even values

    • E. 

      For negative values

  • 17. 
    What is the output from the following program fragment?int k(4) , sum ;while (k >= 1) {   sum = 0 ;   sum = sum + k ;   k = k - 1 ;} // end whilecout << sum << endl ;
    • A. 

      1

    • B. 

      2

    • C. 

      3

    • D. 

      4

    • E. 

      None of these

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

      15

    • B. 

      17

    • C. 

      19

    • D. 

      20

    • E. 

      21

  • 19. 
    If x and y are integer variables, and we want to calculate the result of dividing x by y using real (floating point) division, we should use the expression?
    • A. 

      X / y

    • B. 

      Static_cast(x / y)

    • C. 

      Static_cast(x) / y

    • D. 

      1.0 * (x / y)

    • E. 

      (x / y) * 1.0

  • 20. 
    To generate a random integer value between 1 and 6 (both inclusive), we can use the expression:
    • A. 

      1 + rand() / 6

    • B. 

      6 + rand() / 1

    • C. 

      6 + rand() % 1

    • D. 

      1 + rand() % 6

    • E. 

      (1 + rand()) / 6

  • 21. 
    Consider the following C++ fragmentif (average == 100) ;   cout << "Congratulations!\n" ;Which of the following is NOT true?
    • A. 

      The message 'Congratulations' is displayed regardless of the value in the variable 'average'

    • B. 

      There is an empty (null) statement in this fragment

    • C. 

      This fragment contains a syntax error so the program will not run

    • D. 

      The if does not control the cout statement

    • E. 

      The output from the fragment will not change if the == is replaced by !=

  • 22. 
    Which of the following is true about the Boolean expression (ch != 'Y') || (ch != 'N') Assuming that ch is of type char?
    • A. 

      The expression has the value true regardless if the value in ch

    • B. 

      The expression has the value false regardless of the value in ch

    • C. 

      The value of the expression cannot be determined unless we know the value in ch

    • D. 

      The expression has a syntax error

    • E. 

      The expression is valid, but it is NOT a Boolean expression

  • 23. 
    If the variables test1, test2, test3 are all of int type, then which of the following expressions will calculate the average of their values correctly (it may have a fractional part)?
    • A. 

      Test1 + test2 + test3 / 3

    • B. 

      (test1 + test2 + test3) / 3

    • C. 

      Test1 + test2 + test3 / 3.0

    • D. 

      Test1 + test2 + (test3 / 3.0)

    • E. 

      None of the above

  • 24. 
    Which of the following is a true statement?
    • A. 

      A variable declared in the main function has a definite value just by being declared (as in int x ;)

    • B. 

      A variable can be given an initial value when declared, but it need not be done

    • C. 

      A variable must be given an initial value when declared (as in int x(5) ;

    • D. 

      All of the above

    • E. 

      None of the above

  • 25. 
    Which of the following statements has an output that cannot be predicted?
    • A. 

      Cout

    • B. 

      Cout

    • C. 

      Cout

    • D. 

      All of the above

    • E. 

      None of the above

Back to Top Back to top