jituTechnology

jituTechnology

>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

No comments yet.

Add a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.



Connect with Me

GPO 8973 NPC 541; Kathmandu Nepal
Phone: +977 9851236800

Calendar

October 2019
S M T W T F S
« Jun    
 12345
6789101112
13141516171819
20212223242526
2728293031