Design a class which models the behavior of a point in the cartesian plane Code:
ID: 3773227 • Letter: D
Question
Design a class which models the behavior of a point in the cartesian plane Code: Construct a client called point_client.cpp which demonstrates that all the member functions work. * Use point.h and point.cpp * Add code for the implementations in point.cpp * Add code for a copy constructor, destructor, assignment operator ( = ) (demonstrate that they work ) * Overload << and , >> (demonstrate that they work ) Please check email attachment for files point.h and point.cpp . point.h /////////////////////////////////////////////////////////////////////////////////////////////// // // File name : point.h // // This file is the include file(ie prototypes) for the class Point // // Programmer : // // Date created : // // Date last revised : // //////////////////////////////////////////////////////////////////////////////////////////////// #ifndef point_h #define point_h class Point //class point defined { private: double xVal; //x value or x coordinate of point double yVal; //y value or y coordinate of point public: Point(); //default constructor Point( double x, double y ); //constructor initializer void setX( double x ); //mutator change x value of point void setY( double y ); //mutator change y value of point void setPoint( double x, double y ); //change point value double getX(); //accessor xVal double getY(); //accessors yVal //overloaded << //prints the point in the form ( x coord, y coord ) }; #endif point.cpp /////////////////////////////////////////////////////////////////////////////////////////////// // // File name : point.cpp // // This is the implementation file for the class Point and auxiliary functions // // Programmer : // Date created : // // // //////////////////////////////////////////////////////////////////////////////////////////////// #include #include using namespace std; #include "point.h" //obtain prototype definitions ///////////////////////////////////////////////////////////////////////////////////////// // // function name : setX // // purpose : set/change the x coordinate of the point // // input parameters : double x - the x value of the point // // output parameters : none // // return value : void // ///////////////////////////////////////////////////////////////////////////////////////// void Point::setX( double x ) { } ///////////////////////////////////////////////////////////////////////////////////////// // // function name : setY // // purpose : set/change the y coordinate of the point // // input parameters : double y - the x value of the point // // output parameters : none // // return value : void // ///////////////////////////////////////////////////////////////////////////////////////// void Point::setY( double y ) { } ///////////////////////////////////////////////////////////////////////////////////////// // // function name : Point() - default constructor // // purpose : creates a default point ( 0, 0 ) // // input parameters : none // // output parameters : none // // return value : none // ///////////////////////////////////////////////////////////////////////////////////////// Point::Point() { } ///////////////////////////////////////////////////////////////////////////////////////// // // function name : Point // // purpose : creates a point based on the argument list // // input parameters : double x - for the x coord; double y - for the y coor // // output parameters : none // // return value : none // ///////////////////////////////////////////////////////////////////////////////////////// Point::Point( double x, double y ) { } /////////////////////////////////////////////////////////////////////////////////////////// // // function name : setPoint // // purpose : sets the individual the x and y coords of a point to the // double values in the // values in the argument list // // input parameters : double x - for the x coord; double y - for the y coor // // output parameters : none // // return value : none // ///////////////////////////////////////////////////////////////////////////////////////// void Point::setPoint( double x, double y ) { } ////////////////////////////////////////////////////////////////////////////////////////// // // function name : getX // // purpose : get the x coord of a point // // input parameters : none // // output parameters : none // // return value : double xVal- the x coord // ///////////////////////////////////////////////////////////////////////////////////////// double Point::getX() { } ///////////////////////////////////////////////////////////////////////////////////////// // // function name : getY // // purpose : get the y coord of a point // // input parameters : none // // output parameters : none // // return value : double yVal-the y coord of point // ///////////////////////////////////////////////////////////////////////////////////////// double Point::getY() { } ///////////////////////////////////////////////////////////////////////////////////////// // // function name : << // // purpose : overloaded << to print a point in the form ( num1, num2 ) // // input parameters : none // // output parameters : none // // return value : none // ///////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// c++
Explanation / Answer
/*Design a class which models the behavior of a point in the cartesian plane Code:
Construct a client called point_client.cpp which demonstrates that all the member functions work.
* Use point.h and point.cpp
* Add code for the implementations in point.cpp
* Add code for a copy constructor, destructor, assignment operator ( = ) (demonstrate that they work )
* Overload << and , >> (demonstrate that they work )
Please check email attachment for files point.h and point.cpp . */
//point.cpp
///////////////////////////////////////////////////////////////////////////////////////////////
// // File name : point.cpp // // This is the implementation file for the class Point and auxiliary functions
// // Programmer :
// Date created :
// // // ////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
//#include <>
using namespace std;
#include "point.h"
//obtain prototype definitions
/////////////////////////////////////////////////////////////////////////////////////////
//
// function name : setX //
// purpose : set/change the x coordinate of the point //
// input parameters : double x - the x value of the point //
// output parameters : none //
// return value : void
// /////////////////////////////////////////////////////////////////////////////////////////
void Point::setX( double x ) {
xVal=x;
}
///////////////////////////////////////////////////////////////////////////////////////// //
// function name : setY // // purpose : set/change the y coordinate of the point //
// input parameters : double y - the x value of the point //
// output parameters : none //
// return value : void
// /////////////////////////////////////////////////////////////////////////////////////////
void Point::setY( double y ) {
yVal=y;
}
///////////////////////////////////////////////////////////////////////////////////////// //
// function name : Point() - default constructor //
// purpose : creates a default point ( 0, 0 ) //
// input parameters : none //
// output parameters : none //
// return value : none // /////////////////////////////////////////////////////////////////////////////////////////
Point::Point() {
xVal=0;
yVal=0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// // function name : Point //
// purpose : creates a point based on the argument list //
// input parameters :
//double x - for the x coord;
//double y - for the y coor //
// output parameters : none //
// return value : none
// /////////////////////////////////////////////////////////////////////////////////////////
Point::Point( double x, double y ) {
xVal=x;
yVal=y;
}
///////////////////////////////////////////////////////////////////////////////////////////
// // function name : setPoint //
// purpose : sets the individual the x and y coords of a point to the
// double values in the // values in the argument list //
// input parameters : double x - for the x coord;
//double y - for the y coor //
// output parameters : none //
// return value : none //
/////////////////////////////////////////////////////////////////////////////////////////
void Point::setPoint( double x, double y ) {
xVal=x;
yVal=y;
}
//////////////////////////////////////////////////////////////////////////////////////////
// // function name : getX // // purpose : get the x coord of a point //
// input parameters : none // // output parameters : none //
// return value : double xVal- the x coord
// /////////////////////////////////////////////////////////////////////////////////////////
double Point::getX() {
return xVal;
}
///////////////////////////////////////////////////////////////////////////////////////// //
// function name : getY // // purpose : get the y coord of a point //
// input parameters : none // // output parameters : none //
// return value : double yVal-the y coord of point //
/////////////////////////////////////////////////////////////////////////////////////////
double Point::getY() {
return yVal;
} ///////////////////////////////////////////////////////////////////////////////////////// //
// function name : << //
// purpose : overloaded << to print a point in the form ( num1, num2 ) //
// input parameters : none //
// output parameters : none //
// return value : none //
ostream & operator << (ostream &out, const Point &p)
{
out <<"point ";
out << p.getX()<<endl;
out << p.getY()<< endl;
return out;
}
istream & operator >> (istream &in, Point &p)
{
cout << "Enter x-value";
in >> p.xVal;
cout << "Enter y-value";
in >> p.yVal;
return in;
}
Point& operator=(const Point& p) // copy assignment
{
Point p;
xVal=p.getX();
yVal=p.getY();
return p;
}
// Copy constructor
Point(const Point &p2)
{xVal = p2.getX(); yVal = p2.getY(); }
Point::~Point(void)
{
cout << "Freeing memory!" << endl;
delete ptr;
}
// ////////////////////////////////////////////////////////////////////////////////////////////////
// File name : point.h
// // This file is the include file(ie prototypes) for the class Point
// // Programmer : //
// Date created : //
// Date last revised :
// ////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef point_h
#define point_h
class Point
//class point defined
{
private:
double xVal;
//x value or x coordinate of point
double yVal;
//y value or y coordinate of point
public:
Point();
//default constructor
Point( double x, double y );
//constructor initializer
void setX( double x );
//mutator change x value of point
void setY( double y );
//mutator change y value of point
void setPoint( double x, double y );
//change point value
double getX();
//accessor xVal
double getY();
friend ostream & operator << (ostream &out, const Point &p);
friend istream & operator >> (istream &in, Point &p);
//accessors yVal
//overloaded << //prints the point in the form ( x coord, y coord ) };
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.