Question
Write a c++ program that - extends the Point class from HW #5.1(codes are on the bottom) - data members - x, y, and z
Write a c++ program that
- extends the Point class from HW #5.1(codes are on the bottom)
- data members
- x, y, and z coordinates
- member functions
- setter and getter for each data member
- overload the + operator to add two points (adds each coordinate)
- overload the ! operator to return true if point is NOT the origin (0,0,0)
- in main()
- instantiate three Point objects (default constructor)
- initialize data members for 2 objects using setter member functions
- no prompting, just hard code these values
- add these 2 Point objects and assign the result into the third object
- display coordinates for the resulting object
- instantiate another Point object (default constructor)
- use the ! operator on the object and inform the user if that Point was the origin or not
#include
#include
using namespace std;
class Point
{
private:
int xcoordinate;
int ycoordinate;
public:
//funtion prototypes
int getXcoord(void);
int getYcoord(void);
void setXcoord(int xcoord);
void setYcoord(int ycoord);
double distance(void);
Point(int xcoord, int ycoord);
//default constructor
Point()
{
xcoordinate = 0;
ycoordinate = 0;
}
};
// constructor that has two parameter
Point::Point(int xcoord, int ycoord)
{
xcoordinate = xcoord;
ycoordinate = ycoord;
}
// getter setter methods
void Point::setXcoord(int xcoord)
{
xcoordinate = xcoord;
}
int Point::getXcoord( void )
{
return xcoordinate;
}
void Point::setYcoord(int ycoord)
{
ycoordinate = ycoord;
}
int Point::getYcoord( void )
{
return ycoordinate;
}
double Point::distance( void )
{
return sqrt((xcoordinate*xcoordinate) + (ycoordinate*ycoordinate));
}
// Main function for the program
int main( )
{
Point obj;
obj.setXcoord(7);
obj.setYcoord(4);
cout<<"Distance from orgin: "< return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started