Question: Write a c++ program that - extends the Point class from HW #5.1 ( instructions are on the bottom) - data members - x, y,
Write a c++ program that
- extends the Point class from HW #5.1 ( instructions 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
// hw 5.1 here
Write a program that
- defines the class Point which has the following:
- default constructor (has no parameters)
- constructor that has 2 parameters (x coordinate, y coordinate)
- data members
- x coordinate, y coordinate
- member functions
- one to set the value of each of the data members
- one to get the value of each of the data members
- one that returns the distance from the origin (0,0)
(Function definitions outside of the class!!!)
- in main()
- instantiate one Point object and initialize at the time of definition by
providing initial coordinates
- define a pointer that points to the object defined above
- use the pointer
- as an argument passed to a global function that will
- update the coordinates of the point to (7,4)
- back in main, display the distance from the origin
This code includes stuff that should NOT be there, and Missing the global function to update the coordinates to (7,4). fix this please before the complete code
#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
Get step-by-step solutions from verified subject matter experts
