初学者请教一个问题
试定义类student ,它包括
(1)私有数据为name ,sid birthday 分别表示姓名和学号和出生日期
(2)公有函数为一个带缺省参数的构造函数,一个无返回值print()函数打印学生的姓名,学号和出生日期:一个无返回值的函数modify用以修改学生的姓名和学号.
(3)定义一个主函数,且创建两个对象s1和s2分别调用缺省和非缺省构造函数,并分别调用打印函数,
(4)写出主函数的打印结果
#include <iostream.h>
class student
{
private:
char* name;
char* sid;
char* birthday;
public:
student ();
student ( char* name_in, char* sid_in, char* birthday_in );
void print ();
void modify ( char* name_in, char* sid_in );
};
student::student ()
{
name = "张三";
sid = "01";
birthday= "1980-01-01";
}
student::student ( char* name_in, char* sid_in, char* birthday_in )
{
name = name_in;
sid = sid_in;
birthday= birthday_in;
}
void student::modify ( char* name_in, char* sid_in )
{
name = name_in;
sid = sid_in;
}
void student::print ()
{
cout << name << "," << sid << "," << birthday << endl;
}
int main ()
{
student s1;
student s2 ( "李四", "02", "1978-03-11" );
s1.print ();
s2.print ();
return 0;
}