C++实现KFC点餐系统

本文实例为大家分享了C++实现KFC点餐系统的具体代码,供大家参考,具体内容如下

一、题目名称:模拟肯德基收银系统
二、题目内容:

同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++或Java或Python结合设计模式(2种以上)至少实现系统的以下功能:

1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
5.模拟打印小票的功能(写到文件中)。

基本要求:

1.程序设计风格良好,控制台界面友好,最多两人一组完成任务。
2.实现功能测试代码,确保程序的健壮性。
3.画出使用的设计模式图。

提高要求:

1.实现可视化界面(使用MFC)。
2.实现会员储值卡功能,完成储值卡消费。
实现当天营业额和餐品销量计算和统计,用数据库记录。

三、算法设计:

四、代码

1.点餐系统代码

#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.测试代码

#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;
}

五、结果展示

六、总结

1.本次作业为KFC点餐系统,刚开始的想法是用Java做,但是在看了许多资料结合自己的情况,最终采用C++来写程序,C++确实较Java熟悉了很多。
2.这次只做了基本要求,没有做提高要求,我会在后面的学习中,结合可视化界面和数据库连接,将点餐系统完善。
3.主要运用到设计模式中的策略模式和工厂模式,其中工厂模式负责生产餐厅中的各种食物的对象,策略模式负责在生成小票时避免出现冗杂的if语句。
4.从RPG游戏和KFC点餐系统两次的作业来看,这两次的代码认为量来说都是比较大的,对于其中的一些函数功能的使用,还有设计模式的理解并且不到位。

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • C#实现一个控制台的点餐系统

    本文实例为大家分享了C#点餐系统的具体代码,供大家参考,具体内容如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 控制台操作尝试 { class Program { static void Main(string[] args) { int price = 0; Console.WriteL

  • 基于C语言实现点餐系统

    这是一个很简单的点餐系统,用到的知识也不复杂,所以对新手学习还是很有作用,贴上来给大家参考下. 完成了如下功能: 1.显示餐厅提示语: 2.打印菜单(输出菜品分类:主食.甜点.饮料.主菜.开胃菜): 3.选择ID进入菜品分类子目录: 4.进行具体选择(可重复选择同一样菜): 5.返回上级菜单(进行其他分类的选择): 6.完成点餐: 7.打印点餐信息(菜名.单价.数量.价格). 代码如下: #include <stdio.h> void main_munu(){ //打印主菜单 char a[6

  • python3实现点餐系统

    本文实例为大家分享了python3实现点餐系统的具体代码,供大家参考,具体内容如下 题目: 某餐厅外卖每天更新菜品,但是搭配价格是不变的,具体如下: "今天菜单如下","1  宫保鸡丁","2  青椒鸡米粒" ,"3  白萝卜焖肉", "4  蒜薹腊肉", "5  豆腐包肉 ", "6  鲤鱼跃龙门", "7  凉拌莲藕", "8  红烧

  • C语言实现点餐系统

    本文实例为大家分享了C语言点餐系统的具体代码,供大家参考,具体内容如下 #include<iostream> #include<fstream> #include<string> #include<conio.h> using namespace std; class shiwu { public: string mingzi; int price; shiwu(){} shiwu(string n,int p):mingzi(n),price(p){} }

  • Java实现餐厅点餐系统的实例代码

    学习Java实现餐厅点餐系统,本文实现该系统的功能截图,和数据库设计SQL语句,系统功能图,功能优势等供大家参考 1.点餐管理系统背景 随着科技的发展,去饭店吃饭点餐和结账都是以线上操作的形势完成. a.和现在有的系统比较起来,本系统有餐桌管理,菜系管理,菜名管理,订单管理,订单详情等功能. b.和现有系统比较起来,本系统是B/S结构,一般点餐系统为C/S结构,性能方面不如B/S结构,并且C/S接口需要安装客户端,客户端压力很大,我的系统只需要电脑或者手机具有浏览器,在同一局域网就可以进行订餐.

  • java实现KFC点餐系统

    同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++/python/Java,结合设计模式(2种以上)至少实现系统的以下功能: 1.正常餐品结算和找零. 2.基本套餐结算和找零. 3.使用优惠劵购买餐品结算和找零. 4.可在一定时间段参与店内活动(自行设计或参考官网信息). 5.模拟打印小票的功能(写到文件中). 类图: 建立IFood接口实现各类食物信息的打印: public interface IFood { /** * 打印输出食物

  • java实现可视化界面肯德基(KFC)点餐系统代码实例

    一.题目 使用java实现可视化KFC点餐系统. 二.题目分析 根据java中的用户图形界面包中的各个类设计界面.利用JFrame提供最大的容器,然后设计各个面板,各个面板中添加所需要的组件,本程序中需要对按钮组件添加监听者,当按下按钮之后做出相应的相应. 对于程序运行显示的第一个界面由一个继承于JFrame的类run类在构造函数中设计并通过函数setVisible(true)显示在界面上,界面上有一个按钮"点餐饮",当此按钮按下时触发响应函数,进入点餐界面,然后通过点击点餐界面各食物

  • C#实现在线点餐系统

    这个是C#大作业,写作业很用心,写了很久,所以留存一下.不是现在的是之前的的期末作业,现在才想着整理一下 实现功能: 1.商家登录:客户的登录.注册. 2.商家界面实现了对菜单的增.删.改.查:还有订单的查看.查询.结账(删除订单).查看已结账订单.关闭:退出系统. 3.用户界面实现了菜单的查看,查询,新建订单,选择餐桌,保存订单,增加菜品,退出. C#语言实现在线点餐系统,具体功能如下图 登录界面 using System; using System.Collections.Generic;

  • 微信小程序点餐系统开发常见问题汇总

    java后台相关问题 一,程序包lombok不存在 通常报这个错误,是因为,我们的开发者工具idea没有安装lombok库导致的 解决办法如下: 提示我们没有安装,我们就安装一个不就行了,下面来教大家如何安装. 1,点击扳手进入设置页 2,点击plugins,然后搜索lombok,点击install即可安装 3,安装完成后,重启idea开发工具即可 二,无法执行sql文件,IDEA 2019.1连接数据库报错(08001) 链接mysql数据库报如下错误 08001 could not conn

  • C++实现KFC点餐系统

    本文实例为大家分享了C++实现KFC点餐系统的具体代码,供大家参考,具体内容如下 一.题目名称:模拟肯德基收银系统 二.题目内容: 同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++或Java或Python结合设计模式(2种以上)至少实现系统的以下功能: 1.正常餐品结算和找零. 2.基本套餐结算和找零. 3.使用优惠劵购买餐品结算和找零. 4.可在一定时间段参与店内活动(自行设计或参考官网信息). 5.模拟打印小票的功能(写到文件中)

  • Java实现KFC点餐系统过程解析

    这篇文章主要为大家详细介绍了java实现KFC点餐系统,模拟肯德基快餐店的收银系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++/python/Java,结合设计模式(2种以上)至少实现系统的以下功能: 1.正常餐品结算和找零. 2.基本套餐结算和找零. 3.使用优惠劵购买餐品结算和找零. 4.可在一定时间段参与店内活动(自行设计或参考官网信息). 5.模拟打印小票的功能(写到文件

  • java实现KFC点餐小程序

    本文实例为大家分享了java实现KFC点餐系统的具体代码,供大家参考,具体内容如下 package KFC点餐系统; //food 类 public class Kfcfood { private String fname ; private int fnumb=1; private float fPrice; public Kfcfood() { super(); } public Kfcfood(String fname, int fnumb, float fPrice) { super()

  • python+pyqt5实现KFC点餐收银系统

    本文实例为大家分享了python实现KFC点餐收银系统的具体代码,供大家参考,具体内容如下 这个kfc收银系统我实现了的以下功能: 1.正常餐品结算和找零. 2.基本套餐结算和找零. 3.使用优惠劵购买餐品结算和找零. 4.可在一定时间段参与店内活动 5.模拟打印小票的功能(写到文件中). 工程文件: 肯德基.py文件实现各功能.kfctip.txt文件用于打印小票.picture文件里存放界面所需的图片.其他四个文件为各界面布局. 主界面: 正常餐品点餐界面: 套餐点餐界面: 活动套餐点餐界面

随机推荐