员工管理系统输出界面的美化-----c++

最近在翻阅往期作业的时候,发现在大一学习c语言的时候的大作业存在些许问题,我逐步改进我现在能解决的一些问题,并将输出界面美化

改进

改进1

我首先将信息的是提前内置在程序中的方式更改为可以随时输入,增加了输入功能

改进2

原本的系统在输入错误信息后会报乱码,我在每一个模块前加入了判断语句

改进3

我将代码从301增加到852,将输出界面美化

原代码

 

  1 #include <iostream>
  2 #include <string>
  3 #include <fstream>
  4 
  5 using namespace std;
  6 
  7 class Employee {
  8 public:
  9     string no;// 工号
 10     string name;
 11     string sex;
 12     string tel;
 13     string room;// 科室
 14     double wage; //工资 按月算
 15     double deduct;
 16     double extra;
 17 
 18     Employee(const string &no, const string &name, const string &sex, const string &tel, const string &room,
 19              double wage)
 20             : no(no), name(name), sex(sex), tel(tel), room(room), wage(wage) {
 21         deduct = 0;
 22         extra = 0;
 23     }
 24 
 25     Employee() {
 26         deduct = 0;
 27         extra = 0;
 28     }
 29 };
 30 
 31 class Manage {
 32 private:
 33     Employee es[100];
 34     int n;
 35 
 36 public:
 37     Manage() {
 38         n = 0;
 39     }
 40 
 41     void print_all() {
 42         int i;
 43         cout << "工号\t姓名\t性别\t电话\t科室\t工资\t迟到扣除\t加班奖励\n";
 44         for (i = 0; i < n; i++) {
 45             cout << es[i].no << "\t" << es[i].name << "\t" << es[i].sex << "\t" << es[i].tel << "\t" << es[i].room
 46                  << "\t" << es[i].wage << "\t" << es[i].deduct << "\t" << es[i].extra << endl;
 47         }
 48     }
 49 
 50     int find_by_no(string no) {
 51         int i;
 52         for (i = 0; i < n; i++) {
 53             if (es[i].no == no)
 54                 return i;
 55         }
 56         return -1;
 57     }
 58 
 59     int find_by_name(string name) {
 60         int i;
 61         for (i = 0; i < n; i++) {
 62             if (es[i].name == name)
 63                 return i;
 64         }
 65         return -1;
 66     }
 67 
 68     void select() {
 69         int choose;
 70         int index;
 71         string v;
 72         cout << "请问您想通过什么来查找员工:" << endl;
 73         cout << "1.工号" << endl;
 74         cout << "2.姓名" << endl;
 75         cin >> choose;
 76         if (choose == 1) {
 77             cout << "请输入您要查找的工号:";
 78             cin >> v;
 79             index = find_by_no(v);
 80         } else {
 81             cout << "请输入您要查找的姓名:";
 82             cin >> v;
 83             index = find_by_name(v);
 84         }
 85         if (index == -1) {
 86             cout << "您要查找的员工不存在!" << endl;
 87             return;
 88         }
 89         Employee e = es[index];
 90         cout << "工号\t姓名\t性别\t电话\t科室\t工资\t迟到扣除\t加班奖励\n";
 91         cout << e.no << "\t" << e.name << "\t" << e.sex << "\t" << e.tel << "\t" << e.room
 92              << "\t" << e.wage << "\t" << e.deduct << "\t" << e.extra << endl;
 93     }
 94 
 95     void add() {
 96         string no;// 工号
 97         string name;
 98         string sex;
 99         string tel;
100         string room;// 科室
101         double wage; //工资
102         cout << "请输入新员工工号:";
103         cin >> no;
104         cout << "请输入新员工姓名:";
105         cin >> name;
106         cout << "请输入新员工性别:";
107         cin >> sex;
108         cout << "请输入新员工电话:";
109         cin >> tel;
110         cout << "请输入新员工科室:";
111         cin >> room;
112         cout << "请输入新员工工资:";
113         cin >> wage;
114         Employee e(no, name, sex, tel, room, wage);
115         es[n++] = e;
116     }
117 
118     void del() {
119         string no;
120         int index;
121         int i;
122         cout << "请输入您想删除的工号:";
123         cin >> no;
124         index = find_by_no(no);
125         if (index == -1) {
126             cout << "您要查找的员工不存在!" << endl;
127             return;
128         }
129         n--;
130         for (i = index; i < n; i++)
131             es[i] = es[i + 1];
132     }
133 
134     void update() {
135         string no;
136         int index;
137         int choose;
138         int i;
139         cout << "请输入您想编辑的员工的工号:";
140         cin >> no;
141         index = find_by_no(no);
142         if (index == -1) {
143             cout << "您要查找的员工不存在!" << endl;
144             return;
145         }
146         cout << "请问您想修改员工的什么信息:" << endl;
147         cout << "1.工号" << endl;
148         cout << "2.姓名" << endl;
149         cout << "3.性别" << endl;
150         cout << "4.电话" << endl;
151         cout << "5.科室" << endl;
152         cout << "6.工资" << endl;
153 
154         cin >> choose;
155         if (choose == 1) {
156             cout << "请输入更改之后的工号:";
157             cin >> es[index].no;
158         } else if (choose == 2) {
159             cout << "请输入更改之后的姓名:";
160             cin >> es[index].name;
161         } else if (choose == 3) {
162             cout << "请输入更改之后的性别:";
163             cin >> es[index].tel;
164         } else if (choose == 4) {
165             cout << "请输入更改之后的电话:";
166             cin >> es[index].tel;
167         } else if (choose == 5) {
168             cout << "请输入更改之后的科室:";
169             cin >> es[index].room;
170         } else if (choose == 6) {
171             cout << "请输入更改之后的工资:";
172             cin >> es[index].wage;
173         }
174     }
175 
176     void analysis() {
177         int book[100] = {0};
178         int i, j;
179         double sum = 0;
180         int num = 0;
181         for (i = 0; i < n; i++) {
182             if (!book[i]) {
183                 sum = 0;
184                 num = 0;
185                 for (j = i; j < n; j++) {
186                     if (!book[j] && es[j].room == es[i].room) {
187                         book[j] = 1;
188                         num++;
189                         sum += es[j].wage;
190                     }
191                 }
192                 cout << "科室 " << es[i].room << " 的平均工资为:" << sum / num << endl;
193             }
194         }
195     }
196 
197     void load() {
198         ifstream f("data.txt");
199         int i;
200         n = 0;
201         if (f.fail())
202             return;
203         f >> n;
204         for (i = 0; i < n; i++) {
205             f >> es[i].no >> es[i].name >> es[i].sex >> es[i].tel >> es[i].room >> es[i].wage >> es[i].deduct
206               >> es[i].extra;
207         }
208         f.close();
209     }
210 
211     void save() {
212         ofstream f("data.txt");
213         int i;
214         f << n << endl;
215         for (i = 0; i < n; i++) {
216             f << es[i].no << " " << es[i].name << " " << es[i].sex << " " << es[i].tel << " " << es[i].room
217               << " " << es[i].wage << " " << es[i].deduct << " " << es[i].extra << endl;
218         }
219         f.close();
220     }
221 
222     void regis_overtime() {
223         string no;
224         int index;
225         int h;
226         cout << "请输入您想登记的员工的工号:";
227         cin >> no;
228         index = find_by_no(no);
229         if (index == -1) {
230             cout << "您要查找的员工不存在!" << endl;
231             return;
232         }
233         cout << "请输入该员工加班了多少小时:";
234         cin >> h;
235         es[index].extra += es[index].wage / 30 / 24 * h;
236         cout << "登记成功";
237     }
238 
239     void regis_late() {
240         string no;
241         int index;
242         int h;
243         cout << "请输入您想登记的员工的工号:";
244         cin >> no;
245         index = find_by_no(no);
246         if (index == -1) {
247             cout << "您要查找的员工不存在!" << endl;
248             return;
249         }
250         cout << "请输入该员工迟到了多少小时:";
251         cin >> h;
252         es[index].deduct += es[index].wage / 30 / 24 * h;
253         cout << "登记成功";
254     }
255 
256     void menu() {
257         int choose;
258         load();
259         while (1) {
260             cout << endl
261                  << endl
262                  << endl;
263             cout << "*员工管理系统" << endl;
264             cout << "1.查看所有员工" << endl;
265             cout << "2.添加员工" << endl;
266             cout << "3.编辑员工" << endl;
267             cout << "4.删除员工" << endl;
268             cout << "5.查询员工" << endl;
269             cout << "6.统计员工" << endl;
270             cout << "7.登记迟到" << endl;
271             cout << "8.登记加班" << endl;
272             cout << "9.退出" << endl;
273             cin >> choose;
274             if (choose == 1) {
275                 print_all();
276             } else if (choose == 2) {
277                 add();
278             } else if (choose == 3) {
279                 update();
280             } else if (choose == 4) {
281                 del();
282             } else if (choose == 5) {
283                 select();
284             } else if (choose == 6) {
285                 analysis();
286             } else if (choose == 7) {
287                 regis_late();
288             } else if (choose == 8) {
289                 regis_overtime();
290             } else if (choose == 9) {
291                 break;
292             }
293             save();
294         }
295     }
296 };
297 
298 int main() {
299     Manage m;
300     m.menu();
301 }
View Code

 

