COMP-051: Mock Midterm 4, Modules 1-6 Format: 18 multiple choice + 2 function-writing questions, 5 points each = 100 points total. PART 1: MULTIPLE CHOICE (5 points each) 1. What is the correct order of stages turning C++ source into a running program? A. Source, Compiler, Assembly, Assembler, Machine Code B. Source, Assembler, Compiler, Assembly, Machine Code C. Machine Code, Assembly, Assembler, Compiler, Source D. Source, Machine Code, Compiler, Assembly, Assembler 2. What is C++ best described as, relative to C? A. A completely unrelated language B. A superset of C adding features like classes C. An older version of C D. A scripting language for C 3. What does a compiler primarily do? A. Runs the program directly B. Deletes unused variables at runtime C. Translates source code into another form D. Connects to the internet to fetch libraries 4. Which type best fits a whole number count, like a student count? A. float B. bool C. char D. int 5. What does cin do in C++? A. Reads input from the user B. Prints output to the screen C. Declares a new variable D. Compiles the program 6. What does cout << "Hi"; do? A. Reads "Hi" from input B. Prints "Hi" to output C. Declares a string named Hi D. Compares Hi to another value 7. What does an if/else statement do? A. Repeats a block of code B. Declares a function C. Chooses one of two paths based on a condition D. Defines a class 8. What is true about a switch statement's default case? A. It always runs first B. It is required syntactically C. It only works with strings D. It runs only if no other case matches 9. What does the condition (x == 5) check? A. Checks whether x is equal to 5 B. Assigns 5 to x C. Checks whether x is not 5 D. Declares x as type int 10. What is the key difference between while and do-while loops? A. while always runs the body at least once B. do-while always runs the body at least once C. They are identical in every way D. do-while cannot use a condition 11. What does the break keyword do inside a loop? A. Skips to the next iteration B. Restarts the loop from the beginning C. Exits the loop immediately D. Pauses the program 12. What does rand() % 6 + 1 simulate? A. A coin flip B. A random letter C. An infinite loop D. A single six-sided die roll 13. What is the index of the first element in a C++ array? A. 0 B. 1 C. -1 D. It depends on the array 14. Why use an array instead of many separate variables? A. Arrays are always faster to compile B. Arrays let you loop over related values with one name C. Arrays automatically sort themselves D. Arrays cannot hold numbers 15. What does grades[2] access in an array named grades? A. The first element B. The second element C. The third element D. The last element 16. What is one reason to write a function? A. To make code run slower on purpose B. To prevent the program from compiling C. To avoid using variables D. To reuse a block of logic under one name 17. In int add(int a, int b), what does the leading int represent? A. The function's return type B. The function's name C. The number of parameters D. A parameter's default value 18. What happens when a function is called without using its return value? A. The program always crashes B. The returned value is simply discarded C. The function runs twice D. A compile error always occurs PART 2: WRITE THE FUNCTION (5 points each) 19. Write a C++ function int square(int n) that returns n multiplied by itself. 20. Write a C++ function bool isEven(int n) that returns true if n is even, false otherwise.