Midterm 1 sol

# Midterm 1 sol - Last name SID(last 4 digits First name...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Section I: Multiple choice – 3 points each 1. You are writing an inventory program, and need a variable to hold the number of cans in a box, which is 48 for the type of boxes your store currently handles. All of the following options are syntactically correct, but only one is in good style : which is it? a. const int N = 48; b. int cans_per_box = 48; c. int n = 48; d. int N = 48; e. const int CANS_PER_BOX = 48; f. const int cans_per_box = 48; 2. Which of the following statements does not have any syntax errors? (Assume int variables n1 , n2 , and n3 have all been correctly declared and initialized as needed). a. cout << n1; << n2; << n3; b. cout << n1, n2, n3; c. cin >> n1, n2, n3; d. cin >> n1 >> n2 >> n3; e. b) and c) f. none: all of them are syntactically correct 3. What is the exact output of the following code fragment? (Note : the dots on the last line of each answer are simply to help you count spaces) double x = 98.7656789; cout << fixed << setprecision(1); cout << setw(8) << x << endl; cout << setprecision(3); cout << setw(8) << x << endl; a. 98.8 98.766 ............. b. 98.70000 98.76500 ........ c. 98.7 98.765 ........ d. 98.7 98.765 ........ e. 98.8 98.766 ........ f. 98.8 98.766 ........ 4. What is the value of n after the following code executes? int n = 10; n += 4; n = n / 4; n = n % 2; n *= 35; a. 0 b.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

Midterm 1 sol - Last name SID(last 4 digits First name...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online