C++實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、題目名稱:模擬肯德基收銀系統(tǒng)
二、題目?jī)?nèi)容:
同學(xué)們應(yīng)該都去麥當(dāng)勞或肯德基吃過(guò)快餐吧?請(qǐng)同學(xué)們參考肯德基官網(wǎng)的信息模擬肯德基快餐店的收銀系統(tǒng),合理使用C++或Java或Python結(jié)合設(shè)計(jì)模式(2種以上)至少實(shí)現(xiàn)系統(tǒng)的以下功能:
1.正常餐品結(jié)算和找零。
2.基本套餐結(jié)算和找零。
3.使用優(yōu)惠劵購(gòu)買餐品結(jié)算和找零。
4.可在一定時(shí)間段參與店內(nèi)活動(dòng)(自行設(shè)計(jì)或參考官網(wǎng)信息)。
5.模擬打印小票的功能(寫(xiě)到文件中)。
基本要求:
1.程序設(shè)計(jì)風(fēng)格良好,控制臺(tái)界面友好,最多兩人一組完成任務(wù)。
2.實(shí)現(xiàn)功能測(cè)試代碼,確保程序的健壯性。
3.畫(huà)出使用的設(shè)計(jì)模式圖。
提高要求:
1.實(shí)現(xiàn)可視化界面(使用MFC)。
2.實(shí)現(xiàn)會(huì)員儲(chǔ)值卡功能,完成儲(chǔ)值卡消費(fèi)。
實(shí)現(xiàn)當(dāng)天營(yíng)業(yè)額和餐品銷量計(jì)算和統(tǒng)計(jì),用數(shù)據(jù)庫(kù)記錄。
三、算法設(shè)計(jì):

