#include <bits/stdc++.h>
using namespace std;
struct Point
{
int x;
int y;
};
void displayMenu() {
for (int i = 0; i < 32; ++i)
cout << "*";
cout << endl;
cout << " 1.Circle(圆)" << endl;
cout << " 2.Rectangle(长方形)" << endl;
cout << " 0.Exit(退出)" << endl;
for (int i = 0; i < 32; ++i)
cout << "*";
cout << endl;
cout << "Please select the shape:";
}
// void getTwoPoints(struct Point * P1, struct Point * P2) {
// }
// void printPoint(struct Point *) {
// }
void drawCircle(struct Point * P1, struct Point * P2) {
if (P2 -> x - P1 -> x == P2 -> y - P1 -> y) {
cout << "Draw a circle at center (" << (P1 -> x + P2 -> x) / 2 << "," << (P2 -> y + P1 -> y) / 2 << ")" << "with radius " << (P2 -> x - P1 -> x) / 2 << endl;
}
else {
cout << "Not a circle, select again" << endl;
}
}
void drawRectangle(struct Point * P1, struct Point * P2) {
cout << "Draw a rectangle at toleft(" << P1 -> x << "," << P1 -> y << "), whose width is " << P2 -> x - P1 -> x << " and height is " << P2 -> y - P1 -> y << endl;
}
int main () {
int choice;
struct Point startP, endP;
while (choice) {
displayMenu();
cin >> choice;
switch (choice) {
case 1:
cout << "Please input the coordinate(x,y)of the start point:";
cin >> startP.x >> startP.y;
cout << "Please input the coordinate(x,y)of the end point:";
cin >> endP.x >> endP.y;
if (endP.x <= startP.x || endP.y <= startP.y){
cout << "输入点的坐标存在问题,请重新输入!" << endl;
break;
}
//getTwoPoints(&startP, &endP);
drawCircle(&startP, &endP);
break;
case 2:
cout << "Please input the coordinate(x,y)of the start point:";
cin >> startP.x >> startP.y;
cout << "Please input the coordinate(x,y)of the end point:";
cin >> endP.x >> endP.y;
if (endP.x <= startP.x || endP.y <= startP.y){
cout << "输入点的坐标存在问题,请重新输入!" << endl;
break;
}
//getTwoPoints(&startP, &endP);
drawRectangle(&startP, &endP);
break;
case 0:
cout << "Good Bye!
";
break;
default:
cout << "Not supported! Please select again!
";
break;
}
}
return 0;
}
// //测试样例
// 1
// 5 20
// 15 30
// 1
// 5 20
// 15 25
// 2
// 3 10
// 20 30
// 3
// 0