出错啦,题不会了
#include<iostream>#include<cmath>
using namespace std;
struct point
{
int x; //横坐标
int y; //纵坐标
};
void displaymenu(); //显示主菜单
void gettwopoints(struct point *,struct point *); //得到用户输入的两个点
void printpoint(struct point *); //以(X,Y)的形式打印点
void drawcircle(struct point *,struct point *); //画圆的函数
void drawrectangle(struct point *,struct point *); //画长方形的函数
int main()
{
int choice = 5; //用户选择
struct point startp,endp; //起点和终点
while (choice)
{
displaymenu(); //显示主菜单
cin >> choice; //接受用户输入
switch ( choice )
{
case 1: //圆
gettwopoints(&startp,&endp,&choice); //得到两个点
drawcircle(&startp,&endp); //画圆
break;
case 2: //长方形
gettwopoints(&startp,&endp,&choice);
drawcircle(&startp,&endp);
break;
case 0:
cout << "Good Bye!" << endl;
break;
default:
cout << "Not supported! Please select again!" << endl;
break;
}
}
}
void displaymenu() //显示主菜单
{
cout << "1. Circle(圆)" << endl <<"2. Rectangle (长方形)" << endl<< "0. Exit (退出)" << endl;
cout << "Please select the shape:";
}
void gettwopoints(struct point *startp,struct point *endp) //得到用户输入的两个点
{
cout <<"Please input the coordinate(x,y) of the start point:";
cin >>startp->x >> startp->y;
//printpoint( startp );
cout <<"Please input the coordinate(x,y) of the end point:";
cin >>endp->x>> endp->x;
//printpoint( endp );
if (choice == 1)
{
if( abs(endp->x -startp->x) != abs(endp->y - startp->y))
cout << "Not a circle,Select again.\n";
else
drawcircle(startp->x,startp->y);
}
if(choice == 2)
{
if((endp->x != startp->x) ||( endp->y != startp->y ))
cout << "Not a Rectangle,Select again.\n ";
else
drawrectangle(startp-> x,startp-> y);
}
}
void printpoint(struct point *p) //以(X,Y)的形式打印点
{
cout << p->x,p->y \n;
}
void drawcircle(struct point *,struct point *) //画圆的函数
{
int i,j;
i=endp->x + startp->x;
j=endp->y + startp->y;
k=abs(endp->y - startp->y) / 2;
cout << "Draw a circle at center ("<< i / 2 <<","<< j / 2 << ") with radius "<< k \n;
}
void drawrectangle(struct point *,struct point *) //画长方形的函数
{
int i,j;
i =abs(point.endp.x - point.startp.x);
j = abs( point.endp.y - point.startp.y);
cout <<"Draw a rectangle at topleft ("<< point.startp.x << point.startp.y << ") ,whose width is "<< i << "and height is "<< j \n;
}