WAP in C++ : Defines a structure called ThreeDPoint that represents a point in a 3D space. The point has an x , a y , and a z coordinate. Defines a function getPointData() to accept values of x, y and z coordinates of a point from the user. Defines another function for operator overloading of less than (<) operator. The function compares x coordinates of two structure variables and returns true if that of first one is less than that of second. If both are equal, it compares y coordinates of two structure variables and returns true if that of first one is less than that of second. If they are also equal, it compares z coordinates of two structure variables and returns true if that of first one is less than that of second. For example if input values for two points, say p1 and p2 are (1, 1, 2) and (1, 1, 0) then p1 < p2 returns false and p2 < p1 returns true. Define two variables of the structure ThreeDPoint, namely- p1 and p2 in the main() function and print the smaller of the two points.
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
#include <iostream>
using namespace std;
struct point
{
intx;
inty;
};
int main( )
{
point A,B,C;
cout<<"Enter coordinates for p1:";
cin>>A.x>>A.y;
cout<<"Enter coordinates for p2:";
cin>>B.x>>B.y;
C.x=A.x+B.x;
C.y=A.y+B.y;
cout<<"Coordinates of p1+p2 are:"<<C.x<<", "<<C.y;
return 0;
}