CMPT 111 Mock Midterm 12010-2011University Learning Centre

CMPT 111 Mock Midterm 1 /
2010-2011 Term 1 /
This practice exam was prepared for you by your SSS coach (not your professor!).
It is designed to help you test yourself on the topics covered in class and should not be considered as a preview of the actual midterm.

Section 1: Multiple Choice

Circle the correct answer to the following questions.

  1. C++ is the only programming language.
  2. True
  3. False
  4. “Keep studying until you are too tired” is what type of task?
  5. Simple
  6. Conditional
  7. Repetitive
  8. Which one of these is NOT a simple data type?
  9. Text
  10. List
  11. Array
  12. Record
  13. Abstraction is the process of making things more detailed than they are.
  14. True
  15. False
  16. TRUE AND NOT (FALSE OR NOT TRUE)
  17. True
  18. False

Section 2: Variable Naming

Determine whether a variable is valid or invalid. If it’s invalid, explain why.

  • B- Valid
  • Canada-is-number-one- Invalid, due to the dash
  • _myVar- Valid
  • 4myVar- Invalid, variables can’t start with numbers
  • Int- Invalid, int is a reserved work (and so are if, float, etc.)
  • success!- Invalid, due to the exclamation point
  • ______peekaboo- Valid
  • This_variable_is_invalid- Valid

Section 3: Program Analysis

Circle all the statements that get executed in the following code fragments.


  1. Pseudocode

  2. C++

  3. Pseudocode

Section 4: Program Output

Write down what would be output to the screen if you were to run these programs.



  1. C++
    Output (Write in the space below)


  2. Pseudocode
    Output (Write in the space below)


  3. Pseudocode
    Output (Write in the space below)

Section 5: C++ Errors


Cross out the errors in this C++ program and correct them.

Section 6: Algorithm Creation

Create an algorithm to accomplish the following problems.

  1. Pseudocode
    Write a program to get a user to type in the number ‘42’. Prompt the user to enter a number repeatedly then give clues to try and get to the number ‘42’.
    If the guess is between 40 and 49, output “You’ve got the first digit!”
    If the guess is between 30 and 39, output “Hot!”
    If the guess is between 50 and 59, output “Warm!”
    If the guess is negative or three digits, output “Ice Cold!”
    Otherwise, output “Higher” or “Lower” depending on the number.
    Keep doing this until the user gets ‘42’. When they do, output “That’s the answer” and then exit the program.
    BONUS: If the user enters a number ending with ‘2’, output “You’ve got the last digit!”

(see s6q1.txt for a possible solution)

  1. C++
    Alice, Bob, and Carol are planning a Secret Santa this Christmas.
    (A Secret Santa is where each person secretly gives gifts to another person in the group)
    Therefore, write a computer program that will act as a 3rd-party to determine who gets whose name for gifts. The program should come up with a configuration first. Then, come up with a creative way to show each of the three friends their selection while still maintaining the secrecy.
    Hint: there are only 2 possible configurations, so to pick randomly in C++, use
    if (rand() % 2 < 1) { ... } else { ... }

(sees6q2.cpp for a possible solution)

NOTE: You don’t need to understand how the rand() part works yet.