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 x1)
- {
- x = x1;
- }
- void sety(int y1)
- {
- y= y1;
- }
- void setz(int z1)
- {
- 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;
- resultVector.setx(x + anotherV.getx());
- resultVector.sety(y + anotherV.gety());
- resultVector.setz(z + anotherV.getz());
- 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