第四次课——7.4
作者:互联网
作业15
//poe
#include <iostream>
#include <string>
using namespace std;
class People
{
public:
string number;
string name;
string id_number;
public:
People(){};
People(string number1,string name1,string id_number1)
{
number=number1;
name=name1;
id_number=id_number1;
}
void input();//输入函数
void output();//输出函数
};
void People::input()
{
cin>>number;
cin>>name;
cin>>id_number;
}
void People::output()
{
cout<<"number:"<<number<<"name:"<<name
<<"id_number:"<<id_number;
}
//子类
class Student:public People
{
public:
string Class;//班级
string Major;//专业
public:
Student(){};
Student(string number1,string name1,string id_number1,
string class1,string major1):People(number1,name1,id_number1)
{
Class=class1;
Major=major1;
}
void input();
void output();
bool operator==(const Student &);
};
//子类成员函数定义
void Student::input()
{
People::input();//调用基类input()
cin>>Class>>Major;
}
void Student::output()
{
People::output();
cout<<"Class:"<<Class<<"Major:"<<Major<<endl;
}
//调用运算符重载函数
bool Student::operator==(const Student &s)
{
if (number==s.number)
{
cout<<"两个学生的学号相同,不合法!";
exit(1);
}
else return 1;
}
//子类graduate,研究生
class Graduate:public Student
{
public:
string teacher;//导师
public:
Graduate(){};
Graduate(string number1,string name1,string id_number1,
string class1,string major1,string teacher1):Student(number1,name,id_number1,
class1,major1)
{
teacher=teacher1;
}
void input();
void output();
};
void Graduate::input()
{
Student::input();
cin>>teacher;
}
void Graduate::output()
{
Student::output();
cout<<"teacher:"<<teacher<<endl;
}
//主函数
int main()
{
Student s1,s2;
Graduate g;
cout<<"请输入第一个本科生的信息:"<<endl;
s1.input();
cout<<"请输入另一个本科生的信息:"<<endl;
s2.input();
s1==s2;//调用==重载函数,用来判断两个学生的学号是否相同
cout<<"请输入研究生的信息"<<endl;
g.input();
cout<<endl;
cout<<"显示两个本科生信息:"<<endl;
s1.output();s2.output();
cout<<"显示研究生信息:"<<endl;
g.output();
return 1;
}
标签:string,output,void,Student,number1,input,7.4,第四次 来源: https://www.cnblogs.com/cnxm/p/14968930.html