| 网站首页 | 业界新闻 | 群组 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
雷速体育发帖软件开发QQ118000023C语言培训|一对一辅导|零基础学编程LightningChart 快速先进的.Net图表控件
共有 203 人关注过本帖
标题:新手求教 设计一个空调类
只看楼主 收藏
有一个人
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-3-28
  问题点数:0  回复次数:1   
新手求教 设计一个空调类
·················································
我上课的时候没跟上,所以想在这里请教一下在座的各位前辈,
希望前辈能把完整的代码写一下,
谢谢了!!!
附件: 您没有浏览附件的权限,请 登录注册
2018-03-28 21:04
爱之梦魇
Rank: 2
等 级:论坛游民
帖 子:17
专家分:30
注 册:2018-2-2
  得分:0 

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


程序比较简单粗糙,希望楼主够用
附件: 您没有浏览附件的权限,请 登录注册
2018-05-21 17:28







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053777 second(s), 9 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved