| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1444 人关注过本帖
标题:求不同的图形面积
只看楼主 加入收藏
w4654646
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2016-3-2
结帖率:76.47%
收藏
已结贴  问题点数:20 回复次数:2 
求不同的图形面积
求不同图形的面积
#include
using namespace std;

class Figure {
protected:
    double x,y;

public:
    Figure(double a,double b) { x = a; y = b; }

    virtual void showArea() {
        cout<<"No area computation defined";
        cout<<"For this class. \n";
    }
};

class Triangle:public Figure {
public:
    Triangle(double a,double b):Figure(a,b) {};

    void showArea() {
        cout<<"Triangle with height "<<X;
        cout<<" and base "<<Y;
        cout<<X*Y 2<<endl;
    }
};

class Square:public Figure {
public:
    Square(double a,double b):Figure(a,b) {};

    void showArea() {
        cout<<"Square with dimension "<<X;
        cout<<" * "<<Y<<" HAS AN AREA OF ";
        cout<<X*Y<<ENDL;
    }
};

class Circle:public Figure {
public:
    Circle(double a):Figure(a,a) {};

    void showArea() {
        cout<<"Circle with radius "<<X;
        cout<<" has an area of ";
        cout<<X*X*3.1416<<ENDL;
    }
};

class Trapezoid:public Figure {
protected:
    double z;

public:
    Trapezoid(double a,double b,double c):Figure(a,b) { z = c; };

    void showArea() {
        cout<<"Trapezoid area is: "<<ENDL;
        cout<<(x + y) * z / 2<<ENDL;
    }
};

int main() {
    int m;
    double base,high;
    double length,wide;
    double radius;
    double b1,b2,h1;

    for(int j = 0; j <= 3; j++) {

    cout<<"         _______________________         "<<ENDL;
    cout<<"         |     请选择操作      |         "<<ENDL;
    cout<<"         |    1.求三角形面积   |         "<<ENDL;
    cout<<"         |    2.求矩形面积     |         "<<ENDL;
    cout<<"         |    3.求圆面积       |         "<<ENDL;
    cout<<"         |    4.求梯形面积     |         "<<ENDL;
    cout<<"         |     请输入操作      |         "<<ENDL;
    cout<<"         |_____________________|         "<<ENDL;
    cin>>m;

   
    cout<<"请输入三角形底与高"<<ENDL;
    cin>>base>>high;
    Triangle t(base , high);

    cout<<"请输入矩形长与宽"<<ENDL;
    cin>>length>>wide;
    Square s(length , wide);

    cout<<"请输入圆的半径";
    cin>>radius;
    Circle c(radius);

    cout<<"请输入梯形上下底与高"<<ENDL;
    cin>>b1>>b2>>h1;
    Trapezoid p(b1 , b2 , h1);

    switch(m) {
    case 1:
        t.showArea();
        break;

    case 2:
        s.showArea();
        break;

    case 3:
        c.showArea();
        break;

    case 4:
        p.showArea();
        break;
    }
    }
    return 0;
}
图片附件: 游客没有浏览图片的权限,请 登录注册

  

每次都出现操作界面,无论按什么操作都会出现“输入三角形底与高”等,这怎么改?


[此贴子已经被作者于2016-12-7 11:00编辑过]

2016-12-07 10:57
w4654646
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2016-3-2
收藏
得分:0 
已经3个小时了,没人回答吗
2016-12-07 14:46
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:20 
回复 2楼 w4654646
连编译都通不过,哪来的运行?
2016-12-07 16:07
快速回复:求不同的图形面积
数据加载中...
 
   



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

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