编写应用程序,程序定义Fruit、Apple和Exercise三个类。

2025-03-21 07:00:55
推荐回答(1个)
回答1:

#include #include using namespace std;class fruit{public:string color;//颜色float height;//重量};class apple:public fruit{public://不知道你的苹果还有啥属性自己添加吧string shape;//形状apple(float a,string b,string c){height = a;color = b;shape = c;}};int main(){apple a1(0.5,"暗红色","球形");apple a2(0.4,"绿色","椭球形");apple a3(0.65,"艳红色","心形");cout<