This is my code. I think the problem would be Makefile or main.cpp but I can't figure it out.
And this is the description for this codes.
Your Point class will define an n-dimensional point. Your Point should have two constructors: a "default" constructor takes one integer, n, and constructs a point of n dimensions at the origin and a second constructor that takes either a vector or an array of integers as an argument.
You should add a method that reports how many dimensions this Point object is. It should have getter and setter methods for each coordinate and two methods, Distance, to calculate the Euclidian distance between this Point and one other point, and Translate, which moves all of this Points coordinates by whatever integer value is passed to the method. Note that Distance and Translate are methods of the Point class.
Your main function should create at least three points, calculate the distance between them, and report their coordinates and the calculated distances between them to the user. Do not prompt the user for the coordinates of the Points that you create.
Your main function should then translate one of the Points that you've created by a positive amount, then report the new coordinates and calculated distances between the translated point and the other points that you created to the user.
It should then translate the same Point by a negative amount (this amount does not need to be the same as the positive amount), then report the new coordinates and calculated distances between the translated point and the other points that you created to the user.
main.cpp
#include <iostream>
using namespace std;
#include "point.h"
int main()
{
Point p1(3,9),p2(2,5),p3(3,5);
cout<<"Distance between P1("<<p1.getXCordinate()<<","<<p1.getYCordinate()<<") and P2("<<p2.getXCordinate()<<","<<p2.getYCordinate()<<") is :"<<p1.distance(p2)<<endl;
cout<<"Distance between P2("<<p2.getXCordinate()<<","<<p2.getYCordinate()<<") and P3("<<p3.getXCordinate()<<","<<p3.getYCordinate()<<") is :"<<p2.distance(p3)<<endl;
cout<<"Distance between P3("<<p3.getXCordinate()<<","<<p3.getYCordinate()<<") and P1("<<p1.getXCordinate()<<","<<p1.getYCordinate()<<") is :"<<p3.distance(p1)<<endl;
p1.translate(2);
p2.translate(6);
p3.translate(8);
cout<<"\nAfter Translation :"<<endl;
cout<<"Distance between P1("<<p1.getXCordinate()<<","<<p1.getYCordinate()<<") and P2("<<p2.getXCordinate()<<","<<p2.getYCordinate()<<") is :"<<p1.distance(p2)<<endl;
cout<<"Distance between P2("<<p2.getXCordinate()<<","<<p2.getYCordinate()<<") and P3("<<p3.getXCordinate()<<","<<p3.getYCordinate()<<") is :"<<p2.distance(p3)<<endl;
cout<<"Distance between P3("<<p3.getXCordinate()<<","<<p3.getYCordinate()<<") and P1("<<p1.getXCordinate()<<","<<p1.getYCordinate()<<") is :"<<p3.distance(p1)<<endl;
p1.translate(-3);
p2.translate(-4);
p3.translate(-9);
cout<<"\nAfter Translation :"<<endl;
cout<<"Distance between P1("<<p1.getXCordinate()<<","<<p1.getYCordinate()<<") and P2("<<p2.getXCordinate()<<","<<p2.getYCordinate()<<") is :"<<p1.distance(p2)<<endl;
cout<<"Distance between P2("<<p2.getXCordinate()<<","<<p2.getYCordinate()<<") and P3("<<p3.getXCordinate()<<","<<p3.getYCordinate()<<") is :"<<p2.distance(p3)<<endl;
cout<<"Distance between P3("<<p3.getXCordinate()<<","<<p3.getYCordinate()<<") and P1("<<p1.getXCordinate()<<","<<p1.getYCordinate()<<") is :"<<p3.distance(p1)<<endl;
return 0;
}
Point.cpp
#include <iostream>
#include <cmath>
using namespace std;
#include "point.h"
#include "main.cpp"
Point::Point()
{
this->cordinateX=0;
this->cordinateY=0;
}
Point::Point(int x,int y)
{
this->cordinateX=x;
this->cordinateY=y;
}
int Point::getXCordinate()
{
return cordinateX;
}
int Point::getYCordinate()
{
return cordinateY;
}
void Point::setYCordinate(int x)
{
this->cordinateY=x;
}
void Point::setXCordinate(int x)
{
this->cordinateX=x;
}
double Point::distance(Point p)
{
int dx = cordinateX - p.cordinateX;
int dy = cordinateY - p.cordinateY;
return sqrt(dx * dx + dy * dy);
}
void Point::translate(int val)
{
this->cordinateX-=val;
this->cordinateY-=val;
}
point.h
#ifndef POINT_H
#define POINT_H
class Point
{
private:
int cordinateX;
int cordinateY;
public:
Point();
Point(int x,int y);
int getXCordinate();
int getYCordinate();
void setXCordinate(int x);
void setYCordinate(int y);
double distance(Point p);
void translate(int val);
};
#endif
Makefile
CXX = g++ # the compiler
CXXFLAGS = -std=c++11 -Wall
# runs for "make all"
all: main
main: main.o point.o
$(CC) $(CFLAGS) -o main main.o point.o
main.o: main.cpp
$(CC) $(CFLAGS) -c main.cpp
point.o: Point.cpp
$(CC) $(CFLAGS) -c Point.cpp
clean:
rm -f main
Error
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
I'm trying to compile with 'make all' command but it keep getting error. every other commands are work now.