9_79.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:2k
- #include<iostream.h>
- #include<string.h>
- class Person
- {
- public:
- Person(const char*n,const char*t,const char*a)
- {
- name=new char[strlen(n)+1];
- strcpy(name,n);
- tel=new char[strlen(t)+1];
- strcpy(tel,t);
- add=new char[strlen(a)+1];
- strcpy(add,a);
- }
- void Print() const
- {
- cout<<name<<endl;
- cout<<" TEL:"<<tel;
- cout<<" Address:"<<add;
- }
- ~Person()
- {
- delete[] name;
- delete[] tel;
- delete[] add;
- // cout<<"Destructed class Person!"<<endl;
- }
- protected:
- char*name;
- char*tel;
- char*add;
- };
- class Student:virtual public Person
- {
- public:
- Student(const char*n,const char*t,const char*a,const char*m):Person(n,t,a)
- {
- major=new char[strlen(m)+1];
- strcpy(major,m);
- }
- void Print() const
- {
- Person::Print();
- cout<<" Major:"<<major<<endl;
- }
- protected:
- char*major;
- };
- class Staff:virtual public Person
- {
- public:
- Staff(const char*n,const char*t,const char*a,const char*d,int sal):Person(n,t,a)
- {
- dept=new char[strlen(d)+1];
- strcpy(dept,d);
- salary=sal;
- }
- void Print() const
- {
- Person::Print();
- cout<<" Department:"<<dept;
- cout<<" Salary:"<<salary<<endl;
- }
- protected:
- char*dept;
- int salary;
- };
- class Teacher: public Staff
- {
- public:
- Teacher(const char*n,const char*d,const char*t,const char*a,const char*l,int sal)
- :Person(n,t,a),Staff(n,t,a,d,sal)
- {
- lesson=new char[strlen(l)+1];
- strcpy(lesson,l);
- }
- void Print() const
- {
- Staff::Print();
- cout<<" Lesson: "<<lesson<<endl;
- }
- protected:
- char*lesson;
- };
- class StudentTeacher:public Student,public Teacher
- {
- public:
- StudentTeacher(const char*n,const char *m,const char*d,const char*t,
- const char*a,const char*l,int sal)
- :Person(n,t,a),Student(n,t,a,m),Teacher(n,d,t,a,l,sal){}
- void Print() const
- {
- Student::Print();
- cout<<" Department: "<<dept;
- cout<<" Lesson: "<<lesson;
- cout<<" Salary: "<<salary;
- }
- };
- void main()
- {
- Student stu("Richard","01012345678","EAST_16_1","Software Engineering");
- Staff sta("Volatire","01012345679","WEST_16_2","Management",2000);
- Teacher te("Churchill","Computer","01012345677","EAST_16_5","C++",2500);
- StudentTeacher st("Emerson","Computer Application","Computer","01012345676",
- "EAST_16_7","C++",2200);
- cout<<"Student:";
- stu.Print();
- cout<<"Stsff:";
- sta.Print();
- cout<<"Teacher:";
- te.Print();
- cout<<"Teacher in studying:";
- st.Print();
- cout<<endl;
- }