Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. // erer.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. struct Vector {
  12.     double x, y, z;
  13. };
  14.  
  15. Vector makeNewVector(double x, double y, double z)
  16. {
  17.     Vector res;
  18.     res.x = x;
  19.     res.y = y;
  20.     res.z = z;
  21.     return res;
  22. }
  23.  
  24. Vector operator+(Vector a, Vector b)
  25. {
  26.     Vector res;
  27.     res.x = a.x + b.x;
  28.     res.y = a.y + b.y;
  29.     res.z = a.z + b.z;
  30.     return res;
  31. }
  32.  
  33. Vector operator*(double c, Vector b)
  34. {
  35.     Vector res;
  36.     res.x = c*b.x;
  37.     res.y = c*b.y;
  38.     res.z = c*b.z;
  39.     return res;
  40. }
  41.  
  42. Vector operator-(Vector a, Vector b)
  43. {
  44.     Vector res;
  45.     res.x = a.x - b.x;
  46.     res.y = a.y - b.y;
  47.     res.z = a.z - b.z;
  48.     return res;
  49. }
  50.  
  51. return 0;
  52. }
  53.  
  54. int _tmain(int argc, _TCHAR* argv[])
  55. {
  56.  
  57.     Vector a = makeNewVector(3, 4, 5),
  58.        b = makeNewVector(1, 2, 4);
  59.        c = 5;
  60.  
  61. cout << "a = " << a << endl;
  62. cout << "b = " << b << endl;
  63.  
  64. Vector res = a + b;
  65. cout << a << " + " << b << " = " << res << endl;
  66.  
  67. Vector res = c * b;
  68. cout << c << " * " << b << " = " << res << endl;
  69.  
  70. Vector res = a - b;
  71. cout << a << " - " << b << " = " << res << endl;
  72.  
  73. }
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement