国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - C/C++ - C++實現KFC點餐系統

C++實現KFC點餐系統

2021-09-17 10:35Cynthia! C/C++

這篇文章主要為大家詳細介紹了C++實現KFC點餐系統,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C++實現KFC點餐系統的具體代碼,供大家參考,具體內容如下

一、題目名稱:模擬肯德基收銀系統
二、題目內容:

同學們應該都去麥當勞或肯德基吃過快餐吧?請同學們參考肯德基官網的信息模擬肯德基快餐店的收銀系統,合理使用C++或Java或Python結合設計模式(2種以上)至少實現系統的以下功能:

1.正常餐品結算和找零。
2.基本套餐結算和找零。
3.使用優惠劵購買餐品結算和找零。
4.可在一定時間段參與店內活動(自行設計或參考官網信息)。
5.模擬打印小票的功能(寫到文件中)。

基本要求:

1.程序設計風格良好,控制臺界面友好,最多兩人一組完成任務。
2.實現功能測試代碼,確保程序的健壯性。
3.畫出使用的設計模式圖。

提高要求:

1.實現可視化界面(使用MFC)。
2.實現會員儲值卡功能,完成儲值卡消費。
實現當天營業額和餐品銷量計算和統計,用數據庫記錄。

三、算法設計:

C++實現KFC點餐系統

四、代碼

1.點餐系統代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
 
class Food
{
protected:
 string name;
 double price;
 int num;
public:
 virtual double get_sum()
 {
 double sum = price * num;
 return sum;
 }
 virtual void set_name(string name)
 {
 this->name = name;
 }
 virtual string get_name()
 {
 return name;
 }
 virtual void set_price(double price)
 {
 this->price = price;
 }
 virtual double get_price()
 {
 return price;
 }
 virtual void set_num(int num)
 {
 this->num = num;
 }
 virtual int get_num()
 {
 return num;
 }
};
 
class Hamburger :public Food
{
public:
 virtual double get_sum()
 {
 double sum = price * num;
 return sum;
 }
};
 
class Snack :public Food
{
public:
 virtual double get_sum()
 {
 double sum = price * num;
 return sum;
 }
};
 
class Drink :public Food
{
public:
 virtual double get_sum()
 {
 double sum = price * num;
 return sum;
 }
};
 
class Set :public Food
{
public:
 virtual double get_sum()
 {
 double sum = price * num;
 return sum;
 }
};
 
class Factory
{
public:
 virtual Food* food() = 0;
};
 
class Factory_Hamburger :public Factory
{
public:
 Food* food()
 {
 return new Hamburger;
 }
};
 
class Factory_Snack :public Factory
{
public:
 Food* food()
 {
 return new Snack;
 }
};
 
class Factory_Drink :public Factory
{
public:
 Food* food()
 {
 return new Drink;
 }
};
 
class Factory_Set :public Factory
{
public:
 Food* food()
 {
 return new Set;
 }
};
 
class xiaopiao
{
 public:
 virtual void output() = 0;
} ;
 
class H1 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "巨無霸--" << num << "份" <<endl;
 outfile << "巨無霸--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class H2 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "雙層吉士漢堡--" << num << "份" <<endl;
 outfile << "雙層吉士漢堡--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class H3 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "麥辣雞腿漢堡--" << num << "份" <<endl;
 outfile << "麥辣雞腿漢堡--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class S1 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "大薯條--" << num << "份" <<endl;
 outfile << "大薯條--" << num << "份" << endl;
 outfile.close();
 }
 
  }
protected:
 int num;
};
 
class S2 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "麥樂雞--" << num << "份" <<endl;
 outfile << "麥樂雞--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class D1 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "可口可樂--" << num << "份" <<endl;
 outfile << "可口可樂--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class D2 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "七喜--" << num << "份" <<endl;
 outfile << "七喜--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class D3 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "橙汁--" << num << "份" <<endl;
 outfile << "橙汁--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class SET1 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
  ofstream outfile("receipt.dat", ios::out);
 cout << "巨無霸超值套餐--" << num << "份" <<endl;
 outfile << "巨無霸超值套餐--" << num << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
 
class SET2 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   
 if(0 != num)
 {
 ofstream outfile("receipt.dat", ios::out);
 cout << "雙層吉士漢堡超值套餐--" << 1 << "份" <<endl;
 outfile << "雙層吉士漢堡超值套餐--" << 1 << "份" << endl;
 outfile.close();
 }
  }
protected:
 int num;
};
//運用策略模式簡化
class Context
{
public:
  Context(xiaopiao *p) : pStrategy(p)
  {
  }
  void Interface()
  {
   pStrategy->output();
  }
private:
  xiaopiao *pStrategy;
};
 
 
class collect
{
private:
 
public:
 void main_menu()
 {
 cout << "---------------------" << endl;
 cout << "歡迎進入肯德基點餐系統!" << endl;
 cout << "---------------------" << endl;
 cout << "請問你選擇單點(1)或者套餐(2):" << endl;
 }
 void single_menu()
 {
 cout << "---------------------" << endl;
 cout << "請選擇您要點的產品: " << endl;
 cout << "主食:  " << endl;
 cout << " 1.巨無霸  --17元 " << endl;
 cout << " 2.雙層吉士漢堡--15元 " << endl;
 cout << " 3.麥辣雞腿漢堡--15元 " << endl;
 cout << "配餐:  " << endl;
 cout << " 4.大薯條  --11元 " << endl;
 cout << " 5.麥樂雞  --9元 " << endl;
 cout << "飲料:  " << endl;
 cout << " 6.可口可樂 --7元 " << endl;
 cout << " 7.七喜  --7元 " << endl;
 cout << " 8.橙汁  --10元 " << endl;
 cout << "若點餐結束,請輸入0以結束點餐!" << endl;
 }
 void set_menu()
 {
 cout << "---------------------" << endl;
 cout << "請選擇您要點的套餐: " << endl;
 cout << " 1.巨無霸超值套餐 --25元" << endl;
 cout << " (包含巨無霸一份、大薯條一份、可口可樂一份)" << endl;
 cout << " 2.雙層吉士漢堡超值套餐 --23元" << endl;
 cout << " (包含雙層吉士漢堡一份、大薯條一份、可口可樂一份)" << endl;
 cout << "若點餐結束,請輸入0以結束點餐!" << endl;
 }
 void menu()
 {
 main_menu();
 int choose;
 int hamburger[3], snack[2], drink[3],set[2];
 for (int i = 0; i < 3; i++) { hamburger[i] = 0; drink[i] = 0; }
 for (int i = 0; i < 2; i++) { snack[i] = 0; set[i] = 0; }
 cin >> choose;
 if (1 == choose)
 {
 single_menu();
 int ch,flag=1;
 while(flag)
 {
 cout << "請輸入對應商品的序號:" ;
 cin >> ch;
 switch (ch)
 {
 case(0):
 {
  flag = 0;
  break;
 }
 case(1):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  hamburger[0] = number;
  break;
 }
 case(2):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  hamburger[1] = number;
  break;
 }
 case(3):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  hamburger[2] = number;
  break;
 }
 case(4):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  snack[0] = number;
  break;
 }
 case(5):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  snack[1] = number;
  break;
 }
 case(6):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  drink[0] = number;
  break;
 }
 case(7):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  drink[1] = number;
  break;
 }
 case(8):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  drink[2] = number;
  break;
 }
 default:
 {
  cout << "請輸入正確的序號!" << endl;
  break;
 }
 }
 }
 }
 else if (2 == choose)
 {
 set_menu();
 int ch, flag = 1;
 while (flag)
 {
 cout << "請輸入對應商品的序號:";
 cin >> ch;
 switch (ch)
 {
 case(0):
 {
  flag = 0;
  break;
 }
 case(1):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  set[0] = number;
  break;
 }
 case(2):
 {
  cout << "請輸入需要幾份?:";
  int number;
  cin >> number;
  set[1] = number;
  break;
 }
 
 default:
 {
  cout << "請輸入正確的序號!" << endl;
  break;
 }
 }
 }
 }
 //生成漢堡工廠類
 Factory_Hamburger* fac_h = new Factory_Hamburger();
 //生成具體的漢堡類
 Food* hamburger1 = fac_h->food();
 Food* hamburger2 = fac_h->food();
 Food* hamburger3 = fac_h->food();
 //實例化各個漢堡
 //巨無霸
 hamburger1->set_name("巨無霸");
 hamburger1->set_price(17);
 hamburger1->set_num(hamburger[0]);
 //雙層吉士漢堡
 hamburger2->set_name("雙層吉士漢堡");
 hamburger2->set_price(15);
 hamburger2->set_num(hamburger[1]);
 //麥辣雞腿漢堡
 hamburger3->set_name("麥辣雞腿漢堡");
 hamburger3->set_price(15);
 hamburger3->set_num(hamburger[2]);
 
 //生成小吃工廠類
 Factory_Snack* fac_s = new Factory_Snack();
 //生成具體的小吃類
 Food* snack1 = fac_s->food();
 Food* snack2 = fac_s->food();
 //實例化各個小吃
 //大薯條
 snack1->set_name("大薯條");
 snack1->set_price(11);
 snack1->set_num(snack[0]);
 //麥樂雞
 snack2->set_name("麥樂雞");
 snack2->set_price(9);
 snack2->set_num(snack[1]);
 
 //生成飲料工廠類
 Factory_Drink* fac_d = new Factory_Drink();
 //生成具體的飲料類
 Food* drink1 = fac_d->food();
 Food* drink2 = fac_d->food();
 Food* drink3 = fac_d->food();
 //實例化各個飲料
 //可口可樂
 drink1->set_name("可口可樂");
 drink1->set_price(7);
 drink1->set_num(drink[0]);
 //七喜
 drink2->set_name("七喜");
 drink2->set_price(7);
 drink2->set_num(drink[1]);
 //橙汁
 drink3->set_name("橙汁");
 drink3->set_price(7);
 drink3->set_num(drink[2]);
 
 //生成套餐工廠類
 Factory_Set* fac_se = new Factory_Set();
 //生成具體的套餐類
 Food* set1 = fac_se->food();
 Food* set2 = fac_se->food();
 //實例化各個套餐
 //巨無霸超值套餐
 set1->set_name("巨無霸超值套餐");
 set1->set_price(25);
 set1->set_num(set[0]);
 //雙層吉士漢堡超值套餐
 set2->set_name("雙層吉士漢堡超值套餐");
 set2->set_price(23);
 set2->set_num(set[1]);
 
 //找零部分
 cout << "---------------------" << endl;
 double sum = 0;
 sum = sum + hamburger1->get_sum();
 sum = sum + hamburger2->get_sum();
 sum = sum + hamburger3->get_sum();
 sum = sum + snack1->get_sum();
 sum = sum + snack2->get_sum();
 sum = sum + drink1->get_sum();
 sum = sum + drink2->get_sum();
 sum = sum + drink3->get_sum();
 sum = sum + set1->get_sum();
 sum = sum + set2->get_sum();
 cout << "您共計消費:" << sum << endl;
 cout << "請問您是否使用優惠券?(輸入0已接受)";
 int ch;
 cin >> ch;
 int yhq=0;
 if (0 == ch)
 {
 cout << "您擁有如下優惠券:" << endl;
 cout << "-1.滿50減5" << endl;
 cout << "-2.滿100減15" << endl;
 cout << "-3.滿200減40" << endl;
 cout << "每次消費僅能使用一張優惠券,請選擇使用的優惠券" << endl;
 int flag = 1;
 while (flag)
 {
 int ch;
 cin >> ch;
 if (ch == 1)
 {
  if (sum > 50) { sum -= 5; cout << "使用消費券成功!"; }
  else { cout << "您的消費金額還不能使用優惠券!" << endl; }
  flag = 0;
 }
 if (ch == 2)
 {
  if (sum > 100) { sum -= 15; cout << "使用消費券成功!";}
  else { cout << "您的消費金額還不能使用優惠券!" << endl; }
  flag = 0;
 }
 if (ch == 3)
 {
  if (sum > 200) { sum -= 40; cout << "使用消費券成功!";}
  else { cout << "您的消費金額還不能使用優惠券!" << endl; }
  flag = 0;
 }
 if (ch == 0)
 {
  cout << "不使用優惠券" << endl;
  flag = 0;
 }
 }
 }
 cout << "請問您支付多少:";
 double pay;
 cin >> pay;
 double payback = pay - sum;
 while (0 > payback)
 {
 cout << "您好,您的錢不夠本次消費(微笑.jpg),請重給,謝謝您哦~";
 cin >> pay; 
 payback = pay - sum;
 }
 cout << "共計收您" << pay << "元。" << endl;
 cout << "找零為:" << payback << "元" << endl;
 int cho;
 cout << "---------------------" << endl;
 cout << "請選擇是否打印小票:(輸入0以打印)" << endl;
 cin >> cho;
 if (0 == cho)
 {
 //打印小票部分
 
 /*
 ofstream outfile("receipt.dat", ios::out);
 cout << "---------------------" << endl;
 outfile << "---------------------" << endl;
 cout << "歡迎來到肯德基歡樂餐廳!" << endl;
 outfile << "歡迎來到肯德基歡樂餐廳!" << endl;
 cout << "您共計點餐:" << endl;
 outfile << "您共計點餐:" << endl;
 cout << endl;
 outfile << endl;
 if (0 != hamburger[0]) { cout << "巨無霸--" << hamburger[0] << "份" <<endl;outfile << "巨無霸--" << hamburger[0] << "份" << endl; }
 if (0 != hamburger[1]) { cout << "雙層吉士漢堡--" << hamburger[1] << "份" << endl;outfile << "雙層吉士漢堡--" << hamburger[1] << "份" << endl; }
 if (0 != hamburger[2]) { cout << "麥辣雞腿漢堡--" << hamburger[2] << "份" << endl; outfile << "麥辣雞腿漢堡--" << hamburger[2] << "份" << endl;}
 if (0 != snack[0]) { cout << "大薯條--" << snack[0] << "份" << endl;outfile << "大薯條--" << snack[0] << "份" << endl; }
 if (0 != snack[1]) { cout << "麥樂雞--" << snack[1] << "份" << endl; outfile << "麥樂雞--" << snack[1] << "份" << endl;}
 if (0 != drink[0]) { cout << "可口可樂--" << drink[0] << "份" << endl;outfile << "可口可樂--" << drink[0] << "份" << endl; }
 if (0 != drink[1]) { cout << "七喜--" << drink[1] << "份" << endl; outfile << "七喜--" << drink[1] << "份" << endl;}
 if (0 != drink[2]) { cout << "橙汁--" << drink[2] << "份" << endl;outfile << "橙汁--" << drink[2] << "份" << endl; }
 if (0 != set[0]) { cout << "巨無霸超值套餐--" << set[0] << "份" << endl;outfile << "巨無霸超值套餐--" << set[0] << "份" << endl; }
 if (0 != set[1]) { cout << "雙層吉士漢堡超值套餐--" << set[1] << "份" << endl; outfile << "雙層吉士漢堡超值套餐--" << set[1] << "份" << endl;}
 cout << "---------------------" << endl;
 outfile << "---------------------" << endl;
 cout << "共計收您" << pay << "元。" << endl;
 outfile << "共計收您" << pay << "元。" << endl;
 cout << "找零為:" << payback << "元" << endl;
 outfile << "找零為:" << payback << "元" << endl;
 */
 ofstream outfile("receipt.dat", ios::out);
 cout << "---------------------" << endl;
 outfile << "---------------------" << endl;
 cout << "歡迎來到肯德基歡樂餐廳!" << endl;
 outfile << "歡迎來到肯德基歡樂餐廳!" << endl;
 cout << "您共計點餐:" << endl;
 outfile << "您共計點餐:" << endl;
 cout << endl;
 outfile << endl;
 H1 *h1 = new H1;
 h1->get_num(hamburger[0]);
 H2 *h2 = new H2;
 h2->get_num(hamburger[1]);
 H3 *h3 = new H3;
 h3->get_num(hamburger[2]);
 S1 *s1 = new S1;
 s1->get_num(snack[0]);
 S2 *s2 = new S2;
 s2->get_num(snack[1]);
 D1 *d1 = new D1;
 d1->get_num(drink[0]);
 D2 *d2 = new D2;
 d2->get_num(drink[1]);
 D3 *d3 = new D3;
 d3->get_num(drink[2]);
 SET1 *set1 = new SET1;
 set1->get_num(set[0]);
 SET2 *set2 = new SET2;
 set2->get_num(set[1]);
 Context *ph1 = new Context(h1);
 Context *ph2 = new Context(h2);
 Context *ph3 = new Context(h3);
 Context *ps1 = new Context(s1);
 Context *ps2 = new Context(s1);
 Context *pd1 = new Context(d1);
 Context *pd2 = new Context(d2);
 Context *pd3 = new Context(d3);
 Context *pset1 = new Context(set1);
 Context *pset2 = new Context(set2);
 ph1->Interface();
 ph2->Interface();
 ph3->Interface();
 ps1->Interface();
 ps2->Interface();
 pd1->Interface();
 pd2->Interface();
 pd3->Interface();
 pset1->Interface();
 pset2->Interface();
 cout << endl;
 outfile << endl;
 cout << "---------------------" << endl;
 outfile << "---------------------" << endl;
 cout << "---------------------" << endl;
 outfile << "---------------------" << endl;
 cout << endl;
 outfile << endl;
 cout << "共計收您" << pay << "元。" << endl;
 outfile << "共計收您" << pay << "元。" << endl;
 cout << "找零為:" << payback << "元" << endl;
 outfile << "找零為:" << payback << "元" << endl;
 outfile.close();
 //運用策略模式簡化上列大量if語句
 }
 
 }
};
 
 
int main()
{
 collect c;
 c.menu();
 
}

