How to write a program that will declare a class point. The class point has two private data members x and y of type float. The class point has a parameterized constructor to initialize both the data members i.e. x and y. The class point has a member function display() that display the value of x and y. Create two objects p1 and p2 with your desired data and display the values of x and y of p1 and p2. Now create a third object p3 by using the expression p3=p1+p2 and display the values of x and y of p3.
Sample Output
Point 1 is
x=2.5
y=3.8
Point 2 is
x=5.9
y=6.8
Point 3 is
x=8.4
y=10.6



LinkBack URL
About LinkBacks




to initialize both the variables. The class has a function that displays the value of x and of y to the screen.
CornedBee
Only joking. I like his approach though.