exam3-review - Exam3Review Problem1...

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

View Full Document Right Arrow Icon
    Exam 3 Review
Background image of page 1

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

View Full DocumentRight Arrow Icon
    Problem 1 Write a program that prints the tokens given on  the command line in reverse order.
Background image of page 2
    Solution 1 int main (int argc, char **argv) { for (int i = argc -1; i >= 0; i--) cout << argv[i] << “ “; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
    Problem 2 The class Point has the following contructor and  public function: Point(double, double) int distance_to_origin() Write a code fragment that creates an object of  type Point representing (-1.0, 2.5) and prints the  length of the line drawn from (-1.0, 2.5) to the  origin.
Background image of page 4
    Solution 2 Point p1(-1.0, 2.5); int dist = p1.distance_to_origin(); cout << dist << endl; OR Point p1(-1.0, 2.5); cout << p1.distance_to_origin() << endl;
Background image of page 5

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

View Full DocumentRight Arrow Icon
    Problem 3 Write a function called find_max that has a single  integer parameter.   The function reads integers from the keyboard until  EOT (ctrl+d) is entered. If at least one positive integer is read, the function sets  the input parameter equal to the maximum positive  integer read and returns true, otherwise sets the input  parameter to zero and returns false. Let us assume the user enters only integers and  whitespace.
Background image of page 6
    Solution 3 int cur; bool found_int = false; max = 0; while (cin >> cur) { found_int = true; if (cur > max) max = cur; } return found_int; }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/08/2010 for the course CS CS 141 taught by Professor Mcguire during the Spring '10 term at Clarkson University .

Page1 / 19

exam3-review - Exam3Review Problem1...

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

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