1 #include<iostream>
2 #include<string.h>
3 using namespace std;
4 class Person
5 {
6 public:
7 Person(char n[],char i[] = "",char p[] = "")
8 {
9 strcpy(name,n);
10 strcpy(id , i);
11 strcpy(phonenumber , p);
12 }
13 ~Person(){}
14 void print()
15 {
16 cout << name << endl;
17 cout << id << endl;
18 cout << phonenumber << endl;
19 }
20 private:
21 char name[10],id[20],phonenumber[15];
22 };
23 const int Fleshman = 1;
24 const int Sophomore = 2;
25 const int Junior = 3;
26 const int Senior = 4;
27 class Student:public Person
28 {
29 public:
30 Student(char n[],char i[] = "",char p[]="",int g= 0):Person( n,i,p)
31 {
32 grade = g;
33 }
34 ~Student(){}
35 void print()
36 {
37 Person::print();
38 switch ( grade )
39 {
40 case Fleshman: cout << "Fleshman" << endl;
41 break;
42 case Sophomore : cout << "Sophomore" << endl;
43 break;
44 case Junior:cout << "Junior" << endl;
45 break;
46 case Senior : cout << "Senior" << endl;
47 break;
48 default:cout << "error!" << endl;
49 break;
50 }
51 }
52 private:
53 int grade;
54 };
55 class Mydate
56 {
57 public:
58 Mydate(int y = 0,int m = 0,int d = 0)
59 {
60 year = y;
61 month = m;
62 day = d;
63 }
64 ~Mydate(){}
65 void print()
66 {
67 cout << year << " " << month << " " << day << endl;
68 }
69 int gety()
70 {
71 return year;
72 }
73 int getm()
74 {
75 return month;
76 }
77 int getd()
78 {
79 return day;
80 }
81 double diffYear(Mydate & ma)
82 {
83 int a,b,c;
84 a = ( year - 1 ) * 12 + month;
85 b = (ma.gety() - 1) * 12 + ma.getm();
86 c =abs( b - a );
87 return c/12.0;
88 }
89 private:
90 int year;
91 int month;
92 int day;
93 };
94 class Employee:public Person
95 {
96 public:
97 Employee(char n[],char i[]="",char p[]="",char o[]="",double s=0,int y=0,int m=0,int d=0):Person(n,i,p),datehired(y,m,d)
98 {
99 strcpy(office,o);
100 salary = s;
101 }
102 ~Employee(){}
103 void setsalary(double s)
104 {
105 salary = s;
106 }
107 double getsalary()
108 {
109 return salary;
110 }
111 Mydate getdate()
112 {
113 return datehired;
114 }
115 void putsalary()
116 {
117 cout << "salary " << salary << endl;
118 }
119 void print()
120 {
121 Person::print();
122 cout << "office: " << office << endl;
123 datehired.print();
124 }
125 private:
126 char office[20];
127 double salary;
128 Mydate datehired;
129 };
130 const int Professor = 3;
131 const int AssociateProfessor = 2;
132 const int AssistantProfessor = 1;
133 const double basicwages = 1000;
134 class Faculty:public Employee
135 {
136 public:
137 Faculty(char n[],char i[]="",char p[]="",char o[]="",double s=0,int y=0,int m=0,int d=0,int r=0):Employee( n,i,p,o,s,y,m,d )
138 {
139 rank=r;
140 }
141 ~Faculty(){}
142 int calsal()
143 {
144 double sal;
145 sal = rank * basicwages;
146 Employee::setsalary(sal);
147 return 0;
148 }
149 void print()
150 {
151 Employee::print();
152 switch(rank)
153 {
154 case 1 :cout << "AssistantProfessor" << endl;
155 break;
156 case 2 :cout << "AssociateProfessor" << endl;
157 break;
158 case 3 :cout << "Professor" << endl;
159 break;
160 default:cout << "Error!" << endl;
161 break;
162 }
163 }
164 private:
165 int rank;
166 };
167 const double allowance = 500;
168 class Staff:public Employee
169 {
170 public:
171 Staff(char n[],char i[]="",char p[]="",char o[]="",double s=0,int y=0,int m=0,int d=0,char po[] = ""):Employee(n,i,p,o,s,y,m,d)
172 {
173 strcpy(position,po);
174 }
175 ~Staff(){}
176 void calculate()
177 {
178 double s;
179 Mydate mb;
180 Mydate ma(2010,1,1);
181 mb = Employee::getdate();
182 s = basicwages + allowance * mb.diffYear( ma );
183 Employee::setsalary(s);
184 }
185 void print()
186 {
187 Employee::print();
188 cout << position << endl;
189 }
190 private:
191 char position[20];
192 };
193 int main()
194 {
195 Person ren("abc","12243","1243241");
196 Student tong("sdd","3143","432132",2);
197 Employee em("adsf","341346","6465423","sgfd",1000,2008,11,3);
198 Faculty fa("fad","53534","475453","fwedf",2000,2007,11,3,2);
199 Staff st("fdsgf","47567","8769","uytu",1000,2006,11,3,"eofff");
200 st.print();
201 st.calculate();
202 st.putsalary();
203 fa.print();
204 fa.calsal();
205 fa.putsalary();
206 em.print();
207 em.putsalary();
208 tong.print();
209 ren.print();
210 cout << "That is all!" << endl;
211 return 0;
212 }