| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 443 人关注过本帖
标题:出错啦,题不会了
取消只看楼主 加入收藏
金虎儿168
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-8
结帖率:0
收藏
 问题点数:0 回复次数:0 
出错啦,题不会了
#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;
}
搜索更多相关主题的帖子: include choice 长方形 用户 
2010-03-20 22:10
快速回复:出错啦,题不会了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021615 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved