Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Vector {
- public:
- double x;
- double y;
- double z;
- void input() {
- double a, b, c;
- cin >> a >> b >> c;
- this->x = a;
- this->y = b;
- this->z = c;
- }
- Vector operator+(Vector tmp) {
- Vector a;
- a.x = this->x + tmp.x;
- a.y = this->y + tmp.y;
- a.z = this->z + tmp.z;
- return a;
- }
- Vector operator-(Vector tmp) {
- Vector a;
- a.x = this->x - tmp.x;
- a.y = this->y - tmp.y;
- a.z = this->z - tmp.z;
- return a;
- }
- double operator*(Vector tmp) {
- return this->x*tmp.x + this->y*tmp.y + this->z*tmp.z;
- }
- void output() {
- cout << "(" << x << ", " << y << ", " << z << ")" << endl;
- }
- };
- int main()
- {
- int n = 3;
- Vector mass1[n];
- Vector mass2[n];
- for (int i = 0; i<n; i++)
- {
- cout << "Please, enter 3 coords from " << i << " element from 1 mass: ";
- mass1[i].input();
- }
- for (int i = 0; i<n; i++)
- {
- cout << "Please, enter 3 coords from " << i << " element from 2 mass: ";
- mass2[i].input();
- }
- Vector tmp;
- for (int i = 0; i<n; i++)
- {
- cout << "mass1["<<i<<"] + mass2[" << i << "] = ";
- tmp = mass1[i]+mass2[i];
- tmp.output();
- }
- for (int i = 0; i<n; i++)
- {
- cout << "mass1["<<i<<"] - mass2[" << i << "] = ";
- tmp = mass1[i]-mass2[i];
- tmp.output();
- }
- double tmp2;
- for (int i = 0; i<n; i++)
- cout << "mass1["<<i<<"] * mass2[" << i << "] = " << mass1[i]*mass2[i] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement