(I'm new to use this platform, sorry if I ask the question incorrectly .)
I'm trying to pass the coordination of point to the segment class,
in order to compute length of the segment,
but codeblocks return error message:
could someone tell me how to solve this problem
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
public:
Point(float in1, float in2):x(in1),y(in2){};
float x, y;
};
class Segment
{
public:
Segment(Point in1, Point in2){
this->a.x = in1.x;
this->a.y = in1.y;
this->b.x = in2.x;
this->b.y = in2.y;
};
float length() //return the length of segment
{
float delta_x = a.x - b.x, delta_y = a.y - b.y;
return sqrt( delta_x * delta_x + delta_y * delta_y);
};
private:
Point a, b;
};
int main(){
Point a(12,5),b(6,6);
Segment seg1(a, b);
cout << seg1.length();
}