Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // erer.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct Vector {
- double x, y, z;
- };
- Vector makeNewVector(double x, double y, double z)
- {
- Vector res;
- res.x = x;
- res.y = y;
- res.z = z;
- return res;
- }
- Vector operator+(Vector a, Vector b)
- {
- Vector res;
- res.x = a.x + b.x;
- res.y = a.y + b.y;
- res.z = a.z + b.z;
- return res;
- }
- Vector operator*(double c, Vector b)
- {
- Vector res;
- res.x = c*b.x;
- res.y = c*b.y;
- res.z = c*b.z;
- return res;
- }
- Vector operator-(Vector a, Vector b)
- {
- Vector res;
- res.x = a.x - b.x;
- res.y = a.y - b.y;
- res.z = a.z - b.z;
- return res;
- }
- return 0;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- Vector a = makeNewVector(3, 4, 5),
- b = makeNewVector(1, 2, 4);
- c = 5;
- cout << "a = " << a << endl;
- cout << "b = " << b << endl;
- Vector res = a + b;
- cout << a << " + " << b << " = " << res << endl;
- Vector res = c * b;
- cout << c << " * " << b << " = " << res << endl;
- Vector res = a - b;
- cout << a << " - " << b << " = " << res << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement