实验四
1.
#include <iostream>
using namespace std;
#include <string.h>
class Student
{
private:
char *name;
int age;
int ID;
public:
Student()
{
name=new char[strlen(name)+1];
cout<<"构造函数中"<<endl;
}
~Student()
{
delete [] name;
}
void setInfo(char *n,int a,int id)
{
strcpy(name,n);
age=a;
ID=id;
}
void show()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"学号:"<<ID<<endl;
}
};
int main()
{
Student st1;
st1.setInfo("张三",18,12345);
st1.show();
return 0;
}
-----------------------------------------------------------
2、
Student.h
#ifndef STUDENT_H
#define STUDENT_H
class Student
{
private:
char *name;
int age;
int ID;
public:
Student()
{
name=new char[strlen(name)+1];
cout<<"构造函数中"<<endl;
}
~Student()
{