早教吧作业答案频道 -->其他-->
以下是一个学生类(Student)的类定义部分,请完成相应的类的实现部分,并编写相应的main函数测试相应的功#includeclassStudent{private:intnumber;//学号charname[20];//姓名Datebirth;//出生日期,为日期类
题目详情
以下是一个学生类(Student)的类定义部分,请完成相应的类的实现部分,并编写相应的main函数测试相应的功
#include
class Student{
private:
int number;//学号
char name[20];//姓名
Date birth;//出生日期,为日期类的对象
public:
Student();
Student(int n,char *m,Date d);
Student(const Student &s);
Student();
void setnumber(int *n);//设置学号
void setname(char *s);//设置姓名
void setbirth(Date d);//设置出生日期
void printstudent();//输出各成员的值
};
#include
class Student{
private:
int number;//学号
char name[20];//姓名
Date birth;//出生日期,为日期类的对象
public:
Student();
Student(int n,char *m,Date d);
Student(const Student &s);
Student();
void setnumber(int *n);//设置学号
void setname(char *s);//设置姓名
void setbirth(Date d);//设置出生日期
void printstudent();//输出各成员的值
};
▼优质解答
答案和解析
1.我建议楼主用string类型.我写的代码就是用string类型的,个人觉得比较方便使用,如果你想减少内存开销的话可以用你用的那几种数据类型,因为有些学号里面有字母,而名字长度也是不确定的,char name[20]只能接纳9个汉字,当然这已经足够用了,我懂得,有了string这种类型就不必再为生日定义另外一种数据类型的.
2.以下是我写的一些代码和测试用例,希望对你有些帮助和启发:
#include
#include
using namespace std;
class Student
{
private:
string NO;//学号
string Name;//姓名
string Birthday;//出生日期,为日期类的对象
public:
Student(){};//string 型变量默认值为空所以不需要构造函数对其进行初始化了,如果有其他类型变量请自行添加
Student(const string& NO,const string& Name,const string& Birthday);
Student(const Student& Obj);
~Student();
string& SetNO(const string& NO) ;//设置学号
string& SetName(const string& Name);//设置姓名
string& SetBirthday(const string& Birthday);//设置出生日期
void DisplayStu();//输出各成员的值
};
Student::Student(const string& NO,const string& Name,const string& Birthday)
{
this->NO=NO;
this->Name=Name;
this->Birthday=Birthday;
}
Student::Student(const Student& Obj)
{
this->NO=Obj.NO;
this->Name=Obj.Name;
this->Birthday=Obj.Birthday;
}
Student::~Student()
{ NO=Name=Birthday=""; }
string& Student::SetNO(const string& NO) //设置学号
{ return this->NO=NO;}
string& Student::SetName(const string& Name)//设置姓名
{ return this->Name=Name;}
string& Student::SetBirthday(const string& Birthday) //设置出生日期
{ return this->Birthday=Birthday;}
void Student::DisplayStu() //输出各成员的值
{
cout
2.以下是我写的一些代码和测试用例,希望对你有些帮助和启发:
#include
#include
using namespace std;
class Student
{
private:
string NO;//学号
string Name;//姓名
string Birthday;//出生日期,为日期类的对象
public:
Student(){};//string 型变量默认值为空所以不需要构造函数对其进行初始化了,如果有其他类型变量请自行添加
Student(const string& NO,const string& Name,const string& Birthday);
Student(const Student& Obj);
~Student();
string& SetNO(const string& NO) ;//设置学号
string& SetName(const string& Name);//设置姓名
string& SetBirthday(const string& Birthday);//设置出生日期
void DisplayStu();//输出各成员的值
};
Student::Student(const string& NO,const string& Name,const string& Birthday)
{
this->NO=NO;
this->Name=Name;
this->Birthday=Birthday;
}
Student::Student(const Student& Obj)
{
this->NO=Obj.NO;
this->Name=Obj.Name;
this->Birthday=Obj.Birthday;
}
Student::~Student()
{ NO=Name=Birthday=""; }
string& Student::SetNO(const string& NO) //设置学号
{ return this->NO=NO;}
string& Student::SetName(const string& Name)//设置姓名
{ return this->Name=Name;}
string& Student::SetBirthday(const string& Birthday) //设置出生日期
{ return this->Birthday=Birthday;}
void Student::DisplayStu() //输出各成员的值
{
cout
看了 以下是一个学生类(Stude...的网友还看了以下:
可以参考的公式是:s[1]=a[1];s[n]=s[n-1]>=0?s[n-1]+a[n]:a[n 2020-05-14 …
这首歌的中文翻译? 歌名叫:here i amHere I am - this is meTher 2020-05-16 …
这题哪里出错了?本题:输出11-999之间的数m,要求m,m*m,m*m*m都为回文数.如11,1 2020-05-17 …
译歌 《girl in my mirror 》 有意者请进!there's a girl in m 2020-05-17 …
Dima(3,3)AsIntegerFori=1To3Forj=1To3a(i,j)=i*j+iN 2020-06-12 …
英语单词填空1.时间状语:d-r-n-2.场所:b-s-s-o-f-r--e-a-t-e-t3.教 2020-07-14 …
i是虚数单位,若集合S={-1,0,1},则()A.i属于SB.i的二次方属于SC.i的i是虚数单 2020-07-30 …
下面是求1~1000内所有偶数的和的程序,把程序框图补充完整,则()A.①处为S=S+i,②处为i= 2020-11-01 …
下证明过程中蕴涵的数学思想是什么s=a+a(1+i)+a(1+i)(1+i)+...+a(1+i)的 2020-11-01 …
已知,给出的是计算1/2+1/4+1/6+1/8+...+1/100的一个程序S=0,n=2,i=1 2020-11-01 …