Question
a) Which line in the class definition contains the constructor? b) Give the prototype and defintion for the overloaded + operator, that will add two
a) Which line in the class definition contains the constructor?
b) Give the prototype and defintion for the overloaded + operator, that will add two points. You can define the addition of two points as follows: (x1,y1) + (x2,y2) = (x1+y1,x2+y2)
prototype:_____________________________________________
definition:
c) Assume the class defintion above, plus the added overloaded addition from question b). What is printed by the following code?
int main()
{
// Some points.
Point a(5.2, -4.8);
Point b(1.0, 9.0);
Point d; //look at default values
a.print();
b.print();
d.print();
cout
b.move(2,-5);
b.print();
(a + b).print();
cout
b.print();
cout
d.print();
cout
}
d ) Suppose that we want users to input a point in the following format (note that the numbers here are just examples; the user can input any doubles): (2,3.5) Give the prototype and definition for the overloaded >> operator.
prototype:____________________________________________________________
definition:
2) Here is a class definition for a Point class. Objects in the class represent points on the Cartesian Graph. 1 class Point 2 public Uses default arguments to allow calling with zero, one or two values. Point (double x 0.0, double y 0.0) Computes distance to another point using Pythagorean theorem. double dist (Point other) Move the existing point. void move (double a double b) //print the point nicely 10 void print 11 12 private: 13 double xval double val; 15 Point:: Point (double x, double y) xval yval void Point move (double a double b) xval val b; double Point dist (Point other) double xd J xval other. xval; double ya yval other yval return sart (xd*xd yd yd); void Point print cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started