软件设计 2017-05-17
好久没更新博客了,最近一直在忙,花了一天时间做出这个简陋版的课程设计,
为了储存,也为了更新,所以于今天更新我的博客。
我选的课程设计题目如下:
某某公司的设备管理系统
功能及要求描述:
(1)公司主要包括三类设备需要管理:电视机、DVD、带DVD的电视机;
(2)设备主要包含的信息:编号、类别、名称、价格、库存数量;
(3)添加各类设备信息;
(4)删除设备信息;
(5)查找设备信息;
(6)修改设备信息;
(7)输出所有设备信息;
(8)将信息保存到文件。
由于我目前水平有限,并没有使用太多c++的东西,正如老师所说,只是把printf scanf换成了cout
cin之类,但尽管如此,我仍使用了类与对象,继承,文件这几个东西,对于这次,有个bug我没时间
调了,就是每次运行程序的时候,储存的后台信息会自动清除,并没有读取上回留下来的产品信息。
如果读者有兴趣的话,可以帮我debug,也算是留给大家的一个小小的“作业”。哈哈。
话不多说,贴上代码,还有一点,我比较调皮,加了两个图形,故代码部分你们可能不知道是什么,
你们可以运行看看这两个小彩蛋。。。。


1 # include<iostream>
2 # include<fstream>
3 # include<cstring>
4 # include<cstdlib>//system()
5 # define maxnum 50 //后台定义最大设备数量为50
6 using namespace std;
7
8 //类的声明
9 class menu;
10 class Product;
11 class graphical;
12
13 class graphical//图形类
14 {
15 public:
16 void in();//进入系统图形
17 void out();//退出系统图形
18 };
19 void graphical::out()
20 {
21 int a[15][37]= {0};
22 int i,j;
23 a[0][18]=1;
24 for(j=17; j<20; j++) a[1][j]=1;
25 for(j=16; j<21; j++) a[2][j]=1;
26 for(j=15; j<22; j++) a[3][j]=1;
27 for(j=14; j<23; j++) a[4][j]=1;
28 for(j=1; j<36; j++) a[5][j]=1;
29 for(j=4; j<33; j++) a[6][j]=1;
30 for(j=7; j<30; j++) a[7][j]=1;
31 for(j=10; j<27; j++) a[8][j]=1;
32 for(j=12; j<25; j++) a[9][j]=1;
33 for(j=11; j<26; j++) a[10][j]=1;
34 for(j=10; j<18; j++) a[11][j]=1;
35 for(j=19; j<27; j++) a[11][j]=1;
36 for(j=9; j<15; j++) a[12][j]=1;
37 for(j=22; j<28; j++) a[12][j]=1;
38 for(j=8; j<12; j++) a[13][j]=1;
39 for(j=25; j<29; j++) a[13][j]=1;
40 for(j=7; j<9; j++) a[14][j]=1;
41 for(j=28; j<30; j++) a[14][j]=1;
42 a[15][6]=1,a[15][31]=1;
43 for(i=0; i<15; i++)
44 {
45 for(j=0; j<37; j++)
46 if(a[i][j]==1)
47 cout<<"*";
48 else
49 cout<<" ";
50 cout<<endl;
51 }
52 cout<<"拜拜 欢迎下次再来玩"<<endl;
53 cout<<"系统由台湾高山族第一美男子黄广独立完成"<<endl;
54 }
55 void graphical::in()
56 {
57 cout<<"----------Dragon be here!----------"<<endl;
58 cout<<" ┏┓ ┏┓"<<endl;
59 cout<<"┏┛┻━━━┛┻┓"<<endl;
60 cout<<"┃ ┃"<<endl;
61 cout<<"┃ ■ ■┃"<<endl;
62 cout<<"┃ ┃"<<endl;
63 cout<<"┃ ┃"<<endl;
64 cout<<"┃ ◎ ┃"<<endl;
65 cout<<"┃ ┃"<<endl;
66 cout<<"┗━┓ ┏━┛"<<endl;
67 cout<<" ┃ ┃神兽保佑"<<endl;
68 cout<<" ┃ ┃代码无BUG!"<<endl;
69 cout<<" ┃ ┗━━━┓"<<endl;
70 cout<<" ┃ ┣┓"<<endl;
71 cout<<" ┃ ┏┛"<<endl;
72 cout<<" ┗┓┓┏━┳┓┏┛"<<endl;
73 cout<<" ┃┫┫ ┃┫┫"<<endl;
74 cout<<" ┗┻┛ ┗┻┛"<<endl;
75 cout<<"━━━━━━神兽出没━━━━━━"<<endl;
76 }
77
78
79 class Product //产品类
80 {
81 public:
82 int ID; //编号
83 int PRICE; //价格
84 int NUM; //库存数量
85 string TYPE; //类别 为三种 TV(电视) DVD DT(带DVD的电视)
86 string NAME; //名称 如 康佳电视机 美的电视机
87 //五个获取信息的成员函数
88 void getID(int & id)
89 {
90 ID=id;
91 }
92 void getPRICE(int & price)
93 {
94 PRICE=price;
95 }
96 void getNUM(int & num)
97 {
98 NUM=num;
99 }
100 void getTYPE(string & type)
101 {
102 TYPE=type;
103 }
104 void getNAME(string & name)
105 {
106 NAME=name;
107 }
108 void headdisplay();//显示南阳公司信息
109 void error();//显示错误信息(因为无产品)
110 };
111 void Product::headdisplay()
112 {
113 cout<<"★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★"<<endl;
114 cout<<"★★★★★★★★★★★★★★欢迎来到南阳康佳公司★★★★★★★★★★★★★★★★"<<endl;
115 cout<<"★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★"<<endl;
116 cout<<"★★★★★★★★★★ 当你看到这个界面 ★★★★★★★★★★★"<<endl;
117 cout<<"★★★★★★★★★★★★★★ 就代表你 ★★★★★★★★★★★★★★★★"<<endl;
118 cout<<"★★★★★★★★★★★★★ 已经成为一名 ★★★★★★★★★★★★★★★"<<endl;
119 cout<<"★★★★★★★★★★★★ 康佳产品搬运工 ★★★★★★★★★★★★★★"<<endl;
120 cout<<"★★★★★★★★★★★ 恭喜恭喜 ★★★★★★★★★★★★★"<<endl;
121 }
122 void Product::error()
123 {
124 cout<<"错误!!没有产品信息"<<endl;
125 cout<<"自动返回主菜单"<<endl<<endl;
126 }
127
128
129 //全局定义产品信息组
130 int count=0;
131 Product pro[maxnum];
132 //全局定义图形类对象
133 graphical b;
134
135
136 class menu: public Product//菜单类继承产品类
137 {
138 public:
139 void Display();//显示菜单信息
140 void use();//操控菜单
141 void Add();//添加
142 void Find();//查找
143 void Delete();//删除
144 void Modify();//修改
145 void display();//显示产品信息
146 void Storage();//自动储存产品信息
147 void storage();//手动储存产品信息(欺骗用户)因为每一个操作之后都会自动储存 所以无需手动
148 void Empty();//清空产品日记信息
149 };
150 void menu::Display()
151 {
152 cout<<"***欢迎使用设备管理系统***"<<endl;
153 cout<<" ***1.添加设备信息***"<<endl;
154 cout<<" ***2.查找设备信息***"<<endl;
155 cout<<" ***3.删除设备信息***"<<endl;
156 cout<<" ***4.修改设备信息***"<<endl;
157 cout<<" ***5.输出设备信息***"<<endl;
158 cout<<" ***6.储存设备信息***"<<endl;
159 cout<<" ***7.一键清空信息***"<<endl;
160 cout<<" ***0.退出管理系统***"<<endl;
161 cout<<"请选择所需要的功能:";
162 }
163 void menu::use()
164 {
165 int i;
166 while(cin>>i)
167 {
168 switch(i)
169 {
170 case 1:
171 Add();
172 system("cls");
173 Storage();//自动储存
174 Display();
175 break;
176 case 2:
177 Find();
178 Display();
179 break;
180 case 3:
181 Delete();
182 Storage();//自动储存
183 Display();
184 break;
185 case 4:
186 Modify();
187 Storage();//自动储存
188 Display();
189 break;
190 case 5:
191 display();
192 Display();
193 break;
194 case 6:
195 storage();
196 Display();
197 break;
198 case 7:
199 Empty();
200 Display();
201 break;
202 case 0:
203 Storage();//自动储存
204 b.out();
205 exit(0);
206 break;
207 default:
208 cout<<"选择错误!!请重新选择!!"<<endl;
209 cout<<"请选择所需要的功能:";
210 }
211 }
212 }
213 void menu :: Add()
214 {
215 system("cls");
216 int _id,_price,_num=1;
217 string _type,_name;
218 // 记录类别信息
219 cout<<"请选择添加的设备类别(1-3):"<<endl;
220 cout<<"1.电视机(TV) 2.DVD(DVD) 3.带DVD的电视机(DT)"<<endl;
221 int i;
222 while(cin>>i)
223 {
224 switch(i)
225 {
226 case 1:
227 _type="TV";
228 pro[count].getTYPE(_type);
229 break;
230 case 2:
231 _type="DVD";
232 pro[count].getTYPE(_type);
233 break;
234 case 3:
235 _type="DT";
236 pro[count].getTYPE(_type);
237 break;
238 default:
239 cout<<"输入有误!!请重新选择!!"<<endl;
240 }
241 if(i==1||i==2||i==3)//防止用户非法输入
242 break;
243 }
244 // 记录名称信息
245 cout<<"请输入设备名称:"<<endl;
246 cin>>_name;
247 pro[count].getNAME(_name);
248 // 记录编号信息
249 cout<<"请输入设备编号(四位数,以“1”开头,如“1000”)"<<endl;
250 cin>>_id;
251 pro[count].getID(_id);
252 //记录价格信息
253 cout<<"请输入价格(1-9999):"<<endl;
254 cin>>_price;
255 pro[count].getPRICE(_price);
256 //记录库存信息
257 pro[count].getNUM(_num);
258 count++;
259 }
260 void menu::Delete()
261 {
262 system("cls");
263 if(count==0)
264 {
265 error();//输出无产品信息
266 return ;//如果没有产品则终止删除函数
267 }
268 cout<<"欢迎使用删除功能,产品信息如下:"<<endl;
269 display();//显示产品信息
270 cout<<"请输入想删除的产品的编号:";
271 int bian,d,i;
272 while(cin>>bian)
273 {
274 for(i=0; i<count; i++)
275 {
276 if(pro[i].ID==bian)//如果编号存在
277 {
278 cout<<"请问您是否确认删除编号为"<<pro[i].ID<<"的产品?"<<endl;
279 cout<<"1.是 2.否"<<endl;
280 cin>>d;
281 if(d==1)//确认删除
282 {
283 if(i==count-1)//如果是最后一个 无需前移
284 count--;
285 else//如果不是最后一个 则后续产品前移
286 {
287 while(1)
288 {
289 pro[i].ID=pro[i+1].ID;
290 pro[i].TYPE=pro[i+1].TYPE;
291 pro[i].NAME=pro[i+1].NAME;
292 pro[i].PRICE=pro[i+1].PRICE;
293 pro[i].NUM =pro[i+1].NUM;
294 count--;
295 i++;
296 if(i==count)//前移完毕后跳出while循环
297 break;
298 }
299 }
300 cout<<"删除成功!!"<<endl;
301 return;//删除成功后 直接终止删除函数
302 }
303 else//否认删除 自动返回主菜单
304 {
305 return ;
306 }
307 }
308 }
309 if(i==count)//如果编号不存在
310 cout<<"您输入的编号有误,请重新输入"<<endl;
311 }
312 }
313 void menu::Find()
314 {
315 system("cls");
316 if(count==0)
317 {
318 error();//输出无产品信息
319 return ;//如果没有产品则终止查找函数
320 }
321 cout<<"欢迎使用查找功能,请选择查找方式:"<<endl;
322 cout<<"1.编号 2.名称 "<<endl;
323 int c;
324 string s_name;
325 int bian,i;
326 while(cin>>c)
327 {
328 if(c==1)//如果选择编号
329 {
330 cout<<"请输入编号:";
331 while(cin>>bian)
332 {
333 for(i=0; i<count; i++)
334 {
335 if(pro[i].ID==bian)//如果编号存在
336 {
337 cout<<"您所输入编号的设备的信息如下:"<<endl;
338 cout<<" "<<endl;
339 cout<<"编号:"<<pro[i].ID;
340 cout<<" 类别:"<<pro[i].TYPE;
341 cout<<" 名称:"<<pro[i].NAME;
342 cout<<" 价格:"<<pro[i].PRICE;
343 cout<<" 库存数量:"<<pro[i].NUM<<endl;
344 cout<<" "<<endl;
345 return ;
346 }
347 }
348 if(i==count)//如果编号不存在
349 {
350 cout<<"您输入的编号有误,请选择"<<endl;
351 cout<<"1.继续查找 2.结束查找"<<endl;
352 int ss;
353 while(cin>>ss)
354 {
355 if(ss==1)
356 {
357 cout<<"请输入编号:";
358 break;//跳出之后返回
359 }
360 else if(ss==2)
361 return ;//结束查找
362 else
363 cout<<"选择错误,请重新选择"<<endl;
364 }
365 }
366 }
367 }
368 if(c==2)//如果选择名称
369 {
370 cout<<"请输入名称:";
371 while(cin>>s_name)
372 {
373 for(i=0; i<count; i++)
374 {
375 if(pro[i].NAME==s_name)//如果编号存在
376 {
377 cout<<"您所输入名称的设备的信息如下:"<<endl;
378 cout<<" "<<endl;
379 cout<<"编号:"<<pro[i].ID;
380 cout<<" 类别:"<<pro[i].TYPE;
381 cout<<" 名称:"<<pro[i].NAME;
382 cout<<" 价格:"<<pro[i].PRICE;
383 cout<<" 库存数量:"<<pro[i].NUM<<endl;
384 cout<<" "<<endl;
385 return ;
386 }
387 }
388 if(i==count)//如果编号不存在
389 {
390 cout<<"您输入的名称有误,请选择"<<endl;
391 cout<<"1.继续查找 2.结束查找"<<endl;
392 int ss;
393 while(cin>>ss)
394 {
395 if(ss==1)
396 {
397 cout<<"请输入名称:";
398 break;//跳出之后返回
399 }
400 else if(ss==2)
401 return ;//终止要求
402 else
403 cout<<"选择错误,请重新选择"<<endl;
404 }
405 }
406 }
407 }
408 else
409 cout<<"选择错误,请重新选择"<<endl;
410 }
411 }
412 void menu::display()
413 {
414 if(count==0)
415 {
416 system("cls");
417 error();
418 return ;
419 }
420 else
421 {
422 int i;
423 for(i=0; i<count; i++)
424 {
425 cout<<endl<<"编号:"<<pro[i].ID;
426 cout<<" 类别:"<<pro[i].TYPE;
427 cout<<" 名称:"<<pro[i].NAME;
428 cout<<" 价格:"<<pro[i].PRICE;
429 cout<<" 库存数量:"<<pro[i].NUM<<endl;
430 cout<<" "<<endl;
431 }
432 }
433 }
434 void menu::Modify()
435 {
436 system("cls");
437 if(count==0)
438 {
439 error();
440 return ;//如果没有产品则终止查找函数
441 }
442 cout<<"欢迎使用修改功能,产品信息如下:"<<endl;
443 display();
444 cout<<"请输入想修改的产品的编号:";
445 int bian,d,i;
446 string s_name;
447 int s_price,s_num;
448 while(cin>>bian)
449 {
450 for(i=0; i<count; i++)
451 {
452 if(pro[i].ID==bian)//如果编号存在
453 {
454 cout<<"请输入想要修改的内容:"<<endl;
455 cout<<"1.名字 2.价格 3.库存数量"<<endl;
456 while(cin>>d)//输入选项 如非法输入则重新输入
457 {
458 switch(d)
459 {
460 case 1:
461 cout<<"请输入新的名字:";
462 cin>>s_name;
463 pro[i].getNAME(s_name);
464 cout<<endl<<"修改成功,自动返回主菜单"<<endl;
465 return ;
466 case 2:
467 cout<<"请输入新的价格:";
468 cin>>s_price;
469 pro[i].getPRICE(s_price);
470 cout<<endl<<"修改成功,自动返回主菜单"<<endl;
471 return ;
472 case 3:
473 cout<<"请输入新的库存数量:";
474 cin>>s_num;
475 pro[i].getNUM(s_num);
476 cout<<endl<<"修改成功,自动返回主菜单"<<endl;
477 return ;
478 }
479 cout<<"选择错误,请重新选择"<<endl;
480 }
481 }
482 }
483 if(i==count)//如果编号不存在
484 cout<<"您输入的编号有误,请重新输入"<<endl;
485 }
486 }
487 void menu::Storage()
488 {
489 ofstream ofs;
490 int i;
491 ofs.open("C:\\information.txt",ios::out|ios::trunc);
492 if(ofs)//判断是否打开成功
493 {
494 for(i=0; i<count; i++)
495 {
496 ofs<<endl<<"编号:"<<pro[i].ID;
497 ofs<<" 类别:"<<pro[i].TYPE;
498 ofs<<" 名称:"<<pro[i].NAME;
499 ofs<<" 价格:"<<pro[i].PRICE;
500 ofs<<" 库存数量:"<<pro[i].NUM<<endl;
501 ofs<<endl;
502 }
503 }
504 ofs.close();
505 }
506 void menu::storage()
507 {
508 system("cls");
509 cout<<"储存成功,信息已存在c盘的information.txt下"<<endl<<endl;
510 }
511 void menu::Empty()
512 {
513 cout<<"请问是否确认清空信息"<<endl;
514 cout<<"1.是 2.否"<<endl;
515 int d;
516 while(cin>>d)
517 {
518 if(d==1)
519 {
520 count=0;
521 cout<<"清空成功,自动返回主菜单"<<endl;
522 return ;
523 }
524 else if(d==2)
525 return ;
526 else
527 cout<<"选择错误!! 请重新选择"<<endl;
528 }
529 }
530
531
532 int main(void)
533 {
534 system("color 3E");//设置颜色
535 //定义菜单类的对象
536 menu a;
537
538 b.in();//调用图形类的进入系统图形函数
539 cout<<"请用你洁白的小手轻轻点击一下回车键"<<endl;
540 getchar();
541 system("cls");
542
543 a.headdisplay();//调用菜单类继承产品类的显示公司函数
544 a.Display();//调用菜单类的显示菜单函数
545 a.use();//使用系统
546 return 0;
547 }
View Code