Answer to Question #305347 in C++ for Rajat Vats

Question #305347

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.
1
Expert's answer
2022-03-03T14:33:57-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Rajat Vats
04.03.22, 13:40

it worked!!! Thank you!!!!

Leave a comment

LATEST TUTORIALS
New on Blog