Problem B: 建造一间教室

HomeWeb BoardProblemSetStandingStatusStatistics

Problem B: 建造一间教室

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 1060   Solved: 655
[ Submit][ Status][ Web Board]

Description

一间教室包括很多物品。这里只考虑灯(Light)和椅子(Chair)。定义Light类,只有一个int类型的参数,表示灯的瓦数;定义Chair类,只有一个字符串类型的参数,表示椅子的颜色。定义ClassRoom类,包括四个属性:两个int类型的属性,分别为灯的个数和椅子的个数。一个Light类的对象和一个Chair类的对象,分别为教室中灯的种类和椅子的种类。

Input

输入有6行,第1行是一个正整数,表示灯的瓦数。第2行是一个不含空白符的字符串,表示椅子的颜色。第3、4行表示教室中灯的个数和椅子的数量。第5行是一个正整数,表示教室中灯的瓦数,第6行是一个不含空白符的字符串,表示教室中椅子的颜色。

Output

见样例。

Sample Input

20blue1610025red

Sample Output

A 20w light is created.A blue chair is created.A 25w light is created.A red chair is created.A classroom having 16 lights and 100 chairs is created.A classroom having 16 lights and 100 chairs is erased.A red chair is created.A 25w light is erased.A blue chair is created.A 20w light is erased.

HINT

Append Code

[ Submit][ Status][ Web Board]
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
class Light
{
private:
    int w;
public:
    Light(){ }
    Light(int ww):w(ww){ cout << "A " << w << "w light is created." << endl; }
    ~Light(){ cout << "A " << w << "w light is erased." << endl;}
    int getw() const { return w; }
};
class Chair
{
private:
    string cl;
public:
    Chair(){ }
    Chair(string c):cl(c){ cout << "A " << cl << " chair is created." << endl; }
    ~Chair(){ cout << "A " << cl << " chair is created." << endl;}
    string getcl() const { return cl; }
};
 
class ClassRoom
{
private:
    int lnum, cnum;
     Light lig;
    Chair cha;
public:
    ClassRoom(){ }
    ClassRoom(int ln,int cn,int w,string c ): lig(w), cha(c),lnum(ln), cnum(cn)
    {
        cout << "A classroom having " << lnum << " lights and " << cnum << " chairs is created." << endl;
    }
    ~ClassRoom(){ cout << "A classroom having " << lnum << " lights and " << cnum << " chairs is erased." << endl;}
};
 
int main()
{
    int nl, nc;
    int w;
    string color;
    cin>>w>>color;
    Light light(w);
    Chair chair(color);
    cin>>nl>>nc;
    cin>>w>>color;
    ClassRoom room(nl, nc, w, color);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值