1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
using namespace std;
class Pointer{
//Data members
private:
int x,y,z;
public:
//Costructors
Pointer(){set(0,0,0);}
Pointer(int new_x, int new_y, int new_z){set(new_x, new_y, new_z);}
//Operations
Pointer operator*(const Pointer &pt){return mul(pt);}
Pointer operator+(const Pointer &pt){return add(pt);}
Pointer operator/(const Pointer &pt){return div(pt);}
Pointer operator-(const Pointer &pt){return sub(pt);}
Pointer add(const Pointer &pt);
Pointer mul(const Pointer &pt);
Pointer div(const Pointer &pt);
Pointer sub(const Pointer &pt);
//Member Functions
void set(int new_x, int new_y, int new_z);
int get_x() const {return x;}
int get_y() const {return y;}
int get_z() const {return z;}
};
int main(){
Pointer PoOb, PoOb2;
int a=0,b=0,c=0;
int a1=0,b1=0,c1=0;
cout << "Enter first point: ";
cin >> a;
cout << ",";
cin >> b;
cout << ",";
cin >> c;
cout << endl;
PoOb.set(a,b,c);
cout << "Enter your second Point: ";
cin >> a1;
cout << ",";
cin >> b1;
cout << ",";
cin >> c1;
PoOb2.set(a1,b1,c1);
PoOb = PoOb * PoOb2;
cout << "The new point is: " << PoOb.get_x() << "," << PoOb.get_y() << "," << PoOb.get_z();
system("pause");
return 0;
}
void Pointer::set(int new_x, int new_y, int new_z){
if(new_x<0)
new_x *= -1;
if(new_y<0)
new_y *= -1;
if(new_z<0)
new_z *= -1;
x = new_x;
y = new_y;
z = new_z;
}
Pointer Pointer::add(const Pointer &pt){
Pointer new_pointer;
new_pointer.x = x + pt.x;
new_pointer.y = y + pt.y;
new_pointer.z = z + pt.z;
return new_pointer;
}
Pointer Pointer::mul(const Pointer &pt){
Pointer new_pointer;
new_pointer.x = x * pt.x;
new_pointer.y = y * pt.y;
new_pointer.z = z * pt.z;
return new_pointer;
}
Pointer Pointer::div(const Pointer &pt){
Pointer new_pointer;
new_pointer.x = x / pt.x;
new_pointer.y = y / pt.y;
new_pointer.z = z / pt.z;
return new_pointer;
}
Pointer Pointer::sub(const Pointer &pt){
Pointer new_pointer;
new_pointer.x = x - pt.x;
new_pointer.y = y - pt.y;
new_pointer.z = z - pt.z;
return new_pointer;
}
|