
사각형의 3가지 점을 받으면
3가지 X값과 Y값중 한개만 있는 값을 가지고 있는 좌표가 4번째 점의 좌표이다.
(5, 5) (5,7) (7 5) : (7, 7)
이전까진 C언어만 하다가
최근들어 C++를 한거라 연습좀 할 겸 객체지향적으로 작성하였는데
쓸데없이 길게 쓴 느낌이 없지 않아 있다.
#include <iostream>
using namespace std;
class Point{
public:
int x;
int y;
Point();
void set(int a, int b);
};
Point :: Point(){
x = 0;
y = 0;
}
void Point::set(int a, int b){
x = a;
y = b;
}
class Rectangle{
public:
Point *p;
Rectangle();
~Rectangle();
void setPoint(int index, int x, int y);
void procPoint();
void printPoint(int index);
};
Rectangle::Rectangle(){
p = new Point[4];
}
Rectangle::~Rectangle(){
delete [] p;
}
void Rectangle::setPoint(int index, int x, int y){
p[index].set(x, y);
}
void Rectangle::procPoint(){
int x, y;
int i, j, k;
for(i=0;i<3;i++){
j = (i==2) ? 0 : i+1;
k = (j==2) ? 0 : j+1;
if((p[i].x!=p[j].x) && (p[i].x!=p[k].x)){
x = p[i].x;
}
if((p[i].y!=p[j].y) && (p[i].y!=p[k].y)){
y = p[i].y;
}
}
setPoint(3, x, y);
printPoint(3);
}
void Rectangle::printPoint(int index){
cout << p[index].x << " " << p[index].y << endl;
}
int main(){
Rectangle *r;
int t;
cin >> t;
r = new Rectangle[t];
for(int i=0; i<t; i++){
for(int j=0; j<3; j++){
int x, y;
cin >> x >> y;
r[i].setPoint(j, x, y);
}
}
for(int i=0; i<t; i++){
r[i].procPoint();
}
delete [] r;
}