#include
#include
using namespace std;
class Person{
//数据成员
private:
int num;//编号
string nam;//姓名
string sex;//性别
int year;//年龄
//成员函数
public:
Person (int a,string b,string c,int d);
void show();
};
Person::Person(int a,string b,string c,int d)
{ num=a;
nam=b;
sex=c;
year=d;
}
void Person::show()
{ cout<<"编号: "<<num<<endl;
cout<<"姓名: "<<nam<<endl;
cout<<"性别: "<<sex<<endl;
cout<<"年龄: "<<year<<endl;
}
class Student:public Person//学生数据有编号、姓名、性别、年龄、系别和成绩
{
private: string xi;
int score;public:
Student (int a,string b,string c,int d,string e,int f); void show();
};
Student::Student(int a,string b,string c,int d,string e,int f):Person(a,b,c,d)
{ xi=e; score=f;}
void Student::show()
{ Person:show(); cout<<"系别: "<<xi<<endl; cout<<"成绩: "<<score<<endl;
}
class Teacher:public Person//教师数据有编号、姓名、性别、年龄、职称和部门
{
private:
string zhichen;
string bumen;
public: Teacher(int a,string b,string c,int d,string g,string h); void show();
};
Teacher::Teacher(int a,string b,string c,int d,string g,string h):Person(a,b,c,d)
{ zhichen=g; bumen=h;}
void Teacher::show()
{
Person:show();
cout<<"职称: "<<zhichen<<endl;
cout<<"部门: "<<bumen<<endl;
}
int main()
{
Student s1(19310232,“张三”,“女”,18,“软工”,90); s1.show();
Teacher T1(20190607,“将老师”,“女”,30,“高级”,“化学”);
T1.show();
return 0;
}
可以帮忙看一下为什么运行没错怎么不出结果呢
最新推荐文章于 2022-02-25 12:46:49 发布