Write a class definition for Point, which represents a point in the Cartesian coordinate system (i.e., x and y). Your Point class should include a default constructor and the following member function:
// set the point to values x, y
void set ( double x, double y );
Overload the << operator to display the point's coordinates.
Then write a small main function that uses a variable of type Point, sets it to the coordinates ( 2.5, 4 ) , and displays its coordinates on cout.
#include
using namespace std;
class Point {
public:
Point() {}
void set( double, double );
private:
double x, y;
friend ostream& operator<< ( ostream&, const Point& );
};
//
// Set x, y coordinates of a point
//
void Point::set( double xVal, double yVal )
{
x = xVal;
y = yVal;
}
//
// Display a Point object
//
ostream& operator<< ( ostream& out, const Point& pt )
{
out << "(x, y) = (" << pt.x << ", " << pt.y << ")";
return out;
}
int main()
{
Point onePt;
onePt.set( 2.5, 4 );
cout << onePt << endl;
return 0;
}
Computer Science & Information Technology
You might also like to view...
A large organization is more likely to use which type of network?
A) client/peer network B) peer-to-peer network C) client-to-client network D) client/server network
Computer Science & Information Technology
Travel cost may be even more of a consideration than the ________ of the contracted recovery site
Fill in the blank(s) with correct word
Computer Science & Information Technology
Cortana can provide instant answers.?
Answer the following statement true (T) or false (F)
Computer Science & Information Technology
What is the most important component in the computer case?
A. Complementary metal-oxide semiconductor? B. Motherboard C. Central processing unit (CPU) D. Monitor
Computer Science & Information Technology