这个类包括:
1.一个名为speed的int型数据域,其取值有1、2或3,默认值为1
2.一个名为color的字符串型数据域,指出风扇的颜色,默认值为blue()
3.一个名为radius的double型数据域,指出风扇的半径,默认值为5
求帮忙写一个类的声明和实现,设计一个名为Fan的类表示一个风扇。用C++并将声明与实现分离
答案:2 悬赏:30 手机版
解决时间 2021-01-30 00:14
- 提问者网友:像風在裏
- 2021-01-29 17:27
最佳答案
- 五星知识达人网友:杯酒困英雄
- 2021-01-29 17:34
可以用enum:
#include <iostream>
#include <iomanip>
using namespace std;
class Fan{
public:
enum Speed{slow=1,intermediate,fast};
Speed sp;
std::string color;
double radius;
Fan(){
sp = slow;
color = "blue";
radius = 5;
}
};
int main(){
return 0;
}
或者:直接int
#include <iostream>
#include <iomanip>
using namespace std;
class Fan{
public:
int speed;
std::string color;
double radius;
Fan(){
speed = 1;
color = "blue";
radius = 5;
}
};
int main(){
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
class Fan{
public:
enum Speed{slow=1,intermediate,fast};
Speed sp;
std::string color;
double radius;
Fan(){
sp = slow;
color = "blue";
radius = 5;
}
};
int main(){
return 0;
}
或者:直接int
#include <iostream>
#include <iomanip>
using namespace std;
class Fan{
public:
int speed;
std::string color;
double radius;
Fan(){
speed = 1;
color = "blue";
radius = 5;
}
};
int main(){
return 0;
}
全部回答
- 1楼网友:洎扰庸人
- 2021-01-29 19:09
你好!
楼上有错误啊enum Speed{slow=1,intermediate,fast};取值要从1开始
我的回答你还满意吗~~
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