题解 | #牛牛学梯形#

牛牛学梯形

https://ac.nowcoder.com/acm/problem/21995

使用面向对象思想来实现

#include <iostream>
#include <iomanip>

using namespace std;

class Trapezia {
    public:
        Trapezia(float up, float down, float height): _up(up), _down(down), _height(height){}
        float area() {
            return (_up + _down) * _height / 2;
        }
        
    private:
        float _up;
        float _down;
        float _height;
};


int main() {
    float up, down, height;
    cin >> up >> down >> height;
    Trapezia trapezia(up, down, height);
    cout << fixed << setprecision(3) << trapezia.area() << endl;
    return 0;
}
全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务