Created
August 12, 2017 16:47
-
-
Save jacyzon/149fb3f8ba2cd4a69f84a06bcb426032 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class quadrangle { | |
public: | |
class vertex { | |
friend class quadrangle; | |
friend ostream& operator<<(ostream& os, const quadrangle::vertex& vertex); | |
private: | |
int _x; | |
int _y; | |
public: | |
vertex(); | |
vertex(int x, int y); | |
}; | |
// member | |
static vertex origin; | |
// constructor | |
quadrangle(vertex p1, vertex p3); | |
quadrangle(vertex p1, vertex p2, vertex p3, vertex p4); | |
// function | |
void draw(); | |
void move(vertex vertex); | |
private: | |
// member | |
vertex _p1; // lower-left | |
vertex _p2; | |
vertex _p3; // upper-right | |
vertex _p4; | |
}; | |
quadrangle::vertex quadrangle::origin = quadrangle::vertex(0, 0); | |
ostream& operator<<(ostream& os, const quadrangle::vertex& vertex) { | |
cout << '(' << vertex._x << ',' << vertex._y << ')'; | |
} | |
quadrangle::vertex::vertex() { | |
_x = 0; | |
_y = 0; | |
} | |
quadrangle::vertex::vertex(int x, int y) { | |
_x = x; | |
_y = y; | |
} | |
quadrangle::quadrangle(vertex p1, vertex p3) { | |
_p1 = p1; | |
_p2._x = p3._x; | |
_p2._y = p1._y; | |
_p3 = p3; | |
_p4._x = p1._x; | |
_p4._y = p3._y; | |
} | |
quadrangle::quadrangle(vertex p1, vertex p2, vertex p3, vertex p4) { | |
_p1 = p1; | |
_p2 = p2; | |
_p3 = p3; | |
_p4 = p4; | |
} | |
void quadrangle::draw() { | |
// TODO: area | |
cout << _p1 << '\t' | |
<< _p2 << '\t' | |
<< _p3 << '\t' | |
<< _p4 << "\t" | |
<< "area: TODO"; | |
} | |
void quadrangle::move(vertex vertex) { | |
// TODO | |
cout << "Distance: " << "TODO" << endl; | |
} | |
int main() | |
{ | |
quadrangle q1(quadrangle::vertex(0,0), | |
quadrangle::vertex(3,2), | |
quadrangle::vertex(10,7), | |
quadrangle::vertex(8,10)); | |
quadrangle q2(quadrangle::vertex(3,6), quadrangle::vertex(10,9)); | |
cout << "q1 information" << endl; | |
q1.draw(); | |
cout << endl; | |
cout << "q2 information" << endl; | |
q2.draw(); | |
cout << endl; | |
cout << "q1 move to (5,5) " << endl; | |
q1.move(quadrangle::vertex(5,5)); | |
cout << "q1 information" << endl; | |
q1.draw(); | |
cout << endl; | |
quadrangle::origin = quadrangle::vertex(-5, 3); | |
cout << "q2 move to (-1,2) " << endl; | |
q2.move(quadrangle::vertex(-1,2)); | |
cout << "q2 information" << endl; | |
q2.draw(); | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment