Advertisement
andruhovski

prog-0301

Feb 18th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include "stdafx.h"
  2. using namespace std;
  3. struct point { double x, y; };
  4.  
  5. int     average(int a, int b);
  6. double  average(double a, double b);
  7. point   average(point a, point b);
  8.  
  9. class Vector {
  10.     double xStart, xEnd, yStart, yEnd;
  11. public:
  12.     Vector();
  13.     Vector(double xs, double ys, double xe, double ye);
  14.     ~Vector();
  15.     Vector operator+(Vector& rOperand);
  16. };
  17.  
  18. Vector::Vector()
  19.     : xStart(0)
  20.     , xEnd(0)
  21.     , yStart(0)
  22.     , yEnd(0)
  23. {
  24. }
  25.  
  26. Vector::Vector(double xs, double ys, double xe, double ye)
  27.     : xStart(xs)
  28.     , xEnd(ys)
  29.     , yStart(xe)
  30.     , yEnd(ye)
  31. {
  32.  
  33. }
  34.  
  35. Vector::~Vector()
  36. {
  37. }
  38.  
  39. Vector Vector::operator+(Vector& rOperand)
  40. {
  41.     return Vector(xStart,xEnd + (rOperand.xEnd - rOperand.xStart),yStart, yEnd + (rOperand.yEnd - rOperand.yStart));
  42. }
  43.  
  44.  
  45. int _tmain(void)
  46. {
  47.     point p1 = { 1, 1 }, p2 = { 2, 2 }, p3;
  48.     cout << average(2, 3) << endl;
  49.     cout << average(2.0, 3.0) << endl;
  50.     p3 = average(p1, p2);
  51.     cout << p3.x << " " <<p3.y << endl;
  52.     return 0;
  53. }
  54.  
  55. int average(int a, int b)
  56. {
  57.     return (a + b) / 2;
  58. }
  59.  
  60. double  average(double a, double b)
  61. {
  62.     return (a + b) / 2.0;
  63. }
  64. point average(point a, point b)
  65. {
  66.     point c;
  67.     c.x = (a.x + b.x) / 2.0;
  68.     c.y = (a.y + b.y) / 2.0;
  69.     return c;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement