请设计并实现一个学生类,其中学生的信息包括:
姓名(char *name),学号(char id[]),年龄(int age), 住址(string)。
该类对外提供的接口功能包括:
1.构造函数:初始化学生类对象(无参构造,有参构造,拷贝构造,至少3种)
2.普通函数:获取学生信息,修改学生信息,输出学生信息
3.析构函数:释放学生类对象内存空间
要求:
1)在主函数中定义多个学生类的对象,并采用不同形式实现对类对象的初始化。
2)阐述普通构造函数(传值初始化新对象),拷贝构造函数(对象初始化对象)在初始化对象过程中的联系与区别。
## # #include <iostrea
using namespace std;
#include <cstring
class student
{
public:
int id,age;char name[11],adress[21];
student(char *name,char *adress,int age,int id)
{
name="lisi";
adress="龙门";
age=21;
id=001;
}
student()
{
name="zhangshan";
adress="东国";
age=23;
id=123;
}
void Show( )
{
cout << " The student’s name: " << name << endl;
cout << "The student’s id: " << id << endl;
cout << "The student’s age: " << age << endl;
cout << "The student’s adress: " << adress << endl;
}
void modify()
{ cout<<"修改姓名为:" ; cin>>name; cout<<endl;
cout<<"修改学号为:" ; cin>>id; cout<<endl;
cout<<"修改年龄为:" ; cin>>age; cout<<endl;
cout<<"修改学生地址为:" ; cin>>adress; cout<<endl;
}
~student()
{
cout<<"这次可以的"<<endl;
}
};
int main( )
{
cout<<"输出学生基本信息"<<endl;
student.Show( ); //输出学生信息
student.modify();
cout<<"输出学生基本信息"<<endl;
student.Show( );
cout<<"输出学生数据信息"<<endl;
student.Show();
return 0;
}