Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called Point for performing arithmetic with x/y coordinates in a

ID: 3625245 • Letter: C

Question

Create a class called Point for performing arithmetic with x/y coordinates in a system. Test your class with the pa8.cpp program included below.

Points have the form (x, y)

•Use double variables to represent the private data of the class.
•Provide a constructor that enables an object to be initialized when it is declared and has default values of 0.0.
•Provide a public member function "add" to add two points together. Add both of the x values and both of the y values and return a new Point.
•Provide a public member function "subtract" to subtract two points together. Subtract both of the x values and both of the y values and return a new Point.
•Provide a public member function "printPoint" to print the coordinate in the form "(x, y)".
•Provie a public member function "setPoint" to set the values of both x and y values of the Point.
The output should look as follows:
(1,7) + (9,8) = (10,15)
(10,1) - (11,3) = (-1,-2)


Notes
To compile use the command g++ Point.h Point.cpp pa8.cpp -o pa8 to compile and link Point.h, Point.cpp, and pa8.cpp in to the executable pa8.

This is my code:
Point.h
#ifndef POINT_H
#define POINT_H


class Point
{
public:
Point();
Point(double,double);
void setPoint(double newX,double newY);
Point add (Point otherPoint) const;
Point subtract (Point otherPoint) const;
Point printPoint();
private:
double x,y;
};

#endif

Point.cpp

Point::Point()
{
x=0.0;
y=0.0;
}

Point::Point(double newX,double newY)
{
x=newX;
y=newY;
}

void Point::setPoint(double newX,double newY)
{
x=newX;
y=newY;
}

Point Point::add (Point p) const
{
Point z;
z.x=x+p.x;
z.y=y+p.y;

return z;
}

Point Point::subtract (Point p) const
{
Point z;
z.x=x-p.x;
z.y=y-p.y;

return z;
}

Point Point::printPoint()
{
cout<<"("<<x<<","<<y<<")";
}

pa8.cpp

int main()
{
Point a( 1, 7 ), b( 9, 8 ), c;

a.printPoint();
cout << " + ";
b.printPoint();
cout << " = ";
c = a.add( b );
c.printPoint();

cout << ' ';
a.setPoint( 10, 1 );
b.setPoint( 11, 3 );
a.printPoint();
cout << " - ";
b.printPoint();
cout << " = ";
c = a.subtract( b );
c.printPoint();
cout << endl;
}

My Problem is that when I am compiling this I am getting a lot errors.
I have this code in seperate files too.

My errors:
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status

Point.cpp:9: error: ISO C++ forbids declaration of `Point' with no type
Point.cpp: In function `int Point()':
Point.cpp:10: error: `x' was not declared in this scope
Point.cpp:11: error: `y' was not declared in this scope
Point.cpp: At global scope:
Point.cpp:14: error: `Point' is not a class or namespace
Point.cpp:15: error: ISO C++ forbids declaration of `Point' with no type
Point.cpp: In function `int Point(double, double)':
Point.cpp:16: error: `x' was not declared in this scope
Point.cpp:17: error: `y' was not declared in this scope
Point.cpp: At global scope:
Point.cpp:20: error: `Point' is not a class or namespace
Point.cpp: In function `void setPoint(double, double)':
Point.cpp:22: error: `x' was not declared in this scope
Point.cpp:23: error: `y' was not declared in this scope
Point.cpp: At global scope:
Point.cpp:26: error: `Point' does not name a type
Point.cpp:35: error: `Point' does not name a type
Point.cpp:44: error: `Point' does not name a type


Can someone please help as soon as possible.

Thank You Very Much



Explanation / Answer

Alright, why don't you just try to combine your .h and Point.cpp file? Combine into this. #include using namespace std; class Point { public: Point(); Point(double,double); void setPoint(double newX,double newY); Point add (Point otherPoint); Point subtract (Point otherPoint); Point printPoint(); private: double x,y; }; Point::Point() { x=0.0; y=0.0; } Point::Point(double newX,double newY) { x=newX; y=newY; } void Point::setPoint(double newX,double newY) { x=newX; y=newY; } Point Point::add (Point p) { Point z; z.x=x+p.x; z.y=y+p.y; return z; } Point Point::subtract (Point p) { Point z; z.x=x-p.x; z.y=y-p.y; return z; } Point Point::printPoint() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote