| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1724 人关注过本帖
标题:新手求教 设计一个空调类
只看楼主 加入收藏
有一个人
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-3-28
收藏
 问题点数:0 回复次数:1 
新手求教 设计一个空调类
·················································
图片附件: 游客没有浏览图片的权限,请 登录注册

我上课的时候没跟上,所以想在这里请教一下在座的各位前辈,
希望前辈能把完整的代码写一下,
谢谢了!!!
搜索更多相关主题的帖子: 设计 代码 
2018-03-28 21:04
爱之梦魇
Rank: 2
等 级:论坛游民
帖 子:21
专家分: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.027737 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved