程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作者:李君凯
* 完成日期: 2012年 5月 8日
* 版本号:
*对任务及求解方法的描述部分
01.#include<iostream> 02.#include<string> 03.#include <iomanip> 04.using namespace std; 05. 06.class Teacher 07.{ 08.public: 09. Teacher(string nam,int Age,int Sex,char *Department, int phone,string title1); 10. ~Teacher( ); 11. void display(); 12.protected: 13. string name; 14. int m_nAge; 15. int m_nSex;//0:women,1:man 16. char *m_szDepartment; 17. int m_phone; 18. string title; 19.}; 20.Teacher::Teacher(string nam,int Age,int Sex,char *Department,int phone,string title1) 21.{ 22. name=nam; 23. m_nAge=Age; 24. m_nSex=Sex; 25. int i; 26. m_szDepartment=new char[30]; 27. for(i=0;i<30;++i) 28. m_szDepartment[i]=*(Department+i); //此处的处理是个重点,处理不好,会在程序中植入非常严重且隐蔽性极强的"定时炸弹" 29. //strcpy(m_szDepartment,Department); 30. m_phone=phone; 31. title=title1; 32.} 33. 34.Teacher::~Teacher() 35.{ 36. delete [] m_szDepartment; 37.} 38.void Teacher::display() 39.{ 40. cout << setiosflags(ios :: left) << setw(5) <<name<< setw(5) <<m_nAge << setw(5)<<((m_nSex==0)?"women":"man")<<setw(8)<<m_szDepartment<<setw(5)<<title<<setw(5)<<m_phone; 41.} 42.class Cadre 43.{ 44.public: 45. Cadre(string nam,int Age,int Sex,char *Department,int phone,string post1) ; 46. ~Cadre( ); 47.protected: 48. string name; 49. int m_nAge; 50. int m_nSex;//0:women,1:man 51. char *m_szDepartment; 52. int m_phone; 53. string post; 54.}; 55.Cadre::Cadre(string nam,int Age,int Sex,char *Department,int phone,string post1) 56.{ 57. name=nam; 58. m_nAge=Age; 59. m_nSex=Sex; 60. int i; 61. m_szDepartment=new char[30]; 62. for(i=0;i<30;++i) 63. m_szDepartment[i]=*(Department+i); 64. m_phone=phone; 65. post=post1; 66.} 67.Cadre::~Cadre() 68.{ 69. delete [] m_szDepartment; 70.} 71.class Teacher_Cadre:public Teacher,public Cadre 72.{ 73.public: 74. Teacher_Cadre(string nam,int Age,int Sex,char *Department,int phone,string title1,string post1,float wages1) ; 75. //~Teacher_Cadre( ); 76. void show(); 77. friend ostream & operator<<(ostream &,const Teacher_Cadre &);//重载运算符"<<" 78.protected: 79. /*string name; 80. int m_nAge; 81. int m_nSex;//0:women,1:man 82. char *m_szDepartment; 83. int m_phone; */ 84. float wages; 85.}; 86.Teacher_Cadre::Teacher_Cadre(string nam,int Age,int Sex,char *Department,int phone,string title1,string post1,float wages1):Teacher(nam,Age,Sex,Department,phone,title1),Cadre(nam,Age,Sex,Department,phone,post1),wages(wages1){} 87./*Teacher_Cadre::~Teacher_Cadre() 88.{ 89. delete [] m_szDepartment; 90.}*/ 91.void Teacher_Cadre::show() 92.{ 93. display(); 94.} 95.ostream & operator<<(ostream &output,const Teacher_Cadre &p) 96.{ 97. output<<" 工资为:"; 98. output<<setw(5)<<p.wages<<" "; 99. output<<"职务为:"; 100. output<<p.title<<endl; 101. return output; 102.} 103. 104.int main( ) 105.{ 106. string name,title1,post1; 107. char department[10]; 108. int sex,age; 109. int phone; 110. float wages; 111. cout<<"input Teacher_Cadre's name,Age,sex(0:women,1:man),department,phone,title,post,wages:\n"; 112. cin>>name>>age>>sex>>department>>phone>>title1>>post1>>wages; 113. Teacher_Cadre Teacher_Cadre1(name,age,sex,department,phone,title1,post1,wages); 114. Teacher_Cadre1.show(); 115. cout<<Teacher_Cadre1; 116. system("PAUSE"); 117. return 0; 118.}