早教吧作业答案频道 -->其他-->
以下是一个学生类(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...的网友还看了以下:
等比数列{an}的前n项和为Sn,已知对任意的n∈N*,点(n,Sn)均在函数y=bx+r(b>0 2020-05-13 …
设有关系模式R(A,B,C,D,E,F) ,其函数依赖集为F={E→D,C→B,CE→F,B→A}。 2020-05-23 …
设关系模式R(A,B,C)有函数依赖集F={A→B,B→C),则关系R的规范化程度至多达到()。A. 2020-05-23 …
设有关系模式R(A,B,C,D,E,F),其函数依赖集为F={E→D,C→B,CE→F,B→A}。则 2020-05-24 …
设有关系模式r(a,b,c),f是r上成立的fd集,f={a→b,b→c},那么f在模式r上的投影π 2020-05-26 …
数据库中σ这个符号是什么意思啊设有关系R(A,B,C)和关系S(B,C,D),那么与R⋈S等价的关 2020-07-10 …
设集合A={x||x-a|<1,x∈R},B={x||x-b|>2,x∈R}.若A⊆B,则实数a, 2020-08-01 …
(2011•枣庄二模)设集合A={x|x-a<1,x∈R},B={x|x-b>1,x∈R},若A⊆B 2020-11-13 …
Foreachofthefollowing,giveabijectionffromAtoB.Yous 2020-11-26 …
A和B都是n阶实对称矩阵,则A与B合同的充分必要条件是()A.R(A)=R(B)B.A与B相似C.A 2021-02-17 …