#include using namespace std; #include class Person{ public: Person(charn,int a) { pname=new char[10]; strcpy(pname,n); page=a; } void disp() { cout<'name:'<<pname<<' '<'age:'<<page<<endl; } protected: char pname; int page; };
class Date{ public: Date(int q,int w,int e) { year=q; month=w; day=e; } void disp() { cout<'birthday:'<<year<<'/'<<month<<'/'<<day<<endl; } protected: int year,month,day; }; class Student:public Person{ public: friend class Teacher; Student(char
q,int w,int e,int r,int t,int a):Person(q,w),d(r,t,e) { grade=a; } Student(const Student&s1):Person(s1.pname, s1.page),d(s1.d) { grade=s1.grade; } void disp() { Person::disp(); d.disp(); cout<'score:'<<grade<<endl; } protected: int grade; Date d; }; class Teacher:public Person{ public: Teacher(char
z,int x,charm):Person(z,x) { zc=new char[10]; strcpy(zc,m); } void getgrade(int g) { student->grade=g; } void setStudent(Student& s) { student=&s; } void disp() { Person::disp(); cout<'title:'<<zc<<endl; } protected: char zc; int grade; Student* student; }; int main() { char q[10],w[10],e[10]; int a,b,v,f,g,h,i; cin>>q>>a>>b>>v>>f>>g; Student s(q,a,b,v,f,g); cin>>w>>h>>e; Teacher t(w,h,e); cin>>i; t.setStudent(s); s.disp(); t.disp(); t.getgrade(i); s.disp(); }


原文地址: https://www.cveoy.top/t/topic/nBH6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录