改代码

  1 #include <iostream>
  2 #include <string>
  3 #include <fstream>
  4 
  5 using namespace std;
  6 
  7 class Employee 
  8 {
  9 public:
 10     string no;// 工号
 11     string name;//姓名 
 12     string sex;//性别 
 13     string tel;//电话 
 14     string room;// 科室
 15     double wage; //工资 按月算
 16     double deduct;//迟到扣除 
 17     double extra;//加班奖励 
 18 
 19     Employee(const string &no, const string &name, const string &sex, const string &tel, const string &room,
 20              double wage)
 21             : no(no), name(name), sex(sex), tel(tel), room(room), wage(wage) {
 22         deduct = 0;
 23         extra = 0;
 24     }
 25 
 26     Employee() {
 27         deduct = 0;
 28         extra = 0;
 29     }
 30 };
 31 
 32 class Manage 
 33 {
 34 private:
 35     Employee es[100];
 36     int n;
 37 
 38 public:
 39     Manage() {
 40         n = 0;
 41     }
 42 
 43     void print_all() {
 44         int i;
 45         cout << "工号\t姓名\t性别\t电话\t科室\t工资\t迟到扣除\t加班奖励\n";
 46         for (i = 0; i < n; i++) {
 47             cout << es[i].no << "\t" << es[i].name << "\t" << es[i].sex << "\t" << es[i].tel << "\t" << es[i].room
 48                  << "\t" << es[i].wage << "\t" << es[i].deduct << "\t" << es[i].extra << endl;
 49         }
 50     }
 51 
 52     int find_by_no(string no) {
 53         int i;
 54         for (i = 0; i < n; i++) {
 55             if (es[i].no == no)
 56                 return i;
 57         }
 58         return -1;
 59     }
 60 
 61     int find_by_name(string name) {
 62         int i;
 63         for (i = 0; i < n; i++) {
 64             if (es[i].name == name)
 65                 return i;
 66         }
 67         return -1;
 68     }
 69 
 70     void select() //查找员工 
 71     {
 72         int choose;
 73         int index;
 74         string v;
 75         system("cls") ;
 76         cout << "          **********员工管理系统**********" << endl;
 77         cout <<"          *                              *"<< endl; 
 78         cout <<"          *                              *"<< endl; 
 79         cout <<"          *                              *"<< endl; 
 80         cout <<"          *                              *"<< endl; 
 81         cout <<"          *                              *"<< endl; 
 82         cout <<"          *                              *"<< endl;
 83         cout <<"          *  请问您想通过什么来查找员工:*" << endl;
 84         cout <<"          *    1.工号                    *"<< endl;
 85         cout <<"          *    2.姓名                    *" << endl;
 86         cout <<"          *                              *"<< endl; 
 87         cout <<"          *                              *"<< endl; 
 88         cout <<"          *                              *"<< endl; 
 89         cout <<"          *                              *"<< endl; 
 90         cout <<"          *                              *"<< endl; 
 91         cout <<"          *                              *"<< endl;   
 92         cout <<"          ********************************" << endl;
 93         cin >> choose;
 94         if (choose == 1) {
 95             system("cls") ;
 96         cout << "          **********员工管理系统**********" << endl;
 97         cout <<"          *                              *"<< endl; 
 98         cout <<"          *                              *"<< endl; 
 99         cout <<"          *                              *"<< endl; 
100         cout <<"          *                              *"<< endl; 
101         cout <<"          *                              *"<< endl; 
102         cout <<"          *                              *"<< endl;
103         cout <<"          *  请输入您要查找的工号:      *"<< endl;
104         cout <<"          *                              *"<< endl; 
105         cout <<"          *                              *"<< endl; 
106         cout <<"          *                              *"<< endl; 
107         cout <<"          *                              *"<< endl; 
108         cout <<"          *                              *"<< endl; 
109         cout <<"          *                              *"<< endl;  
110         cout <<"          *                              *"<< endl; 
111         cout <<"          ********************************" << endl;
112             cin >> v;
113             index = find_by_no(v);
114         } else {
115             system("cls") ;
116         cout << "          **********员工管理系统**********" << endl;
117         cout <<"          *                              *"<< endl; 
118         cout <<"          *                              *"<< endl; 
119         cout <<"          *                              *"<< endl; 
120         cout <<"          *                              *"<< endl; 
121         cout <<"          *                              *"<< endl; 
122         cout <<"          *                              *"<< endl;
123         cout <<"          *   请输入您要查找的姓名:     *"<< endl;
124         cout <<"          *                              *"<< endl; 
125         cout <<"          *                              *"<< endl; 
126         cout <<"          *                              *"<< endl; 
127         cout <<"          *                              *"<< endl; 
128         cout <<"          *                              *"<< endl; 
129         cout <<"          *                              *"<< endl;  
130         cout <<"          *                              *"<< endl; 
131         cout <<"          ********************************" << endl;
132             cin >> v;
133             index = find_by_name(v);
134         }
135         if (index == -1) {
136             system("cls") ;
137         cout << "          **********员工管理系统**********" << endl;
138         cout <<"          *                              *"<< endl; 
139         cout <<"          *                              *"<< endl; 
140         cout <<"          *                              *"<< endl; 
141         cout <<"          *                              *"<< endl; 
142         cout <<"          *                              *"<< endl; 
143         cout <<"          *                              *"<< endl;
144         cout <<"          *    您要查找的员工不存在!    *" << endl;
145         cout <<"          *                              *"<< endl; 
146         cout <<"          *                              *"<< endl; 
147         cout <<"          *                              *"<< endl; 
148         cout <<"          *                              *"<< endl; 
149         cout <<"          *                              *"<< endl; 
150         cout <<"          *                              *"<< endl;  
151         cout <<"          *                              *"<< endl; 
152         cout <<"          ********************************" << endl;
153         system("pause");
154             return;
155         }
156         Employee e = es[index];
157         system("cls") ;
158         cout << "          *******************************员工管理系统*************************************" << endl;
159         cout <<"          *                                                                               *"<< endl; 
160         cout <<"          *                                                                               *"<< endl; 
161         cout <<"          *                                                                               *"<< endl; 
162         cout <<"          *                                                                               *"<< endl; 
163         cout <<"          *                                                                               *"<< endl; 
164         cout <<"          *                                                                               *"<< endl;
165         cout <<"          *   工号\t姓名\t性别\t电话\t科室\t工资\t迟到扣除\t加班奖励\n          *";
166         cout <<"\t"<< e.no << "\t" << e.name << "\t" << e.sex << "\t" << e.tel << "\t" << e.room
167              << "\t" << e.wage << "\t" << e.deduct << "\t" << e.extra << endl;
168              cout <<"          *                                                                          *"<< endl; 
169         cout <<"          *                                                                               *"<< endl; 
170         cout <<"          *                                                                               *"<< endl; 
171         cout <<"          *                                                                               *"<< endl; 
172         cout <<"          *                                                                               *"<< endl; 
173         cout <<"          *                                                                               *"<< endl;  
174         cout <<"          *                                                                               *"<< endl; 
175         cout <<"          *********************************************************************************" << endl;
176         system("pause");     
177     }
178 
179     void add() //添加员工 
180     {
181         string no;// 工号
182         string name;//姓名 
183         string sex;//性别 
184         string tel;//电话 
185         string room;// 科室
186         double wage; //工资
187         system("cls") ;
188         cout << "          **********员工管理系统**********" << endl;
189         cout <<"          *                              *"<< endl; 
190         cout <<"          *                              *"<< endl; 
191         cout <<"          *                              *"<< endl; 
192         cout <<"          *                              *"<< endl; 
193         cout <<"          *                              *"<< endl; 
194         cout <<"          *                              *"<< endl;
195         cout <<"          *     请输入新员工工号:       *"<< endl;
196         cout <<"          *                              *"<< endl; 
197         cout <<"          *                              *"<< endl; 
198         cout <<"          *                              *"<< endl; 
199         cout <<"          *                              *"<< endl; 
200         cout <<"          *                              *"<< endl; 
201         cout <<"          *                              *"<< endl;  
202         cout <<"          *                              *"<< endl; 
203         cout <<"          ********************************" << endl;
204         cin >> no;
205         system("cls") ;
206         cout << "          **********员工管理系统**********" << endl;
207         cout <<"          *                              *"<< endl; 
208         cout <<"          *                              *"<< endl; 
209         cout <<"          *                              *"<< endl; 
210         cout <<"          *                              *"<< endl; 
211         cout <<"          *                              *"<< endl; 
212         cout <<"          *                              *"<< endl;
213         cout << "          *     请输入新员工姓名:       *"<< endl;
214         cout <<"          *                              *"<< endl; 
215         cout <<"          *                              *"<< endl; 
216         cout <<"          *                              *"<< endl; 
217         cout <<"          *                              *"<< endl; 
218         cout <<"          *                              *"<< endl; 
219         cout <<"          *                              *"<< endl;  
220         cout <<"          *                              *"<< endl; 
221         cout <<"          ********************************" << endl;
222         cin >> name;
223         system("cls") ;
224         cout << "          **********员工管理系统**********" << endl;
225         cout <<"          *                              *"<< endl; 
226         cout <<"          *                              *"<< endl; 
227         cout <<"          *                              *"<< endl; 
228         cout <<"          *                              *"<< endl; 
229         cout <<"          *                              *"<< endl; 
230         cout <<"          *                              *"<< endl;
231         cout << "          *     请输入新员工性别:       *"<< endl;
232         cout <<"          *                              *"<< endl; 
233         cout <<"          *                              *"<< endl; 
234         cout <<"          *                              *"<< endl; 
235         cout <<"          *                              *"<< endl; 
236         cout <<"          *                              *"<< endl; 
237         cout <<"          *                              *"<< endl;  
238         cout <<"          *                              *"<< endl; 
239         cout <<"          ********************************" << endl;
240         cin >> sex;
241         system("cls") ;
242         cout << "          **********员工管理系统**********" << endl;
243         cout <<"          *                              *"<< endl; 
244         cout <<"          *                              *"<< endl; 
245         cout <<"          *                              *"<< endl; 
246         cout <<"          *                              *"<< endl; 
247         cout <<"          *                              *"<< endl; 
248         cout <<"          *                              *"<< endl;
249         cout << "          *     请输入新员工电话:       *"<< endl;
250         cout <<"          *                              *"<< endl; 
251         cout <<"          *                              *"<< endl; 
252         cout <<"          *                              *"<< endl; 
253         cout <<"          *                              *"<< endl; 
254         cout <<"          *                              *"<< endl; 
255         cout <<"          *                              *"<< endl;  
256         cout <<"          *                              *"<< endl; 
257         cout <<"          ********************************" << endl;
258         cin >> tel;
259         system("cls") ;
260         cout << "          **********员工管理系统**********" << endl;
261         cout <<"          *                              *"<< endl; 
262         cout <<"          *                              *"<< endl; 
263         cout <<"          *                              *"<< endl; 
264         cout <<"          *                              *"<< endl; 
265         cout <<"          *                              *"<< endl; 
266         cout <<"          *                              *"<< endl;
267         cout << "          *     请输入新员工科室:       *"<< endl;
268         cout <<"          *                              *"<< endl; 
269         cout <<"          *                              *"<< endl; 
270         cout <<"          *                              *"<< endl; 
271         cout <<"          *                              *"<< endl; 
272         cout <<"          *                              *"<< endl; 
273         cout <<"          *                              *"<< endl;  
274         cout <<"          *                              *"<< endl; 
275         cout <<"          ********************************" << endl;
276         cin >> room;
277         system("cls") ;
278         cout << "          **********员工管理系统**********" << endl;
279         cout <<"          *                              *"<< endl; 
280         cout <<"          *                              *"<< endl; 
281         cout <<"          *                              *"<< endl; 
282         cout <<"          *                              *"<< endl; 
283         cout <<"          *                              *"<< endl; 
284         cout <<"          *                              *"<< endl;
285         cout << "          *     请输入新员工工资:       *"<< endl;
286         cout <<"          *                              *"<< endl; 
287         cout <<"          *                              *"<< endl; 
288         cout <<"          *                              *"<< endl; 
289         cout <<"          *                              *"<< endl; 
290         cout <<"          *                              *"<< endl; 
291         cout <<"          *                              *"<< endl;  
292         cout <<"          *                              *"<< endl; 
293         cout <<"          ********************************" << endl;
294         cin >> wage;
295         Employee e(no, name, sex, tel, room, wage);
296         es[n++] = e;
297     }
298 
299     void del() //删除员工信息 
300     {
301         system("cls") ;
302         string no;
303         int index;
304         int i;
305         cout << "          **********员工管理系统**********" << endl;
306         cout <<"          *                              *"<< endl; 
307         cout <<"          *                              *"<< endl; 
308         cout <<"          *                              *"<< endl; 
309         cout <<"          *                              *"<< endl; 
310         cout <<"          *                              *"<< endl; 
311         cout <<"          *                              *"<< endl;
312         cout <<"          *     请输入您想删除的工号:   *"<< endl;
313         cout <<"          *                              *"<< endl; 
314         cout <<"          *                              *"<< endl; 
315         cout <<"          *                              *"<< endl; 
316         cout <<"          *                              *"<< endl; 
317         cout <<"          *                              *"<< endl; 
318         cout <<"          *                              *"<< endl;  
319         cout <<"          *                              *"<< endl; 
320         cout <<"          ********************************" << endl;
321         cin >> no;
322         index = find_by_no(no);
323         if (index == -1) {
324             system("cls") ;
325             cout << "          **********员工管理系统**********" << endl;
326             cout <<"          *                              *"<< endl; 
327             cout <<"          *                              *"<< endl; 
328                cout <<"          *                              *"<< endl; 
329                cout <<"          *                              *"<< endl; 
330             cout <<"          *                              *"<< endl; 
331             cout <<"          *                              *"<< endl;
332             cout <<"          *    您要查找的员工不存在!    *" << endl;
333             cout <<"          *                              *"<< endl; 
334             cout <<"          *                              *"<< endl; 
335             cout <<"          *                              *"<< endl; 
336             cout <<"          *                              *"<< endl; 
337             cout <<"          *                              *"<< endl; 
338             cout <<"          *                              *"<< endl;  
339             cout <<"          *                              *"<< endl; 
340             cout <<"          ********************************" << endl;
341             system("pause");
342             return;
343         }
344         n--;
345         for (i = index; i < n; i++)
346             es[i] = es[i + 1];
347     }
348 
349     void update() //修改员工信息 
350     {
351         system("cls") ;
352         string no;
353         int index;
354         int choose;
355         int i;
356         cout << "          **********员工管理系统**********" << endl;
357         cout <<"          *                              *"<< endl; 
358         cout <<"          *                              *"<< endl; 
359         cout <<"          *                              *"<< endl; 
360         cout <<"          *                              *"<< endl; 
361         cout <<"          *                              *"<< endl; 
362         cout <<"          *                              *"<< endl;
363         cout <<"          * 请输入您想修改的员工的工号: *"<< endl;
364         cout <<"          *                              *"<< endl; 
365         cout <<"          *                              *"<< endl; 
366         cout <<"          *                              *"<< endl; 
367         cout <<"          *                              *"<< endl; 
368         cout <<"          *                              *"<< endl; 
369         cout <<"          *                              *"<< endl;  
370         cout <<"          *                              *"<< endl; 
371         cout <<"          ********************************" << endl;
372         cin >> no;
373         index = find_by_no(no);
374         if (index == -1) {
375             system("cls") ;
376             cout << "          **********员工管理系统**********" << endl;
377                 cout <<"          *                              *"<< endl; 
378             cout <<"          *                              *"<< endl; 
379             cout <<"          *                              *"<< endl; 
380                 cout <<"          *                              *"<< endl; 
381             cout <<"          *                              *"<< endl; 
382                 cout <<"          *                              *"<< endl;
383             cout <<"          *您要查找的员工不存在!        *" << endl;
384             cout <<"          *                              *"<< endl; 
385             cout <<"          *                              *"<< endl; 
386             cout <<"          *                              *"<< endl; 
387             cout <<"          *                              *"<< endl; 
388             cout <<"          *                              *"<< endl; 
389             cout <<"          *                              *"<< endl;  
390             cout <<"          *                              *"<< endl; 
391                cout <<"          ********************************" << endl;
392                system("pause");
393             return;
394         }
395         system("cls") ;
396         cout << "          **********员工管理系统**********" << endl;
397                 cout <<"          *                              *"<< endl; 
398             cout <<"          *                              *"<< endl; 
399             cout <<"          *                              *"<< endl; 
400             cout <<"          *  请问您想修改员工的什么信息:*" << endl;
401             cout <<"          *   1.工号                     *"<< endl;
402                cout <<"          *   2.姓名                     *" << endl;
403             cout <<"          *   3.性别                     *" << endl;
404             cout <<"          *   4.电话                     *" << endl;
405             cout <<"          *   5.科室                     *" << endl;
406             cout <<"          *   6.工资                     *" << endl;
407             cout <<"          *                              *"<< endl; 
408             cout <<"          *                              *"<< endl; 
409             cout <<"          *                              *"<< endl;  
410             cout <<"          *                              *"<< endl; 
411                cout <<"          ********************************" << endl;
412 
413         cin >> choose;
414         if (choose == 1) {
415             system("cls") ;
416             cout << "          **********员工管理系统**********" << endl;
417                 cout <<"          *                              *"<< endl; 
418             cout <<"          *                              *"<< endl; 
419             cout <<"          *                              *"<< endl; 
420                 cout <<"          *                              *"<< endl; 
421             cout <<"          *                              *"<< endl; 
422                 cout <<"          *                              *"<< endl;
423             cout << "          *   请输入更改之后的工号:     *"<< endl;
424             cout <<"          *                              *"<< endl; 
425             cout <<"          *                              *"<< endl; 
426             cout <<"          *                              *"<< endl; 
427             cout <<"          *                              *"<< endl; 
428             cout <<"          *                              *"<< endl; 
429             cout <<"          *                              *"<< endl;  
430             cout <<"          *                              *"<< endl; 
431                cout <<"          ********************************" << endl;
432             cin >> es[index].no;
433         } else if (choose == 2) {
434             system("cls") ;
435             cout << "          **********员工管理系统**********" << endl;
436                 cout <<"          *                              *"<< endl; 
437             cout <<"          *                              *"<< endl; 
438             cout <<"          *                              *"<< endl; 
439                 cout <<"          *                              *"<< endl; 
440             cout <<"          *                              *"<< endl; 
441                 cout <<"          *                              *"<< endl;
442             cout << "          *    请输入更改之后的姓名:    *"<< endl;
443             cout <<"          *                              *"<< endl; 
444             cout <<"          *                              *"<< endl; 
445             cout <<"          *                              *"<< endl; 
446             cout <<"          *                              *"<< endl; 
447             cout <<"          *                              *"<< endl; 
448             cout <<"          *                              *"<< endl;  
449             cout <<"          *                              *"<< endl; 
450                cout <<"          ********************************" << endl;
451             cin >> es[index].name;
452         } else if (choose == 3) {
453             system("cls") ;
454             cout << "          **********员工管理系统**********" << endl;
455                 cout <<"          *                              *"<< endl; 
456             cout <<"          *                              *"<< endl; 
457             cout <<"          *                              *"<< endl; 
458                 cout <<"          *                              *"<< endl; 
459             cout <<"          *                              *"<< endl; 
460                 cout <<"          *                              *"<< endl;
461             cout << "          *    请输入更改之后的性别:    *"<< endl;
462             cout <<"          *                              *"<< endl; 
463             cout <<"          *                              *"<< endl; 
464             cout <<"          *                              *"<< endl; 
465             cout <<"          *                              *"<< endl; 
466             cout <<"          *                              *"<< endl; 
467             cout <<"          *                              *"<< endl;  
468             cout <<"          *                              *"<< endl; 
469                cout <<"          ********************************" << endl;
470             cin >> es[index].tel;
471         } else if (choose == 4) {
472             system("cls") ;
473             cout << "          **********员工管理系统**********" << endl;
474                 cout <<"          *                              *"<< endl; 
475             cout <<"          *                              *"<< endl; 
476             cout <<"          *                              *"<< endl; 
477                 cout <<"          *                              *"<< endl; 
478             cout <<"          *                              *"<< endl; 
479                 cout <<"          *                              *"<< endl;
480             cout << "          *   请输入更改之后的电话:     *"<< endl;
481             cout <<"          *                              *"<< endl; 
482             cout <<"          *                              *"<< endl; 
483             cout <<"          *                              *"<< endl; 
484             cout <<"          *                              *"<< endl; 
485             cout <<"          *                              *"<< endl; 
486             cout <<"          *                              *"<< endl;  
487             cout <<"          *                              *"<< endl; 
488                cout <<"          ********************************" << endl;
489             cin >> es[index].tel;
490         } else if (choose == 5) {
491             system("cls") ;
492             cout << "          **********员工管理系统**********" << endl;
493                 cout <<"          *                              *"<< endl; 
494             cout <<"          *                              *"<< endl; 
495             cout <<"          *                              *"<< endl; 
496                 cout <<"          *                              *"<< endl; 
497             cout <<"          *                              *"<< endl; 
498                 cout <<"          *                              *"<< endl;
499             cout << "          *   请输入更改之后的科室:     *"<< endl;
500             cout <<"          *                              *"<< endl; 
501             cout <<"          *                              *"<< endl; 
502             cout <<"          *                              *"<< endl; 
503             cout <<"          *                              *"<< endl; 
504             cout <<"          *                              *"<< endl; 
505             cout <<"          *                              *"<< endl;  
506             cout <<"          *                              *"<< endl; 
507                cout <<"          ********************************" << endl;
508             cin >> es[index].room;
509         } else if (choose == 6) {
510             system("cls") ;
511             cout << "          **********员工管理系统**********" << endl;
512                 cout <<"          *                              *"<< endl; 
513             cout <<"          *                              *"<< endl; 
514             cout <<"          *                              *"<< endl; 
515                 cout <<"          *                              *"<< endl; 
516             cout <<"          *                              *"<< endl; 
517                 cout <<"          *                              *"<< endl;
518             cout << "          *请输入更改之后的工资:        *"<< endl; 
519             cout <<"          *                              *"<< endl; 
520             cout <<"          *                              *"<< endl; 
521             cout <<"          *                              *"<< endl; 
522             cout <<"          *                              *"<< endl; 
523             cout <<"          *                              *"<< endl; 
524             cout <<"          *                              *"<< endl;  
525             cout <<"          *                              *"<< endl; 
526                cout <<"          ********************************" << endl;
527             cin >> es[index].wage;
528         }
529     }
530 
531     void analysis() //平均工资 
532     {
533         system("cls") ;
534         int book[100] = {0};
535         int i, j;
536         double sum = 0;
537         int num = 0;
538         for (i = 0; i < n; i++) {
539             if (!book[i]) {
540                 sum = 0;
541                 num = 0;
542                 for (j = i; j < n; j++) {
543                     if (!book[j] && es[j].room == es[i].room) {
544                         book[j] = 1;
545                         num++;
546                         sum += es[j].wage;
547                     }
548                 }
549                 cout << "          **********员工管理系统**********" << endl;
550                 cout <<"          *                              *"<< endl; 
551                 cout <<"          *                              *"<< endl; 
552                 cout <<"          *                              *"<< endl; 
553                 cout <<"          *                              *"<< endl;  
554                 cout <<"          *                              *"<< endl;
555                 cout <<"          *    科室 " << es[i].room << endl
556                      <<"          *   的平均工资为:" << sum / num << endl;
557                 cout <<"          *                              *"<< endl; 
558                 cout <<"          *                              *"<< endl; 
559                 cout <<"          *                              *"<< endl; 
560                 cout <<"          *                              *"<< endl; 
561                 cout <<"          *                              *"<< endl; 
562                     cout <<"          *                              *"<< endl;  
563                 cout <<"          *                              *"<< endl; 
564                 cout <<"          ********************************" << endl;
565                 system("pause");
566             }
567         }
568     }
569 
570     void load() 
571     {
572         ifstream f("data.txt");
573         int i;
574         n = 0;
575         if (f.fail())
576             return;
577         f >> n;
578         for (i = 0; i < n; i++) {
579             f >> es[i].no >> es[i].name >> es[i].sex >> es[i].tel >> es[i].room >> es[i].wage >> es[i].deduct
580               >> es[i].extra;
581         }
582         f.close();
583     }
584 
585     void save() 
586     {
587         ofstream f("data.txt");
588         int i;
589         f << n << endl;
590         for (i = 0; i < n; i++) {
591             f << es[i].no << " " << es[i].name << " " << es[i].sex << " " << es[i].tel << " " << es[i].room
592               << " " << es[i].wage << " " << es[i].deduct << " " << es[i].extra << endl;
593         }
594         f.close();
595     }
596 
597     void regis_overtime() //加班 
598     {
599         system("cls") ;
600         string no;
601         int index;
602         int h;
603         system("cls") ;
604         cout << "          **********员工管理系统**********" << endl;
605         cout <<"          *                              *"<< endl; 
606         cout <<"          *                              *"<< endl; 
607         cout <<"          *                              *"<< endl; 
608         cout <<"          *                              *"<< endl; 
609         cout <<"          *                              *"<< endl; 
610         cout <<"          *                              *"<< endl;
611         cout <<"          *  请输入您想登记的员工的工号: *"<< endl;
612         cout <<"          *                              *"<< endl; 
613         cout <<"          *                              *"<< endl; 
614         cout <<"          *                              *"<< endl; 
615         cout <<"          *                              *"<< endl; 
616         cout <<"          *                              *"<< endl; 
617         cout <<"          *                              *"<< endl;  
618         cout <<"          *                              *"<< endl; 
619         cout <<"          ********************************" << endl;
620         cin >> no;
621         index = find_by_no(no);
622         if (index == -1) {
623             system("cls") ;
624             cout << "          **********员工管理系统**********" << endl;
625             cout <<"          *                              *"<< endl;
626             cout <<"          *                              *"<< endl; 
627             cout <<"          *                              *"<< endl; 
628             cout <<"          *                              *"<< endl;
629             cout <<"          *                              *"<< endl; 
630             cout <<"          *                              *"<< endl;  
631             cout <<"          *    您要查找的员工不存在!    *" << endl;
632             cout <<"          *                              *"<< endl;  
633             cout <<"          *                              *"<< endl; 
634             cout <<"          *                              *"<< endl; 
635             cout <<"          *                              *"<< endl; 
636             cout <<"          *                              *"<< endl; 
637             cout <<"          *                              *"<< endl; 
638             cout <<"          *                              *"<< endl; 
639             cout <<"          ********************************" << endl;
640             cout <<endl
641                  <<endl;
642             system("pause");
643             return;
644         }
645         system("cls") ;
646         cout << "          **********员工管理系统**********" << endl;
647         cout <<"          *                              *"<< endl; 
648         cout <<"          *                              *"<< endl; 
649         cout <<"          *                              *"<< endl; 
650         cout <<"          *                              *"<< endl; 
651         cout <<"          *                              *"<< endl; 
652         cout <<"          *                              *"<< endl;
653         cout <<"          * 请输入该员工加班了多少小时: *"<< endl;
654         cout <<"          *                              *"<< endl;  
655         cout <<"          *                              *"<< endl; 
656         cout <<"          *                              *"<< endl; 
657         cout <<"          *                              *"<< endl; 
658            cout <<"          *                              *"<< endl; 
659         cout <<"          *                              *"<< endl; 
660         cout <<"          *                              *"<< endl; 
661         cout <<"          ********************************" << endl;
662         cin >> h;
663         es[index].extra += es[index].wage / 30 / 24 * h;
664         system("cls") ;
665             cout << "          **********员工管理系统**********" << endl;
666             cout <<"          *                              *"<< endl;
667             cout <<"          *                              *"<< endl; 
668             cout <<"          *                              *"<< endl; 
669             cout <<"          *                              *"<< endl;
670             cout <<"          *                              *"<< endl; 
671             cout <<"          *                              *"<< endl; 
672             cout <<"          *           登记成功!          *"<< endl;
673             cout <<"          *                              *"<< endl;  
674             cout <<"          *                              *"<< endl; 
675             cout <<"          *                              *"<< endl; 
676             cout <<"          *                              *"<< endl; 
677             cout <<"          *                              *"<< endl; 
678             cout <<"          *                              *"<< endl; 
679             cout <<"          *                              *"<< endl; 
680             cout <<"          ********************************" << endl;
681             cout <<endl
682                  <<endl;
683             system("pause");
684     }
685 
686     void regis_late() //迟到 
687     {
688         system("cls") ;
689         string no;
690         int index;
691         int h;
692         system("cls") ;
693         cout << "          **********员工管理系统**********" << endl;
694         cout <<"          *                              *"<< endl; 
695         cout <<"          *                              *"<< endl; 
696         cout <<"          *                              *"<< endl; 
697         cout <<"          *                              *"<< endl; 
698         cout <<"          *                              *"<< endl; 
699         cout <<"          *                              *"<< endl;
700         cout <<"          * 请输入您想登记的员工的工号: *"<< endl;
701         cout <<"          *                              *"<< endl; 
702         cout <<"          *                              *"<< endl; 
703         cout <<"          *                              *"<< endl; 
704         cout <<"          *                              *"<< endl; 
705         cout <<"          *                              *"<< endl; 
706         cout <<"          *                              *"<< endl;  
707         cout <<"          *                              *"<< endl; 
708         cout << "          ********************************" << endl;
709         cin >> no;
710         index = find_by_no(no);
711         if (index == -1) {
712             system("cls") ;
713             cout << "          **********员工管理系统**********" << endl;
714             cout <<"          *                              *"<< endl;
715             cout <<"          *                              *"<< endl; 
716             cout <<"          *                              *"<< endl; 
717             cout <<"          *                              *"<< endl;
718             cout <<"          *                              *"<< endl; 
719             cout <<"          *                              *"<< endl;  
720             cout <<"          *    您要查找的员工不存在!    *" << endl;
721             cout <<"          *                              *"<< endl;  
722             cout <<"          *                              *"<< endl; 
723             cout <<"          *                              *"<< endl; 
724             cout <<"          *                              *"<< endl; 
725             cout <<"          *                              *"<< endl; 
726             cout <<"          *                              *"<< endl; 
727             cout <<"          *                              *"<< endl; 
728             cout <<"          ********************************" << endl;
729             cout <<endl
730                  <<endl;
731             system("pause");
732             return;
733         }
734             system("cls") ;
735             cout << "          **********员工管理系统**********" << endl;
736             cout <<"          *                              *"<< endl;
737             cout <<"          *                              *"<< endl; 
738             cout <<"          *                              *"<< endl; 
739             cout <<"          *                              *"<< endl;
740             cout <<"          *                              *"<< endl; 
741             cout <<"          *                              *"<< endl; 
742             cout <<"          *  请输入该员工迟到了多少小时:*"<< endl;
743             cout <<"          *                              *"<< endl;  
744             cout <<"          *                              *"<< endl; 
745             cout <<"          *                              *"<< endl; 
746             cout <<"          *                              *"<< endl; 
747             cout <<"          *                              *"<< endl; 
748             cout <<"          *                              *"<< endl; 
749             cout <<"          *                              *"<< endl; 
750             cout <<"          ********************************" << endl;
751         cin >> h;
752         es[index].deduct += es[index].wage / 30 / 24 * h;
753             system("cls") ;
754             cout << "          **********员工管理系统**********" << endl;
755             cout <<"          *                              *"<< endl;
756             cout <<"          *                              *"<< endl; 
757             cout <<"          *                              *"<< endl; 
758             cout <<"          *                              *"<< endl;
759             cout <<"          *                              *"<< endl; 
760             cout <<"          *                              *"<< endl; 
761             cout <<"          *           登记成功!          *"<< endl;
762             cout <<"          *                              *"<< endl;  
763             cout <<"          *                              *"<< endl; 
764             cout <<"          *                              *"<< endl; 
765             cout <<"          *                              *"<< endl; 
766             cout <<"          *                              *"<< endl; 
767             cout <<"          *                              *"<< endl; 
768             cout <<"          *                              *"<< endl; 
769             cout <<"          ********************************" << endl;
770             cout <<endl
771                  <<endl;
772             system("pause");
773             
774     }
775 
776     void menu() //菜单 
777     {
778         int choose;
779         load();
780         while (1) {
781             system("cls") ;
782             cout << "          **********员工管理系统**********" << endl;
783             cout <<"          *                              *"<< endl; 
784             cout << "          *      1.查看所有员工          *" << endl;
785             cout << "          *      2.添加员工              *" << endl;
786             cout << "          *      3.编辑员工              *" << endl;
787             cout << "          *      4.删除员工              *" << endl;
788             cout << "          *      5.查询员工              *" << endl;
789             cout << "          *      6.统计员工              *" << endl;
790             cout << "          *      7.登记迟到              *" << endl;
791             cout << "          *      8.登记加班              *" << endl;
792             cout << "          *      9.退出                  *" << endl;
793             cout <<"          *                              *"<< endl; 
794             cout <<"          *                              *"<< endl; 
795             cout <<"          *                              *"<< endl; 
796             cout <<"          *                              *"<< endl; 
797             cout << "          ********************************" << endl;
798             cout<<endl
799                 <<endl;
800             cout << "          请选择你需要办理的业务:" << endl;
801             cin >> choose;
802             if (choose == 1) 
803             {
804                 system("cls") ;
805                 cout << "******************************员工管理系统******************************" << endl;
806                 cout <<"*                                                                      *"<< endl; 
807                 print_all();
808                 cout <<"*                                                                      *"<< endl; 
809                 cout <<"*                                                                      *"<< endl; 
810                 cout <<"*                                                                      *"<< endl; 
811                 cout <<"*                                                                      *"<< endl; 
812                 cout <<"*                                                                      *"<< endl; 
813                 cout <<"*                                                                      *"<< endl; 
814                 cout <<"*                                                                      *"<< endl; 
815                 cout << "************************************************************************" << endl;
816                 cout<<endl
817                     <<endl;
818                 system("pause");
819             } 
820             else if (choose == 2) {
821                 add();
822             } 
823             else if (choose == 3) {
824                 update();
825             } 
826             else if (choose == 4) {
827                 del();
828             } 
829             else if (choose == 5) {
830                 select();
831             } 
832             else if (choose == 6) {
833                 analysis();
834             } 
835             else if (choose == 7) {
836                 regis_late();
837             } 
838             else if (choose == 8) {
839                 regis_overtime();
840             } 
841             else if (choose == 9) {
842                 break;
843             }
844             save();
845         }
846     }
847 };
848 
849 int main() {
850     Manage m;
851     m.menu();
852 }
View Code

改后效果

 

 

 

posted @ 2021-03-15 17:39  松贤  阅读(448)  评论(0)    收藏  举报