Question: can someone fill in the code? can someone fill in my code // SPECIFICATION: This program is the application class that uses the Point2D //
can someone fill in the code?
can someone fill in my code
// SPECIFICATION: This program is the application class that uses the Point2D // It creates objects and verifies the functions of Point2D // INSTRUCTIONS: Read the following code skeleton and add your own code // according to the comments. Ask your TA or your class- // mates for help and/or clarification. When you see // //--> that is where you need to add code. //-------------------------------------------------------------------------*/ // include the required files //--> using namespace std; int main() { //Lets create a point(0,0) (use default constructor) and name it pointA; //--> //Lets create a point(2,2) and name it pointB; //--> //Lets print the details of the points cout<<"The points pointA and pointB are: "; // Print pointA //--> // Print pointB //--> //Find the distance between pointA and pointB and print it. //--> cout<<"Distance between pointA and pointB is "<??<<" "; //Lets shift the points pointA and pointB by (3,3) //Use the move function to shift the point cout<<"Moving the points by (3, 3) "; // Move pointA by (3,3) //--> // Move pointB by (3,3) //--> //Lets the print the new details of the changed points cout<<"The new points pointA and pointB are: "; //--> //--> //Lets see if the distance between pointA and pointB has changed //Find the new distance between pointA and pointB and print it. // Print out "The new distance between the pointA and pointB is ....[Fill the rest] //--> //Show that vector addition works with our Point2D objects. //We will show that if //a1 = (x1, y1) and a2 = (x2, y2), then //if a3 = a1 + a2 it implies a3 will be (x1+x2, y1+y2) //Example a1 = (1,1) and a2 = (2,3) then //a3 = a1 + a2 implies a3 = (3,4); //Create point a1 = (1,1) //--> //Create point a2 = (2,3) //--> //Create point a3 = (3,4) //--> cout<<"The points a1 and a2 are: "; a1.print(); a2.print(); cout<<"The sum a3 = a1 + a2 is "; a3.print(); //Call the add function using a1 and a2 and assign the result to new_a3 //--> cout<<"The point new_a3 = a1.add(a2) is "; //--> //Check if a3 and new_a3 are equal using the equals function. If they are equal print "My vector addition works!!" // else print "My vector addition fails!!" if(???) //--> else //--> //Lets now do the same for subtraction. //We will show that if //s1 = (x1, y1) and s2 = (x2, y2), then //if s3 = s1 - s2 it implies s3 will be (x1-x2, y1-y2) //Example s1 = (1,1) and s2 = (2,3) then //s3 = s1 - s2 implies s3 = (-1,-2); //Lets use user input to create two points and subtract them double x1, y1, x2, y2; cout<<"Enter details of s1 "; cout<<"x = "; cin>>x1; cout<<"y = "; cin>>y1; //Create point s1 using x1 and y1 //--> cout<<"Enter details of s2 "; cout<<"x = "; cin>>x2; cout<<"y = "; cin>>y2; //Create point s2 using x2 and y2 //--> //Create point s3 as (x1-x2, y1-y2) //--> //Call the sub function using s1 and s2 and assign the result to new_s3 //--> cout<<"The points s1 and s2 are: "; s1.print(); s2.print(); cout<<"The difference s3 = s1 - s2 is "; s3.print(); //Call the sub function using s1 and s2 and assign the result to new_s3 cout<<"The point new_s3 = s1.sub(s2) is "; new_s3.print(); //Check if s3 and new_s3 are equal using the equals function. If they are equal print "My vector subtraction works!!" // else print "My vector subtraction fails!!" //--> return 0; } // SPECIFICATION: This is the implementation of Point2D class // INSTRUCTIONS: Read the following code skeleton and add your own code // according to the comments. Ask your TA or your class- // mates for help and/or clarification. When you see // //--> that is where you need to add code. //-------------------------------------------------------------------------*/ // Include the required files and libraries //--> //Define the Default constructor Point2D::Point2D() { //Assign 0.0 to both zval and yval //--> //--> } //Define the two argument constructor with arguments x and y //--> { // Assign the x and y to xval and yval respectively //--> //--> } // Define the method x which returns the xval //--> // This method returns the yval of the point double Point2D::y() { return yval; } // Define the method dist which takes a Point2D as input and returns a double //--> { // calculate xd by subtracting this point's xval with the input point's xval double xd = ??? // calculate yd by subtracting this point's yval with the input point's yval double yd = ??? // return the square root of (xd*xd + yd*yd) return ????; } //Adds the two points and returns the result Point2D Point2D::add(Point2D b) { return Point2D(xval + b.x(), yval + b.y()); } //Subtracts the two points and returns the result. Point2D Point2D::sub(Point2D b) { // Use the add function for hint //--> } // Define the function move which takes a and b as inputs and adds them to xval // and yval respectively //--> // Define the print function that prints: (xval,yval) followed by newline //--> //Compares if the two points are equal //Points are equal if their respective xval and yval are equal bool Point2D::equals(Point2D other) { // Compare if the xval of this point equals the xval of the input and if yval of this point equals yval of input point if(???) return true; else return false; } // SPECIFICATION: The header file for the Point2D class.
// Point2D is two dimensional point with values xval and yval // INSTRUCTIONS: Read the following code skeleton and add your own code // according to the comments. Ask your TA or your class- // mates for help and/or clarification. When you see // //--> that is where you need to add code. //-------------------------------------------------------------------------*/ #includeusing namespace std; class Point2D { private: double xval, yval; public: Point2D(double, double); Point2D(); double x(); double y(); double dist(Point2D); Point2D add(Point2D); Point2D sub(Point2D); void move(double, double); bool equals(Point2D); void print(); };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
