//C++构造函数 请大佬们帮我看看哪里错了
题目是:定义日期类和学生类,日期类的数据成员为年、月、日。从键盘输入学生的学号、姓名、性别、出生日期以及3门课程的成绩,保存到学生类数组中,计算总分、均分,将成绩按总分由高到低排序,输出学生成绩情况。
#include <iostream>
using namespace std;
class date
{
private:
int year;
int month;
int day;
public:
date();//默认值:1900/01/01
date(int yy,int mm,int dd);//有参构造,定义对象的同时实现对象的初始化
date(date &d);
void input();
void print();
};
date::date()
{
year=1900;
month=01;
day=01;
}
date::date(int yy,int mm,int dd)
{
year=yy;
month=mm;
day=dd;
}
date::date(date &d)
{
year=d.year;
month=d.month;
day=d.day;
}
void date::input()
{
cout<<"出生日期"<<endl;
cout<<"年:";cin>>this->year;
cout<<"月:";cin>>this->month;
cout<<"日;";cin>>this->day;
}
void date::print()
{
cout<<year<<"-"<<month<<"-"<<day<<" ";
}
class student
{
private:
char m_num[4];
char m_name[9];
date m_birthday;//出生日期 含有对象成员
float kc[5];
public:
student();
student(char num[],char name[],int kc[3],int yy,int mm,int dd);//有参构造函数
student(const student &s);
void input();
void print();
};
student::student():m_birthday()
{
strcpy(m_num,"000");
strcpy(m_name,"noname");
kc[0]=90;
kc[1]=90;
kc[2]=90;
}
student::student(char num[],char name[],int kc[3],int yy,int mm,int dd):m_birthday(yy,mm,dd)
{
int a,b,c;
strcpy(m_num,num);
strcpy(m_name,name);
kc[0]=a;
kc[1]=b;
kc[2]=c;
}
student::student(const student &s)
{
strcpy(m_num,s.m_num);
strcpy(m_name,s.m_name);
m_birthday=s.m_birthday;
kc[0]=s.kc[0];
kc[1]=s.kc[1];
kc[2]=s.kc[2];
}
void student::input()
{
cout<<"学号:";
cin>>this->m_num;
cout<<"姓名:";
cin>>this->m_name;
cout<<"语文:";
cin>>kc[0];
cout<<"数学:";
cin>>kc[1];
cout<<"英语:";
cin>>kc[2];
m_birthday.input();
}
void student::print()
{
cout<<"学号:"<<this->m_num<<" "<<"姓名:"<<this->m_name<<" "<<endl;
cout<<"语文:"<<kc[0]<<" "<<"数学:"<<kc[1]<<" "<<"英语:"<<kc[2]<<endl;
m_birthday.print();
}
void main()
{
student s;//定义一个学生对象,取默认值
student s2;//定义学生对象s2,取默认值
student s3("003","Tom",90,90,88,2000,11,14);
student s4(s3);
s2.input();//输入信息
s.print();//输出学生信息
s2.print();//输出信息
s3.print();
s4.print();
}