Advertisement
ilyakanyshev

task3

Jan 23rd, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Vector {
  6.     public:
  7.         double x;
  8.         double y;
  9.         double z;
  10.         void input() {
  11.             double a, b, c;
  12.             cin >> a >> b >> c;
  13.             this->x = a;
  14.             this->y = b;
  15.             this->z = c;
  16.         }
  17.         Vector operator+(Vector tmp) {
  18.             Vector a;
  19.             a.x = this->x + tmp.x;
  20.             a.y = this->y + tmp.y;
  21.             a.z = this->z + tmp.z;
  22.             return a;
  23.         }
  24.         Vector operator-(Vector tmp) {
  25.             Vector a;
  26.             a.x = this->x - tmp.x;
  27.             a.y = this->y - tmp.y;
  28.             a.z = this->z - tmp.z;
  29.             return a;
  30.         }
  31.         double operator*(Vector tmp) {
  32.             return this->x*tmp.x + this->y*tmp.y + this->z*tmp.z;
  33.         }
  34.         void output() {
  35.             cout << "(" << x << ", " << y << ", " << z << ")" << endl;
  36.         }
  37. };
  38.  
  39. int main()
  40. {
  41.     int n = 3;
  42.     Vector mass1[n];
  43.     Vector mass2[n];
  44.     for (int i = 0; i<n; i++)
  45.     {
  46.         cout << "Please, enter 3 coords from " << i << " element from 1 mass: ";
  47.         mass1[i].input();
  48.     }
  49.     for (int i = 0; i<n; i++)
  50.     {
  51.         cout << "Please, enter 3 coords from " << i << " element from 2 mass: ";
  52.         mass2[i].input();
  53.     }
  54.     Vector tmp;
  55.     for (int i = 0; i<n; i++)
  56.     {
  57.         cout << "mass1["<<i<<"] + mass2[" << i << "] = ";
  58.         tmp = mass1[i]+mass2[i];
  59.         tmp.output();
  60.     }
  61.     for (int i = 0; i<n; i++)
  62.     {
  63.         cout << "mass1["<<i<<"] - mass2[" << i << "] = ";
  64.         tmp = mass1[i]-mass2[i];
  65.         tmp.output();
  66.     }
  67.     double tmp2;
  68.     for (int i = 0; i<n; i++)
  69.         cout << "mass1["<<i<<"] * mass2[" << i << "] = " << mass1[i]*mass2[i] << endl;
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement