使用面向对象思想来实现

#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;
}