Tutorial 12: Problem A: Will you define A class ?, Problem definition
Home |
Web Board |
ProblemSet |
Standing |
Status |
Statistics |
Problem A: Will you define A class? Problem A: Will you define A class? Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 556 Solved: 464
[Submit] [Status] [Web Board] Description
Define a Demo class, including constructor, destructor, and member function show (). show () outputs the specific attribute values according to the format of the sample. This class has only one int type member.
Input
The input must be an integer within the int type.
Output
See the example.
Sample Input-100Sample OutputA data 10 is created! A data 0 is created! A data-100 is created! This is data 10 This is data 0 This is data-100A data-100 is erased! A data 0 is erased! A data 10 is erased! HINT Append Codeappend. cc, [Submit] [Status] [Web Board]
Please refer to the following link for more information:
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin: admin
#include<iostream>using namespace std;class Demo{public: int x; Demo(int a=0):x(a){cout<<"A data "<<x<<" is created!"<<endl;} ~Demo(){cout<<"A data "<<x<<" is erased!"<<endl;} void show(){cout<<"This is data "<<x<<endl;}};int main(){ Demo tmp(10), tmp2; int d; cin>>d; Demo tmp3(d); tmp.show(); tmp2.show(); tmp3.show(); return 0;}