c++求梯形面积
#include<iostream>
using namespace std;
class TX
{
private:
double s1,s2,s3,area;
public:
TX(double a,double b,double h){
s1=a;
s2=b;
s3=h;
}
void getarea()
{
area=(s1+s2)*s3 /2;
}
void outarea()
{
cout<<"梯形面积为"<< area << endl;
}
};
int main(){
double a,b,h;
cout << "请输入梯形的上底:";
cin >> a;
cout << "请输入梯形的下底:";
cin >> b;
cout << "请输入梯形的高:";
cin >> h;
TX t1(a,b,h);
t1.getarea();
t1.outarea();
return 0;
}