Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- struct vector {
- float x, y, z;
- };
- //Функция для быстрого задания координат вектора
- void createVector (vector &target, float x, float y, float z) {
- target.x = x;
- target.y = y;
- target.z = z;
- }
- //Оператор сложения векторов
- vector operator+(const vector &v1, const vector &v2) {
- vector result;
- result.x = v1.x+v2.x;
- result.y = v1.y+v2.y;
- result.z = v1.z+v2.z;
- return result;
- }
- //Оператор вычитания векторов
- vector operator-(const vector &v1, const vector &v2) {
- vector result;
- result.x = v1.x-v2.x;
- result.y = v1.y-v2.y;
- result.z = v1.z-v2.z;
- return result;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- //Координаты двух векторов будут задаваться пользователем
- vector a, b, c;
- //Вводим первый вектор
- std::cout<<"Enter coordinates of first vector:\n";
- std::cout<<"X: ";
- std::cin>>a.x;
- std::cout<<"Y: ";
- std::cin>>a.y;
- std::cout<<"Z: ";
- std::cin>>a.z;
- //Вводим второй вектор
- std::cout<<"Enter coordinates of second vector:\n";
- std::cout<<"X: ";
- std::cin>>b.x;
- std::cout<<"Y: ";
- std::cin>>b.y;
- std::cout<<"Z: ";
- std::cin>>b.z;
- //Выводим сумму векторов
- c = a+b;
- std::cout<<"\nResults:\n";
- std::cout<<"\nA+B = ("<<c.x<<"; "<<c.y<<"; "<<c.z<<")\n";
- //Выводим разность векторов
- c = a-b;
- std::cout<<"A-B = ("<<c.x<<"; "<<c.y<<"; "<<c.z<<")\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement