6-2 学生类的构造与析构

类定义:

定义一个学生类Student,使得main()函数能够得到指定的输出结果 

main()函数如下:

/* 请在这里填写答案 */ int main() {Student stud1(10010,"Wang_li",'f'); stud1.display(); Student stud2(10011,"Zhang_fun",'m'); stud2.display(); return 0; } 

输入样例:

输出样例:

在这里给出相应的输出。例如:

Constructor called.
num:10010
name:Wang_li
sex:f

Constructor called.
num:10011
name:Zhang_fun
sex:m

Destructor called.
Destructor called.

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

答案:

class Student{
    public:
    Student(int a,string b,char c){
        num=a;
        name=b;
        sex=c;
    }
    ~Student(){
        cout<<"Destructor called."<

你可能感兴趣的:(中国地质大学,c++,算法,开发语言)