定义一个日期类Date,该类对象存放一个日期数据(年,月,日),创建一个带参数的构造函数,
用来对成员进行初始化,定义一个输出函数输出相关日期,定义一个student类,包含数据成员学号Num(int),成绩Score(double),考试日期SD(Date类对...
用来对成员进行初始化,定义一个输出函数输出相关日期,定义一个student类,包含数据成员学号Num(int),成绩Score(double),考试日期SD(Date类对象),定义一个输出函数show()用来输出学生学号、成绩、考试日期,主函数中定义3个学生,分别输出其相关内容。(其它内容根据需要自己设定)
展开
1个回答
展开全部
#include<iostream.h>
class Date
{
private:int y,m,d;
public:
Date(int year=2013,int month=4,int day=25)
{
y=year;m=month;d=day;
}
void setY(int year){y=year;}
void setM(int month){m=month;}
void setD(int day){d=day;}
int getY(){return y;}
int getM(){return m;}
int getD(){return d;}
void showdate()
{cout<<y<<"."<<m<<"."<<d<<endl;}
};
class Student
{
private:int Num;double Score;Date SD;
public:
Student::Student(int n,double s,int y,int m,int d)
{Num=n;Score=s;SD.setY(y);SD.setM(m);SD.setD(d);}
void show()
{
cout<<"学号:"<<Num<<" 成绩:"<<Score<<" 考试时间:"<<SD.getY()<<"."<<SD.getM()<<"."<<SD.getD()<<endl;
}
};
void main()
{
Student st1(001,65.0,2013,4,26);
Student st2(002,85.0,2013,4,27);
Student st3(003,98.0,2013,4,28);
st1.show();
st2.show();
st3.show();
class Date
{
private:int y,m,d;
public:
Date(int year=2013,int month=4,int day=25)
{
y=year;m=month;d=day;
}
void setY(int year){y=year;}
void setM(int month){m=month;}
void setD(int day){d=day;}
int getY(){return y;}
int getM(){return m;}
int getD(){return d;}
void showdate()
{cout<<y<<"."<<m<<"."<<d<<endl;}
};
class Student
{
private:int Num;double Score;Date SD;
public:
Student::Student(int n,double s,int y,int m,int d)
{Num=n;Score=s;SD.setY(y);SD.setM(m);SD.setD(d);}
void show()
{
cout<<"学号:"<<Num<<" 成绩:"<<Score<<" 考试时间:"<<SD.getY()<<"."<<SD.getM()<<"."<<SD.getD()<<endl;
}
};
void main()
{
Student st1(001,65.0,2013,4,26);
Student st2(002,85.0,2013,4,27);
Student st3(003,98.0,2013,4,28);
st1.show();
st2.show();
st3.show();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询