# Answer to Question #16435 in C++ for arif hussain

Question #16435

Q#3 Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point

Expert's answer

C++

Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point

#include<iostream>

using namespace std;

struct p{

float x, y, z;

} p1, p2, p3;

void main(){

cout<<"enter x, y, z coords for the 1st point: ";

cin>>p1.x>>p1.y>>p1.z;

cout<<"enter x, y, z coords for the 2nd point: ";

cin>>p2.x>>p2.y>>p2.z;

p3.x = p1.x + p2.x;

p3.y = p1.y + p2.y;

p3.z = p1.z + p2.z;

cout<<"sum of the given points is: p3("<<p3.x<<", "<<p3.y<<", "<<p3.z<<").\n";

system("pause");

}

Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point

#include<iostream>

using namespace std;

struct p{

float x, y, z;

} p1, p2, p3;

void main(){

cout<<"enter x, y, z coords for the 1st point: ";

cin>>p1.x>>p1.y>>p1.z;

cout<<"enter x, y, z coords for the 2nd point: ";

cin>>p2.x>>p2.y>>p2.z;

p3.x = p1.x + p2.x;

p3.y = p1.y + p2.y;

p3.z = p1.z + p2.z;

cout<<"sum of the given points is: p3("<<p3.x<<", "<<p3.y<<", "<<p3.z<<").\n";

system("pause");

}

## Comments

## Leave a comment