9_79.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:2k
源码类别:

文章/文档

开发平台:

C/C++

  1. #include<iostream.h>
  2. #include<string.h>
  3. class Person
  4. {
  5. public:
  6. Person(const char*n,const char*t,const char*a)
  7. {
  8. name=new char[strlen(n)+1];
  9. strcpy(name,n);
  10. tel=new char[strlen(t)+1];
  11. strcpy(tel,t);
  12. add=new char[strlen(a)+1];
  13. strcpy(add,a);
  14. }
  15. void Print() const
  16. cout<<name<<endl;
  17. cout<<" TEL:"<<tel;
  18. cout<<" Address:"<<add;
  19. }
  20. ~Person()
  21. {
  22. delete[] name;
  23. delete[] tel;
  24. delete[] add;
  25. // cout<<"Destructed class Person!"<<endl;
  26. }
  27. protected:
  28. char*name;
  29. char*tel;
  30. char*add;
  31. };
  32. class Student:virtual public Person
  33. {
  34. public:
  35. Student(const char*n,const char*t,const char*a,const char*m):Person(n,t,a)
  36. {
  37. major=new char[strlen(m)+1];
  38. strcpy(major,m);
  39. }
  40. void Print() const
  41. {
  42. Person::Print();
  43. cout<<" Major:"<<major<<endl;
  44. }
  45. protected:
  46. char*major;
  47. };
  48. class Staff:virtual public Person
  49. {
  50. public:
  51. Staff(const char*n,const char*t,const char*a,const char*d,int sal):Person(n,t,a)
  52. {
  53. dept=new char[strlen(d)+1];
  54. strcpy(dept,d);
  55. salary=sal;
  56. }
  57. void Print() const
  58. {
  59. Person::Print();
  60. cout<<" Department:"<<dept;
  61. cout<<" Salary:"<<salary<<endl;
  62. }
  63. protected:
  64. char*dept;
  65. int salary;
  66. };
  67. class Teacher: public Staff
  68. {
  69. public:
  70. Teacher(const char*n,const char*d,const char*t,const char*a,const char*l,int sal)
  71. :Person(n,t,a),Staff(n,t,a,d,sal)
  72. {
  73. lesson=new char[strlen(l)+1];
  74. strcpy(lesson,l);
  75. }
  76. void Print() const
  77. {
  78. Staff::Print();
  79. cout<<" Lesson: "<<lesson<<endl;
  80. }
  81. protected:
  82. char*lesson;
  83. };
  84. class StudentTeacher:public Student,public Teacher
  85. {
  86. public:
  87. StudentTeacher(const char*n,const char *m,const char*d,const char*t,
  88. const char*a,const char*l,int sal)
  89. :Person(n,t,a),Student(n,t,a,m),Teacher(n,d,t,a,l,sal){}
  90. void Print() const
  91. {
  92. Student::Print();
  93. cout<<" Department: "<<dept;
  94. cout<<" Lesson: "<<lesson;
  95. cout<<" Salary: "<<salary;
  96. }
  97. };
  98. void main()
  99. {
  100. Student stu("Richard","01012345678","EAST_16_1","Software Engineering");
  101. Staff sta("Volatire","01012345679","WEST_16_2","Management",2000);
  102. Teacher te("Churchill","Computer","01012345677","EAST_16_5","C++",2500);
  103. StudentTeacher st("Emerson","Computer Application","Computer","01012345676",
  104. "EAST_16_7","C++",2200);
  105.     cout<<"Student:";
  106. stu.Print();
  107. cout<<"Stsff:";
  108. sta.Print();
  109. cout<<"Teacher:";
  110. te.Print();
  111. cout<<"Teacher in studying:";
  112. st.Print();
  113. cout<<endl;
  114. }