COMP-051: Mock Midterm 3, 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 does #include do at the top of a C++ program? A. Starts running the program B. Declares the main function C. Makes cin and cout available D. Compiles the file into machine code 2. What is the purpose of int main() in a C++ program? A. It is where program execution begins B. It declares a global variable C. It prints the program's output D. It ends the program immediately 3. What is machine code? A. Human-readable source code B. A comment the compiler ignores C. A kind of variable type D. Binary instructions the CPU runs directly 4. What is the result of 7 / 2 when both values are int? A. 3 B. 3.5 C. 4 D. 2 5. Which type stores a single character such as 'A'? A. bool B. char C. double D. int 6. What does the statement x = x + 1; do? A. Compares x with x + 1 B. Declares a new variable x C. Prints x + 1 to the screen D. Adds 1 to x and stores the result in x 7. What does the != operator check? A. Assigns one value to another B. Checks whether two values are not equal C. Checks whether one value is greater D. Negates both values 8. In if (age >= 18 && hasID), when is the whole condition true? A. Only when both parts are true B. When either part is true C. Only when age is exactly 18 D. Always, regardless of values 9. What is the purpose of else if? A. Runs its code in every case B. Repeats the first if again C. Tests another condition if the first if is false D. Ends the program early 10. How many times does for (int i = 0; i < 5; i++) run its body? A. 4 times B. 5 times C. 6 times D. Forever 11. What happens if a while loop's condition never becomes false? A. The compiler reports an error B. The loop runs exactly once C. The loop is skipped entirely D. The loop runs forever 12. Which part of a for loop runs after each iteration of the body? A. The update (i++) B. The initialization (int i = 0) C. The return statement D. The #include line 13. What does int grades[30]; declare? A. One int set to 30 B. A 30-character string C. An array of 30 ints D. A function named grades 14. Which vector method adds an element to the end? A. size() B. push_back() C. insert_last() D. add() 15. What does grades[0] + grades[1] compute for an array named grades? A. The first element only B. The array's length C. The last element D. The sum of the first two elements 16. What is function overloading? A. Same name, different parameter lists B. Calling a function twice in a row C. A function with no return value D. A function defined inside a loop 17. Where can a variable declared inside a function be used? A. Anywhere in the program B. Only inside main C. Only inside that function D. Only inside loops 18. What does a return statement do inside a function? A. Prints the value to the screen B. Ends the function and sends a value back C. Declares the function's return type D. Runs the function again PART 2: WRITE THE FUNCTION (5 points each) 19. Write a C++ function int countPassing(int grades[], int size) that returns how many values in grades are 60 or greater. Use a loop. 20. Write a C++ function double toCelsius(double fahrenheit) that returns the Celsius equivalent, using (F - 32) * 5 / 9.