Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class Wektory{
  5. public:
  6. Wektory(int x=0,int x1=0 ):wektor_x(x),wektor_x1(x1){};
  7. Wektory operator +(Wektory &wektor1){
  8. Wektory wektors;
  9. wektors.wektor_x = wektor_x + wektor1.wektor_x;
  10. wektors.wektor_x1 = wektor_x1 + wektor1.wektor_x1;
  11. return wektors;
  12. }
  13. Wektory operator -(Wektory wektor_x2){
  14. Wektory wektors1;
  15. wektors1.wektor_x = wektor_x - wektor_x2.wektor_x;
  16. wektors1.wektor_x1 = wektor_x1 - wektor_x2.wektor_x1;
  17. return wektors1;
  18. }
  19. friend istream & operator >>(istream &wejscie ,Wektory &p){
  20. wejscie >> p.wektor_x >> p.wektor_x1;
  21. return wejscie;
  22. }
  23. friend ostream & operator << (ostream &wyjscie ,Wektory &p){
  24. wyjscie << p.wektor_x << ' '<< p.wektor_x1;
  25. return wyjscie;
  26. }
  27. private:
  28. int wektor_x;
  29. int wektor_x1;
  30.  
  31. };
  32. int main(void){
  33. Wektory p1,p2,p3,p4;
  34.  
  35. cout << "Podaj wartosc x i y wektora"<<endl;
  36. cin >> p1;
  37. cout << "Podaj wartosc x i y wektora 2"<<endl;
  38. cin >>p2;
  39.  
  40. p3 = p1 + p2;
  41. cout << "Wartosc po dodania wartosc wektorow : ";
  42. cout << p3<<endl;
  43.  
  44. p4 = p1 - p2;
  45. cout << "Wartosc po odjeciu wartosc wektorow : ";
  46. cout << p4 <<endl;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement