source code:
base class:
class persion
{
protected:
string _name,_sex,_birthday,_number;
int _age;
public:
persion(string st_name,string st_sex,string st_birthday,int st_age,string st_number);
persion(){}
virtual bool SearchData(string studentnumber,string name)=0;
void DisplayData(); };
derived class:
class Student:virtual public persion
{
private:
string _major;
string _electiveslesson;
int _electivessore;
public:
int basesore[3];
Student(){}
Student(string st_name,string st_sex,string st_birthday,int st_age,string st_number);//report student information
Student(string st_major,int st_chinese,int st_math,int st_english,string st_electiveslesson,int st_electivessore);
bool SearchData(string studentnumber,string name);
void DisplayStudentData(); };
Student::Student(string st_name,string st_sex,string st_birthday,int st_age,string st_number)
:persion(st_name,st_sex,st_birthday,st_age,st_number)
{
}
Student::Student(string st_major,int st_chinese,int st_math,int st_english,string st_electiveslesson,int st_electivessore)
{
_major= st_major;
basesore[0]=st_chinese;
basesore[1]=st_math;
basesore[2]=st_english;
_electiveslesson=st_electiveslesson;
_electivessore=st_electivessore;
}
bool Student::SearchData(string studentnumber,string name)
{
if(string(name)==string(_name)||string(studentnumber)==string(_number))
{
cout<<"search success!"<<endl;
return true;
}
else
return false;
}
void Student::DisplayStudentData()
{
cout<<"major\t"<<"Chinese\t"<<"math\t"<<"English\t"<<"elective\t"<<"elective score"<<endl;
cout<<_major<<"\t";
for(int i=0;i<3;i++)
cout<<basesore[i]<<"\t ";
cout<<_electiveslesson<<"\t\t"<<_electivessore<<endl;
}
case 1:
{
cout<<"Please input number,name: ";
cin>>number>>name;
for(x=0;x<st_num;x++)
{
if (st_infor[x].SearchData(number,name)==true)
{
st_infor[x].DisplayData();
score_infor[x].DisplayStudentData();
break;
}
}
if(x==st_num)
cout<<"search no report!"<<endl;
break;
}