This is an example of the composition of classes. But my code doesn't show a correct answer. This program must calculate the length of the line segment in the coordinates of the two ends of the line segment! I don't know what to do in the main function. this code consists of two classes.
#include <cmath>
#include <iostream>
using namespace std;
class point {
private:
float x;
float y;
public:
void setpoint(float abscissa, float ordinate) {
x = abscissa;
y = ordinate;
}
float getx() { return x; }
float gety() { return y; }
};
class LineSegment {
public:
float length() {
result = sqrt(pow(a.getx() - b.getx(), 2) + pow(a.gety() - b.gety(), 2));
return result;
}
void displayMessage() { cout << result; }
private:
float result;
point a;
point b;
};
int main() {
point a;
float q, s;
cout << "Enter two numbers for first point:\n";
cin >> q >> s;
a.setpoint(q, s);
point b;
float e, r;
cout << "Enter two numbers for second point:\n";
cin >> e >> r;
a.getx();
a.gety();
LineSegment pt;
pt.length();
pt.displayMessage();
return 0;
}