四、代碼
1.點(diǎn)餐系統(tǒng)代碼
#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 << "巨無(wú)霸--" << num << "份" <<endl;
outfile << "巨無(wú)霸--" << 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 << "大薯?xiàng)l--" << num << "份" <<endl;
outfile << "大薯?xiàng)l--" << 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 << "麥樂(lè)雞--" << num << "份" <<endl;
outfile << "麥樂(lè)雞--" << 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 << "可口可樂(lè)--" << num << "份" <<endl;
outfile << "可口可樂(lè)--" << 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 << "巨無(wú)霸超值套餐--" << num << "份" <<endl;
outfile << "巨無(wú)霸超值套餐--" << 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;
};
//運(yùn)用策略模式簡(jiǎn)化
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 << "歡迎進(jìn)入肯德基點(diǎn)餐系統(tǒng)!" << endl;
cout << "---------------------" << endl;
cout << "請(qǐng)問(wèn)你選擇單點(diǎn)(1)或者套餐(2):" << endl;
}
void single_menu()
{
cout << "---------------------" << endl;
cout << "請(qǐng)選擇您要點(diǎn)的產(chǎn)品: " << endl;
cout << "主食: " << endl;
cout << " 1.巨無(wú)霸 --17元 " << endl;
cout << " 2.雙層吉士漢堡--15元 " << endl;
cout << " 3.麥辣雞腿漢堡--15元 " << endl;
cout << "配餐: " << endl;
cout << " 4.大薯?xiàng)l --11元 " << endl;
cout << " 5.麥樂(lè)雞 --9元 " << endl;
cout << "飲料: " << endl;
cout << " 6.可口可樂(lè) --7元 " << endl;
cout << " 7.七喜 --7元 " << endl;
cout << " 8.橙汁 --10元 " << endl;
cout << "若點(diǎn)餐結(jié)束,請(qǐng)輸入0以結(jié)束點(diǎn)餐!" << endl;
}
void set_menu()
{
cout << "---------------------" << endl;
cout << "請(qǐng)選擇您要點(diǎn)的套餐: " << endl;
cout << " 1.巨無(wú)霸超值套餐 --25元" << endl;
cout << " (包含巨無(wú)霸一份、大薯?xiàng)l一份、可口可樂(lè)一份)" << endl;
cout << " 2.雙層吉士漢堡超值套餐 --23元" << endl;
cout << " (包含雙層吉士漢堡一份、大薯?xiàng)l一份、可口可樂(lè)一份)" << endl;
cout << "若點(diǎn)餐結(jié)束,請(qǐng)輸入0以結(jié)束點(diǎn)餐!" << 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 << "請(qǐng)輸入對(duì)應(yīng)商品的序號(hào):" ;
cin >> ch;
switch (ch)
{
case(0):
{
flag = 0;
break;
}
case(1):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
hamburger[0] = number;
break;
}
case(2):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
hamburger[1] = number;
break;
}
case(3):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
hamburger[2] = number;
break;
}
case(4):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
snack[0] = number;
break;
}
case(5):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
snack[1] = number;
break;
}
case(6):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
drink[0] = number;
break;
}
case(7):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
drink[1] = number;
break;
}
case(8):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
drink[2] = number;
break;
}
default:
{
cout << "請(qǐng)輸入正確的序號(hào)!" << endl;
break;
}
}
}
}
else if (2 == choose)
{
set_menu();
int ch, flag = 1;
while (flag)
{
cout << "請(qǐng)輸入對(duì)應(yīng)商品的序號(hào):";
cin >> ch;
switch (ch)
{
case(0):
{
flag = 0;
break;
}
case(1):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
set[0] = number;
break;
}
case(2):
{
cout << "請(qǐng)輸入需要幾份?:";
int number;
cin >> number;
set[1] = number;
break;
}
default:
{
cout << "請(qǐng)輸入正確的序號(hào)!" << endl;
break;
}
}
}
}
//生成漢堡工廠類
Factory_Hamburger* fac_h = new Factory_Hamburger();
//生成具體的漢堡類
Food* hamburger1 = fac_h->food();
Food* hamburger2 = fac_h->food();
Food* hamburger3 = fac_h->food();
//實(shí)例化各個(gè)漢堡
//巨無(wú)霸
hamburger1->set_name("巨無(wú)霸");
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();
//實(shí)例化各個(gè)小吃
//大薯?xiàng)l
snack1->set_name("大薯?xiàng)l");
snack1->set_price(11);
snack1->set_num(snack[0]);
//麥樂(lè)雞
snack2->set_name("麥樂(lè)雞");
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();
//實(shí)例化各個(gè)飲料
//可口可樂(lè)
drink1->set_name("可口可樂(lè)");
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();
//實(shí)例化各個(gè)套餐
//巨無(wú)霸超值套餐
set1->set_name("巨無(wú)霸超值套餐");
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 << "您共計(jì)消費(fèi):" << sum << endl;
cout << "請(qǐng)問(wèn)您是否使用優(yōu)惠券?(輸入0已接受)";
int ch;
cin >> ch;
int yhq=0;
if (0 == ch)
{
cout << "您擁有如下優(yōu)惠券:" << endl;
cout << "-1.滿50減5" << endl;
cout << "-2.滿100減15" << endl;
cout << "-3.滿200減40" << endl;
cout << "每次消費(fèi)僅能使用一張優(yōu)惠券,請(qǐng)選擇使用的優(yōu)惠券" << endl;
int flag = 1;
while (flag)
{
int ch;
cin >> ch;
if (ch == 1)
{
if (sum > 50) { sum -= 5; cout << "使用消費(fèi)券成功!"; }
else { cout << "您的消費(fèi)金額還不能使用優(yōu)惠券!" << endl; }
flag = 0;
}
if (ch == 2)
{
if (sum > 100) { sum -= 15; cout << "使用消費(fèi)券成功!";}
else { cout << "您的消費(fèi)金額還不能使用優(yōu)惠券!" << endl; }
flag = 0;
}
if (ch == 3)
{
if (sum > 200) { sum -= 40; cout << "使用消費(fèi)券成功!";}
else { cout << "您的消費(fèi)金額還不能使用優(yōu)惠券!" << endl; }
flag = 0;
}
if (ch == 0)
{
cout << "不使用優(yōu)惠券" << endl;
flag = 0;
}
}
}
cout << "請(qǐng)問(wèn)您支付多少:";
double pay;
cin >> pay;
double payback = pay - sum;
while (0 > payback)
{
cout << "您好,您的錢不夠本次消費(fèi)(微笑.jpg),請(qǐng)重給,謝謝您哦~";
cin >> pay;
payback = pay - sum;
}
cout << "共計(jì)收您" << pay << "元。" << endl;
cout << "找零為:" << payback << "元" << endl;
int cho;
cout << "---------------------" << endl;
cout << "請(qǐng)選擇是否打印小票:(輸入0以打印)" << endl;
cin >> cho;
if (0 == cho)
{
//打印小票部分
/*
ofstream outfile("receipt.dat", ios::out);
cout << "---------------------" << endl;
outfile << "---------------------" << endl;
cout << "歡迎來(lái)到肯德基歡樂(lè)餐廳!" << endl;
outfile << "歡迎來(lái)到肯德基歡樂(lè)餐廳!" << endl;
cout << "您共計(jì)點(diǎn)餐:" << endl;
outfile << "您共計(jì)點(diǎn)餐:" << endl;
cout << endl;
outfile << endl;
if (0 != hamburger[0]) { cout << "巨無(wú)霸--" << hamburger[0] << "份" <<endl;outfile << "巨無(wú)霸--" << 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 << "大薯?xiàng)l--" << snack[0] << "份" << endl;outfile << "大薯?xiàng)l--" << snack[0] << "份" << endl; }
if (0 != snack[1]) { cout << "麥樂(lè)雞--" << snack[1] << "份" << endl; outfile << "麥樂(lè)雞--" << snack[1] << "份" << endl;}
if (0 != drink[0]) { cout << "可口可樂(lè)--" << drink[0] << "份" << endl;outfile << "可口可樂(lè)--" << 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 << "巨無(wú)霸超值套餐--" << set[0] << "份" << endl;outfile << "巨無(wú)霸超值套餐--" << set[0] << "份" << endl; }
if (0 != set[1]) { cout << "雙層吉士漢堡超值套餐--" << set[1] << "份" << endl; outfile << "雙層吉士漢堡超值套餐--" << set[1] << "份" << endl;}
cout << "---------------------" << endl;
outfile << "---------------------" << endl;
cout << "共計(jì)收您" << pay << "元。" << endl;
outfile << "共計(jì)收您" << pay << "元。" << endl;
cout << "找零為:" << payback << "元" << endl;
outfile << "找零為:" << payback << "元" << endl;
*/
ofstream outfile("receipt.dat", ios::out);
cout << "---------------------" << endl;
outfile << "---------------------" << endl;
cout << "歡迎來(lái)到肯德基歡樂(lè)餐廳!" << endl;
outfile << "歡迎來(lái)到肯德基歡樂(lè)餐廳!" << endl;
cout << "您共計(jì)點(diǎn)餐:" << endl;
outfile << "您共計(jì)點(diǎn)餐:" << 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 << "共計(jì)收您" << pay << "元。" << endl;
outfile << "共計(jì)收您" << pay << "元。" << endl;
cout << "找零為:" << payback << "元" << endl;
outfile << "找零為:" << payback << "元" << endl;
outfile.close();
//運(yùn)用策略模式簡(jiǎn)化上列大量if語(yǔ)句
}
}
};
int main()
{
collect c;
c.menu();
}
2.測(cè)試代碼
#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 << "巨無(wú)霸--" << num << "份" <<endl;
outfile << "巨無(wú)霸--" << 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 << "大薯?xiàng)l--" << 1 << "份" <<endl;
outfile << "大薯?xiàng)l--" << 1 << "份" << endl;
outfile.close();
}
};
class S2 : public xiaopiao
{
public:
void output()
{
ofstream outfile("receipt.dat", ios::out);
cout << "麥樂(lè)雞--" << 1 << "份" <<endl;
outfile << "麥樂(lè)雞--" << 1 << "份" << endl;
outfile.close();
}
};
class D1 : public xiaopiao
{
public:
void output()
{
ofstream outfile("receipt.dat", ios::out);
cout << "可口可樂(lè)--" << 1 << "份" <<endl;
outfile << "可口可樂(lè)--" << 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 << "巨無(wú)霸超值套餐--" << 1 << "份" <<endl;
outfile << "巨無(wú)霸超值套餐--" << 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 << "歡迎來(lái)到麥當(dāng)勞歡樂(lè)餐廳!" << endl;
outfile << "歡迎來(lái)到麥當(dāng)勞歡樂(lè)餐廳!" << endl;
cout << "您共計(jì)點(diǎn)餐:" << endl;
outfile << "您共計(jì)點(diǎn)餐:" << 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;
}
五、結(jié)果展示

六、總結(jié)
1.本次作業(yè)為KFC點(diǎn)餐系統(tǒng),剛開(kāi)始的想法是用Java做,但是在看了許多資料結(jié)合自己的情況,最終采用C++來(lái)寫(xiě)程序,C++確實(shí)較Java熟悉了很多。
2.這次只做了基本要求,沒(méi)有做提高要求,我會(huì)在后面的學(xué)習(xí)中,結(jié)合可視化界面和數(shù)據(jù)庫(kù)連接,將點(diǎn)餐系統(tǒng)完善。
3.主要運(yùn)用到設(shè)計(jì)模式中的策略模式和工廠模式,其中工廠模式負(fù)責(zé)生產(chǎn)餐廳中的各種食物的對(duì)象,策略模式負(fù)責(zé)在生成小票時(shí)避免出現(xiàn)冗雜的if語(yǔ)句。
4.從RPG游戲和KFC點(diǎn)餐系統(tǒng)兩次的作業(yè)來(lái)看,這兩次的代碼認(rèn)為量來(lái)說(shuō)都是比較大的,對(duì)于其中的一些函數(shù)功能的使用,還有設(shè)計(jì)模式的理解并且不到位。
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開(kāi)發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java實(shí)現(xiàn)餐廳點(diǎn)餐系統(tǒng)的實(shí)例代碼
- 基于C語(yǔ)言實(shí)現(xiàn)點(diǎn)餐系統(tǒng)
- C語(yǔ)言實(shí)現(xiàn)點(diǎn)餐系統(tǒng)
- C#實(shí)現(xiàn)一個(gè)控制臺(tái)的點(diǎn)餐系統(tǒng)
- C#實(shí)現(xiàn)在線點(diǎn)餐系統(tǒng)
- 微信小程序點(diǎn)餐系統(tǒng)開(kāi)發(fā)常見(jiàn)問(wèn)題匯總
- java實(shí)現(xiàn)可視化界面肯德基(KFC)點(diǎn)餐系統(tǒng)代碼實(shí)例
- python3實(shí)現(xiàn)點(diǎn)餐系統(tǒng)
- java實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng)
相關(guān)文章
C語(yǔ)言實(shí)現(xiàn)信號(hào)槽的項(xiàng)目實(shí)踐
信號(hào)槽是觀察者模式的一種實(shí)現(xiàn),一個(gè)信號(hào)就是一個(gè)能夠被觀察的事件,本文主要介紹了C語(yǔ)言實(shí)現(xiàn)信號(hào)槽的項(xiàng)目實(shí)踐模具有一定的參考價(jià)值,感興趣的可以了解一下2024-04-04
C++中declspec(dllexport)和declspec(dllimport)?的用法介紹
這篇文章介紹了C++中declspec(dllexport)和declspec(dllimport)?的用法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
C++ 壓縮文件及文件夾方法 使用zlib開(kāi)源庫(kù)
下面小編就為大家分享一篇C++ 壓縮文件及文件夾方法 使用zlib開(kāi)源庫(kù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
C++?STL實(shí)現(xiàn)非變易查找算法的示例代碼
C++?STL?中的非變易算法(Non-modifying?Algorithms)是指那些不會(huì)修改容器內(nèi)容的算法,是C++提供的一組模板函數(shù),下面我們就來(lái)看看這一算法的應(yīng)用吧2023-08-08
C++模擬實(shí)現(xiàn)string類的實(shí)例代碼
這篇文章主要給大家介紹了C++如何模擬實(shí)現(xiàn)string類,文章通過(guò)代碼示例講解的非常詳細(xì),有完整的實(shí)現(xiàn)過(guò)程,具有一定的參考價(jià)值,需要的朋友可以參考下2023-08-08
C語(yǔ)言中((type *)0) 和(type *0)區(qū)別小結(jié)
((type *)0)?和?(type *0)?在 C 和 C++ 中有不同的含義和用途,本文主要介紹了C語(yǔ)言中((type *)0) 和(type *0)區(qū)別,具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08

