Advertisement
Ivan_Moscow

5.2.14.(2)

May 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. struct vector {
  5.     float x, y, z;
  6. };
  7.  
  8. //Функция для быстрого задания координат вектора
  9. void createVector (vector &target, float x, float y, float z) {
  10.     target.x = x;
  11.     target.y = y;
  12.     target.z = z;
  13. }
  14.  
  15. //Оператор сложения векторов
  16. vector operator+(const vector &v1, const vector &v2) {
  17.     vector result;
  18.     result.x = v1.x+v2.x;
  19.     result.y = v1.y+v2.y;
  20.     result.z = v1.z+v2.z;
  21.     return result;
  22. }
  23.  
  24. //Оператор вычитания векторов
  25. vector operator-(const vector &v1, const vector &v2) {
  26.     vector result;
  27.     result.x = v1.x-v2.x;
  28.     result.y = v1.y-v2.y;
  29.     result.z = v1.z-v2.z;
  30.     return result;
  31. }
  32.  
  33. int _tmain(int argc, _TCHAR* argv[])
  34. {
  35.     //Координаты двух векторов будут задаваться пользователем
  36.     vector a, b, c;
  37.     //Вводим первый вектор
  38.     std::cout<<"Enter coordinates of first vector:\n";
  39.     std::cout<<"X: ";
  40.     std::cin>>a.x;
  41.     std::cout<<"Y: ";
  42.     std::cin>>a.y;
  43.     std::cout<<"Z: ";
  44.     std::cin>>a.z;
  45.     //Вводим второй вектор
  46.     std::cout<<"Enter coordinates of second vector:\n";
  47.     std::cout<<"X: ";
  48.     std::cin>>b.x;
  49.     std::cout<<"Y: ";
  50.     std::cin>>b.y;
  51.     std::cout<<"Z: ";
  52.     std::cin>>b.z;
  53.     //Выводим сумму векторов
  54.     c = a+b;
  55.     std::cout<<"\nResults:\n";
  56.     std::cout<<"\nA+B = ("<<c.x<<"; "<<c.y<<"; "<<c.z<<")\n";
  57.     //Выводим разность векторов
  58.     c = a-b;
  59.     std::cout<<"A-B = ("<<c.x<<"; "<<c.y<<"; "<<c.z<<")\n";
  60.     system("pause");
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement