Home | Web Board | ProblemSet | Standing | Status | Statistics |
Problem A: 第一个类
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 730 Solved: 669
[ Submit][ Status][ Web Board]
Description
定义一个Thing类,只有1个字符串属性name,定义其构造函数和析构函数,分别输出样例所示的内容。
Input
一个不包含空白符的字符串。
Output
见样例。
Sample Input
Truck
Sample Output
Construct a thing CarConstruct a thing TruckDestroy a thing TruckDestroy a thing Car
HINT
Append Code
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cmath>
using namespace std;
class Thing
{
private:
string name;
public:
Thing(){ }
Thing(string n):name(n) {cout << "Construct a thing " << name << endl; }
~Thing(){ cout << "Destroy a thing " << name << endl;}
};
int main()
{
Thing A("Car");
string str;
cin>>str;
Thing B(str);
return 0;
}