This a a hw assignment, and I haven\'t been about to figure it out. If possible
ID: 3568101 • Letter: T
Question
This a a hw assignment, and I haven't been about to figure it out. If possible please make some notes as you go as to what the line is doing so I can learn. Thank you very much for any help.
This question has been asked before on Chegg, but none of the answers are complete. You can use those answers to save some time, but please don't copy&paste the whole thing because those answers are incomplete.
Create a class to store Distance
Store the data points x1, y1, x2, y2 in the private section of the class as doubles.
Provide public member functions to set the values into the class.
Provide a member function called GetDistance that returns the distance between the points.
Example of using the class: void main()
{
Distance a; // create a Distance object
Double length; // set the values into the object;
a.setx1(12.0)
a.sety1(20.0)
a.setx2(40.0)
a.sety2(50.0)
length = a.GetDistance();
cout <<
Explanation / Answer
#include <cmath>
#include <iostream>
using namespace std;
class Distance
{
public:
Distance()
{
}
Distance(double xx1 ,double yy1,double xx2,double yy2)
{
x1=xx1;
x2=xx2;
y1=yy1;
y2=yy2;
}
double GetDistance(){
double distance =sqrt(pow((x1-x2),2)+pow((y1-y2),2));
return distance;
}
void setx1(double x)
{
x1=x;
}
void setx2(double x)
{
x2=x;
}
void sety1(double y)
{
y1=y;
}
void sety2(double y)
{
y2=y;
}
double getx1()
{
return x1;
}
double getx2()
{
return x2;
}
double gety1()
{
return y1;
}
double gety2()
{
return y2;
}
private:
double x1,x2,y1,y2;
};
int main(){
Distance a(12.0, 20.0, 20.0, 50.0);
cout << "Point 1: x = " << a.getx1() << " y = " << a.gety1() << " ";
cout << "Point 2: x = " << a.getx2() << " y = " << a.gety2() << " ";
cout<<a.GetDistance()<<endl;
return 0;
}
//Distance(firstx ,firsty,Secondx1,Secondy);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.