Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- using namespace std;
- struct point { double x, y; };
- int average(int a, int b);
- double average(double a, double b);
- point average(point a, point b);
- class Vector {
- double xStart, xEnd, yStart, yEnd;
- public:
- Vector();
- Vector(double xs, double ys, double xe, double ye);
- ~Vector();
- Vector operator+(Vector& rOperand);
- };
- Vector::Vector()
- : xStart(0)
- , xEnd(0)
- , yStart(0)
- , yEnd(0)
- {
- }
- Vector::Vector(double xs, double ys, double xe, double ye)
- : xStart(xs)
- , xEnd(ys)
- , yStart(xe)
- , yEnd(ye)
- {
- }
- Vector::~Vector()
- {
- }
- Vector Vector::operator+(Vector& rOperand)
- {
- return Vector(xStart,xEnd + (rOperand.xEnd - rOperand.xStart),yStart, yEnd + (rOperand.yEnd - rOperand.yStart));
- }
- int _tmain(void)
- {
- point p1 = { 1, 1 }, p2 = { 2, 2 }, p3;
- cout << average(2, 3) << endl;
- cout << average(2.0, 3.0) << endl;
- p3 = average(p1, p2);
- cout << p3.x << " " <<p3.y << endl;
- return 0;
- }
- int average(int a, int b)
- {
- return (a + b) / 2;
- }
- double average(double a, double b)
- {
- return (a + b) / 2.0;
- }
- point average(point a, point b)
- {
- point c;
- c.x = (a.x + b.x) / 2.0;
- c.y = (a.y + b.y) / 2.0;
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement