Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING C++: The following is the header file code needed to answer the question: //implement a class that keeps track of the coordinates of a

USING C++:

The following is the header file code needed to answer the question:

//implement a class that keeps track of the coordinates of a point in the X-Y plane class coord { public: coord(double a = 0, double b = 0); //default constructor: initializes coordinates x_coord and y_coord to a and b respectively. void set(double a, double b); //sets the coordinates to (a,b) void display() const; //prints the coordinates in the following format // (x_coord, y_coord) //e.g. if x_coord=3.4, y_coord=-7 then it will print out (3.4, -7) void scale(double k); //scales each coordinate by k (i.e. each coordinate is multiplied by k) //e.g. if point has coordinates (10, -5) and k=10, then the new coordinate is (100,-50) double distance() const; //returns the Euclidian distance of the point from the origin //if coordinates of the point are (x,y) then the distance from the origin is given by // d=sqrt(x^2+y^2) where sqrt is the square root function //e.g. if point has coordinates (3, -4), then d=sqrt(3^2+4^2)=5 double distance(coord p) const; //returns the Euclidian distance of the point p //if coordinates are (x,y), and the coordinates of p are (a,b) then the distance from p is given by // d=sqrt((x-a)^2+(y-b)^2) where sqrt is the square root function //e.g. if the coordinates are (2, -5) and p has coordinates (-1,1) then d=sqrt((2+1)^2+(-5+1)^2)=5 private: double x_coord; //x coordinate double y_coord; //y coordinate };

Referring to the header file above, Implement the following two members of the class coord but answer with only the implemented member functions not the entire program:

double distance() const; //returns the Euclidian distance of the point from the origin //if coordinates of the point are (x,y) then the distance from the origin is given by // d=sqrt(x^2+y^2) where sqrt is the square root function //e.g. if point has coordinates (3, -4), then d=sqrt(3^2+4^2)=5 double distance(coord p) const; //returns the Euclidian distance of the point p //if coordinates are (x,y), and the coordinates of p are (a,b) then the distance from p is given by // d=sqrt((x-a)^2+(y-b)^2) where sqrt is the square root function //e.g. if the coordinates are (2, -5) and p has coordinates (-1,-1) then d=sqrt((2+1)^2+(-5+1)^2)=5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

(e) What is the resolution?

Answered: 1 week ago