注册 登录
编程论坛 C++教室

新手求教 设计一个空调类

有一个人 发布于 2018-03-28 21:04, 1846 次点击
·················································
只有本站会员才能查看附件,请 登录

我上课的时候没跟上,所以想在这里请教一下在座的各位前辈,
希望前辈能把完整的代码写一下,
谢谢了!!!
1 回复
#2
爱之梦魇2018-05-21 17:28
只有本站会员才能查看附件,请 登录

#include<iostream>
#include<cstring>
using namespace std;
class airCondition{
    public:
        airCondition(string,string,string,string,int);
        void switch_state(string);
        void heat_up();
        void heat_down();
        void print();
    private:
        string brand;
        string color;
        string power;
        string switc;
        int heat;
};
airCondition::airCondition(string b,string c,string p,string s,int h)
{
    brand=b;
    color=c;
    power=p;
    switc=s;
    heat=h;
}
void airCondition::switch_state(string s)
{
    if(s=="关")
       switc="开";
    if(s=="开")
       switc="关";
}
void airCondition::heat_up()
{
    int h;
    cout<<"How few degrees do you want to increase the air conditioning temperature?";
    cin>>h;
    heat+=h;
}
void airCondition::heat_down()
{
    int h;
    cout<<"How few degrees do you want to turn the air conditioning temperature down?";
    cin>>h;
    heat-=h;
}
void airCondition::print()
{
    cout<<"The air conditioning's brand is "<<brand<<endl;
    cout<<"The air conditioning's color is "<<color<<endl;
    cout<<"The air conditioning's power is "<<power<<endl;
    cout<<"The air conditioning's switch state is "<<switc<<endl;
    cout<<"The air conditioning's temperature is "<<heat<<"°C"<<endl;
}
int main()
{
    string b,c,p,s;
    int h;
    cout<<"Please input the air conditioning's information:"<<endl;
    cout<<"The brand is :";
    cin>>b;
    cout<<"The color is :";
    cin>>c;
    cout<<"The power is :";
    cin>>p;
    cout<<"The switch state is :";
    cin>>s;
    cout<<"The temperature is :";
    cin>>h;
    airCondition a(b,c,p,s,h);
    cout<<"The air conditioning original information:"<<endl;
    a.print();
    a.switch_state(s);
    a.heat_down();
    cout<<"The air conditioning new information:"<<endl;
    a.print();
}


程序比较简单粗糙,希望楼主够用
1