2.測試代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <iostream>
#include <fstream>
using namespace std;
 
class xiaopiao
{
 public:
 virtual void output() = 0;
} ;
 
class H1 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "巨無霸--" << num << "份" <<endl;
 outfile << "巨無霸--" << num << "份" << endl;
 outfile.close();
  }
protected:
 int num;
};
 
class H2 : public xiaopiao
{
public:
 void get_num(int n)
 {
 num = n;
 }
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "雙層吉士漢堡--" << num << "份" <<endl;
 outfile << "雙層吉士漢堡--" << num << "份" << endl;
 outfile.close();
  }
  protected:
 int num;
};
 
class H3 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "麥辣雞腿漢堡--" << 1 << "份" <<endl;
 outfile << "麥辣雞腿漢堡--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class S1 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "大薯條--" << 1 << "份" <<endl;
 outfile << "大薯條--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class S2 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "麥樂雞--" << 1 << "份" <<endl;
 outfile << "麥樂雞--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class D1 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "可口可樂--" << 1 << "份" <<endl;
 outfile << "可口可樂--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class D2 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "七喜--" << 1 << "份" <<endl;
 outfile << "七喜--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class D3 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "橙汁--" << 1 << "份" <<endl;
 outfile << "橙汁--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class SET1 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "巨無霸超值套餐--" << 1 << "份" <<endl;
 outfile << "巨無霸超值套餐--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class SET2 : public xiaopiao
{
public:
  void output()
  {
   ofstream outfile("receipt.dat", ios::out);
 cout << "雙層吉士漢堡超值套餐--" << 1 << "份" <<endl;
 outfile << "雙層吉士漢堡超值套餐--" << 1 << "份" << endl;
 outfile.close();
  }
};
 
class Context
{
public:
  Context(xiaopiao *p) : pStrategy(p)
  {
  }
  void Interface()
  {
   pStrategy->output();
  }
private:
  xiaopiao *pStrategy;
};
 
int main()
{
 ofstream outfile("receipt.dat", ios::out);
 cout << "---------------------" << endl;
 outfile << "---------------------" << endl;
 cout << "歡迎來到麥當勞歡樂餐廳!" << endl;
 outfile << "歡迎來到麥當勞歡樂餐廳!" << endl;
 cout << "您共計點餐:" << endl;
 outfile << "您共計點餐:" << endl;
 cout << endl;
 outfile << endl;
 H1 *h1 = new H1;
 h1->get_num(2);
 H2 *h2 = new H2;
 h2->get_num(3);
 H3 *h3 = new H3;
 S1 *s1 = new S1;
 S2 *s2 = new S2;
 D1 *d1 = new D1;
 D2 *d2 = new D2;
 D3 *d3 = new D3;
 SET1 *set1 = new SET1;
 SET2 *set2 = new SET2;
 Context *ph1 = new Context(h1);
 Context *ph2 = new Context(h2);
 Context *ph3 = new Context(h3);
 Context *ps1 = new Context(s1);
 Context *ps2 = new Context(s1);
 Context *pd1 = new Context(d1);
 Context *pd2 = new Context(d2);
 Context *pd3 = new Context(d3);
 Context *pset1 = new Context(set1);
 Context *pset2 = new Context(set2);
 ph1->Interface();
 ph2->Interface();
 ph3->Interface();
 ps1->Interface();
 ps2->Interface();
 pd1->Interface();
 pd2->Interface();
 pd3->Interface();
 pset1->Interface();
 pset2->Interface();
 if (h1) delete h1;
 if (h2) delete h2;
 if (h3) delete h3;
 if (s1) delete s1;
 if (s2) delete s2;
 if (d1) delete h1;
 if (d2) delete d2;
 if (d3) delete d3;
 if (set1) delete set1;
 if (set2) delete set2;
}

五、結果展示

C++實現KFC點餐系統

六、總結

1.本次作業為KFC點餐系統,剛開始的想法是用Java做,但是在看了許多資料結合自己的情況,最終采用C++來寫程序,C++確實較Java熟悉了很多。
2.這次只做了基本要求,沒有做提高要求,我會在后面的學習中,結合可視化界面和數據庫連接,將點餐系統完善。
3.主要運用到設計模式中的策略模式和工廠模式,其中工廠模式負責生產餐廳中的各種食物的對象,策略模式負責在生成小票時避免出現冗雜的if語句。
4.從RPG游戲和KFC點餐系統兩次的作業來看,這兩次的代碼認為量來說都是比較大的,對于其中的一些函數功能的使用,還有設計模式的理解并且不到位。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/weixin_44622101/article/details/106486026

延伸 · 閱讀

精彩推薦
  • C/C++詳解c語言中的 strcpy和strncpy字符串函數使用

    詳解c語言中的 strcpy和strncpy字符串函數使用

    strcpy 和strcnpy函數是字符串復制函數。接下來通過本文給大家介紹c語言中的strcpy和strncpy字符串函數使用,感興趣的朋友跟隨小編要求看看吧...

    spring-go5642021-07-02
  • C/C++C/C++經典實例之模擬計算器示例代碼

    C/C++經典實例之模擬計算器示例代碼

    最近在看到的一個需求,本以為比較簡單,但花了不少時間,所以下面這篇文章主要給大家介紹了關于C/C++經典實例之模擬計算器的相關資料,文中通過示...

    jia150610152021-06-07
  • C/C++深入理解goto語句的替代實現方式分析

    深入理解goto語句的替代實現方式分析

    本篇文章是對goto語句的替代實現方式進行了詳細的分析介紹,需要的朋友參考下...

    C語言教程網7342020-12-03
  • C/C++C語言實現電腦關機程序

    C語言實現電腦關機程序

    這篇文章主要為大家詳細介紹了C語言實現電腦關機程序,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下...

    xiaocaidayong8482021-08-20
  • C/C++C++之重載 重定義與重寫用法詳解

    C++之重載 重定義與重寫用法詳解

    這篇文章主要介紹了C++之重載 重定義與重寫用法詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下...

    青山的青6062022-01-04
  • C/C++C語言中炫酷的文件操作實例詳解

    C語言中炫酷的文件操作實例詳解

    內存中的數據都是暫時的,當程序結束時,它們都將丟失,為了永久性的保存大量的數據,C語言提供了對文件的操作,這篇文章主要給大家介紹了關于C語言中文件...

    針眼_6702022-01-24
  • C/C++c++ 單線程實現同時監聽多個端口

    c++ 單線程實現同時監聽多個端口

    這篇文章主要介紹了c++ 單線程實現同時監聽多個端口的方法,幫助大家更好的理解和學習使用c++,感興趣的朋友可以了解下...

    源之緣11542021-10-27
  • C/C++學習C++編程的必備軟件

    學習C++編程的必備軟件

    本文給大家分享的是作者在學習使用C++進行編程的時候所用到的一些常用的軟件,這里推薦給大家...

    謝恩銘10102021-05-08
主站蜘蛛池模板: 亚洲视频观看 | 中文字幕在线视频观看 | 国内自拍视频在线观看 | 日本高清视频在线播放 | 国产精品成人国产乱一区 | 一区亚洲| 中文字幕久久网 | 欧美日韩一区二区在线观看 | 欧美综合在线观看 | 五月婷婷色网 | 日韩精品久久 | 成人羞羞视频在线看网址 | 久久9色 | 亚洲激情在线视频 | 久久久久无码国产精品一区 | 国产精品久久久久久久久免费桃花 | 自拍偷拍五月天 | 久久精品一级 | 国产成人精品一区二区三区四区 | 91视频导航 | 欧美激情精品久久久久久变态 | 亚洲电影在线 | 亚洲精品专区 | 国产一区二区免费视频 | 亚洲热av| 91精品国产综合久久精品 | 懂色一区| 国产精品久久久爽爽爽麻豆色哟哟 | 日韩精品99久久久久中文字幕 | 久久黄网| 亚洲综合av一区 | 日韩国产在线观看 | 91精品国产乱码久久久久久 | 中文字幕在线永久在线视频 | 日韩欧美在线一区 | 国产乱码精品一区二区三区中文 | 在线91 | 亚洲精品成人悠悠色影视 | 国产成人精品一区二区三区四区 | 红桃视频一区二区三区免费 | 日本中文字幕在线视频 |