>2.3 Create a class point that represents a three dimensional co-ordinates system
>
/* create a class point that represents a three dimensional co-ordinates system. Each object of Point have coordinates, (x,y,z) and methods to assign coordinates to the point objects. Add a method to calculate the distance from origin and to print the point in the form of (x,y,z)
Programmed by: Jitendra Kr Yadav
Roll: 10116(NCIT-ELX)
Date: 20 July 2011*/
#include <iostream.h>
#include <conio.h>
#include <math.h>
class Distance //You can replace Distance with Point
{
private:
int x;
int y;
int z;
public:
void assign(int a, int b, int c);
void show();
};
void Distance:: assign(int a, int b, int c)
{
x=a;
y=b;
z=c;
}
void Distance::show()
{
cout<<sqrt(pow(x,2)+pow(y,2)+pow(z,2));
}
int main()
{
int x,y,z;
Distance d1;
cout<<“Enter the cordinates of x, y and z\n”;
cin>>x>>y>>z;
d1.assign(x,y,z);
cout<<“The distance from the origin is: “;
d1.show();
getch();
return(0);
}
Output Sample:
Enter the coordinates of x, y and z
8
9
10
The distance from the origin is: 15.6525