Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- class D3 {
- private:
- int x;
- int y;
- int z;
- public:
- D3()
- {
- x = 0;
- y = 0;
- z = 0;
- }
- D3(int x1,int y1,int z1)
- {
- x = x1;
- y = y1;
- z = z1;
- }
- void setx(int x)
- {
- this->x = x;
- }
- void sety(int y1)
- {
- this->y= y1;
- }
- void setz(int z1)
- {
- this->z = z1;
- }
- int getx()
- {
- return x;
- }
- int gety()
- {
- return y;
- }
- int getz()
- {
- return z;
- }
- void print()
- {
- std::cout << "x = " << x << " , y = " << y << " , z = " << z << std::endl;
- }
- D3 addVect(D3 anotherV)
- {
- D3 resultVector;
- //x,y,z
- int x1 = anotherV.getx();
- int y1 = anotherV.gety();
- int z1 = anotherV.getz();
- int x2 = 0;
- int y2 = 0;
- int z2 = 0;
- x2 = this->x + x1;
- y2 = this->y + y1;
- z2 = this->z + z1;
- resultVector.setx(x2);
- resultVector.sety(y2);
- resultVector.setz(z2);
- return resultVector;
- }
- // resultVector = MainVector + AnotherVector;
- };
- int main()
- {
- D3 first(1, 2, 3);
- D3 second(2, 3, 4);
- D3 result(0, 0, 0);
- result = first.addVect(second);
- result.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement