{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cs10_sample_midterm_sol

# cs10_sample_midterm_sol - CS 010 Intro to Computer Science...

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

CS 010 – Intro to Computer Science I Fall - 2007 Midterm – practice exam SOLUTION Each question is worth 1 point. 1. What will be output by the following code fragment? double f = 123.4567 cout << fixed << setprecision(5) << f << " " << setprecision(1) << f << endl; a. 123.45 1 b. 123.4567 123.4 c. 123.45670 123.4 d. 123.45670 123.5 e. 123.4567 123.4567 f. none of the above 2. What is the value of f after the code in the previous question executes? 3. What is the value of sum after the following code fragment executes? Point p = Point(2, 7); Circle c = Circle(p, 5); c.move(2, 4); double sum; sum = c.get_center().get_x() + p.get_y() + c.get_radius(); a. 16 b. 18 c. 20 d. 9 e. 14 f. None of the above 4. Which of the following expressions has the value false ? 5. Which of the following expressions has the value true ? 6. What will be output by the cout statement in the following code fragment if the user types The quick brown fox jumped over the lazy dog. and then hits enter when prompted for a sentence?

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

View Full Document
string s; cout << "Enter a sentence:\n"; cin >> s; cout << s; a. The b. The quick brown fox jumped over the lazy dog. c. dog. d. none of the above 7. What will be the exact output by the cout statement in the following code fragment? Time t1 = Time(1, 1, 1); Time t2 = Time(1, 2, 2); cout << t2.seconds_from(t1); 8. Given the following statement at the top of the program: cwin.coord(-1000, 1000, 10, -10); Which of the following statements would NOT produce output within the output window? 9. What will be output to the window by the following code fragment (assume default window coordinates)? Point pt1 = Point(0, 0); Point pt2 = pt1; pt2.move(0, -7); Line line1 = Line(pt1, pt2); cwin << line1; line1.move(-5, 0); pt1.move(-5, 0); cwin << line1 << Line(pt1, pt2);
This is the end of the preview. Sign up to access the rest of the document.