Advertisement
Guest User

Untitled

a guest
Oct 27th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class wektor{
  5. string nazwaWektora;
  6. double x, y, z;
  7. public:
  8. wektor (double xi = 0., double yi = 0., double zi = 0., string naW = ""){
  9. x = xi;
  10. y = yi;
  11. z = zi;
  12. nazwaWektora = naW;
  13. }
  14. wektor operator+(wektor w){
  15. wektor wynik;
  16. wynik.x = x + w.x;
  17. wynik.y = y + w.y;
  18. wynik.z = z + w.z;
  19. return wynik;
  20. }
  21. wektor operator*(wektor w){
  22. wektor wynik;
  23. wynik.x = x * w.x;
  24. wynik.y = y * w.y;
  25. wynik.z = z * w.z;
  26. return wynik;
  27. }
  28. bool operator == (wektor w)
  29. {
  30. if(x == w.x && y == w.y && z == w.z)
  31. {
  32. return true;
  33. }
  34. return false;
  35. }
  36. double getX(){return x;}
  37. double getY(){return y;}
  38. double getZ(){return z;}
  39. string getNazwa(){return nazwaWektora;}
  40. };
  41. ostream& operator<<(ostream& strumien, wektor& w){
  42. strumien << "(" << w.getX() << ", " << w.getY() << ", " << w.getZ() << ")";
  43. return strumien;
  44. }
  45.  
  46.  
  47. wektor w1(-1., -1., -1., "Globalny");
  48.  
  49. int main(){
  50. wektor w1(1., -2., 1., "Lokalny");
  51. cout << w1 << endl;
  52. cout << ::w1 << endl;
  53. cout << "Suma wektorow - " << w1 + ::w1 << endl;
  54. if(w1 * ::w1 == 0) cout << "Wektory są prostopadle";
  55. else cout << "Wektory nie sa prostopadle";
  56.  
  57. return 0;
  58. }
  59.  
  60.  
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement