Hi everyone I'm a newbie to programming and self-taught C++ by a website. I'm writing a program to calculate the distance between the beginning and the end point. Here's my code
File Point.cpp:
#include<iostream>
#pragma once
using namespace std;
class Point {
private:
int x;
int y;
public:
Point() {
}
Point(int x, int y) {
this->x = x;
this->y = y;
}
void setX(int x) {
this->x = x;
}
int getX() {
return x;
}
void setY(int y) {
this->y = y;
}
int getY() {
return y;
}
};
File Line.cpp :
#include<iostream>
#include<math.h>
#include "Point.cpp"
class Line {
private:
Point begin;
Point end;
public:
Line(Point begin, Point end) {
this->begin = begin;
this->end = end;
}
Line(int x1, int y1, int x2, int y2) {
x1 = begin.getX();
y1 = begin.getY();
x2 = end.getX();
y2 = end.getY();
}
void setBegin(Point begin) {
begin.setX(int x1);
begin.setY(int y1);
}
Point getBegin() {
return begin;
}
void setEnd(Point end) {
end.setX(int x2);
end.setY(int y2);
}
Point getEnd() {
return end;
}
double getLength() {
return sqrt( (begin.getX() - end.getY())*(begin.getX() - end.getY()) + (begin.getX() - end.getY())*(begin.getX() - end.getY()) );
}
};
In file Line.cpp, the setEnd and setBegin can't run and the error said "type name is not allowed" for the parameters of setters although I've made pointers for them.
Hope anyone can have a good explanation and fix my code. Thank you.