cpp3_code_s08 - CGS-2421 C+ EXAM 3 CODING PART USERNAME _...

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

View Full Document Right Arrow Icon
CGS-2421 C++ EXAM 3 CODING PART SPRING 2008 USERNAME ___________________ NAME __________________________________ 1. ( 15 pts ) Suppose we want to add a new method to the Point class discussed in chapter 8 of the lecture notes. class Point { private: double x; double y; public: ... double dist(Point &); // new method }; This method will measure the distance between two Point objects. Example: Point p1(1.0,2.0); Point p2(-2.0,6.0); cout << "distance:" << p1.dist(p2); In the example, the distance between p1 and p2 is ( ) ( ) 2 2 1 ( 2) 2 6 5 - - + - = --------------------------------------------- Your Solution -------------------------------------------- double Point::dist(Point &p) { return (sqrt(pow(x-p.x,2)+pow(y-p.y,2))); }
Background image of page 1

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

View Full DocumentRight Arrow Icon
USERNAME ___________________ NAME ______________________________EX.3 2. (15 pts ) This question is related to the string class. You are a part of the C++ development team that is re-designing the string class. You are given the task of adding a method to the class that overloads the -= operator. Given two string objects, s1 and s2, a
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.

Page1 / 4

cpp3_code_s08 - CGS-2421 C+ EXAM 3 CODING PART USERNAME _...

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