cs10_sample_midterm_sol

cs10_sample_midterm_sol - CS 010 Intro to Computer Science...

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

View Full Document Right Arrow Icon
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? a. 1 b. 123.4 c. 123.5 d. 123.4567 e. 123.5567 f. none of the above 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 ? a. 5 == 5 b. ("HELLO" == "hello") or (4 < 5) c. (2 < 4) and (3 == 5) d. 4 % 5 5. Which of the following expressions has the value true ? a. 5 != 5 b. (4 < 5) and ("h" == "H") c. (3 + 5) <= (2 * 4) d. ("hello" == "HELLO") or (5 != 5) 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?
Background image of page 1

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

View Full DocumentRight Arrow Icon
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); a. 1 b. 3 c. 61 d. 3661 e. 1:1:1 f. (1,1,1) 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? a. cwin << Point(100, -100); b. cwin << Point(0, 0); c. cwin << Point(-100, 100); d. cwin << Point(0, 500); 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); a. a shape in the form of a capital Z b. a shape in the form of a capital H c. a shape in the form of a capital N d. 3 parallel lines e. a shape in the form of a triangle f. 2 non-parallel lines 10. The following statement has a syntax error given a Point p has already been declared and
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/05/2008 for the course CS CS10 taught by Professor Linard during the Spring '08 term at UC Riverside.

Page1 / 9

cs10_sample_midterm_sol - CS 010 Intro to Computer Science...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online