面向对象程序设计A课程设计(共33页).docx
精选优质文档-倾情为你奉上面向对象程序课程设计(2017/2018学年第二学期第17周)指导教师: XXX班级:XXX学号:XXXX姓名:XXX 面向对象程序课程设计任务书【题目】自助点餐系统【目的】通过设计一个小型的自助点餐系统,训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念,使自己的程序设计与调试水平有一个明显的提高。【要求】1、每个学生必须独立完成;2、课程设计时间为1周;3、设计语言采用C+;4、学生有事离校必须请假。课程设计期间,无故缺席按旷课处理;缺席时间达四分之一以上者,未按规定上交实验报告的学生,其成绩按不及格处理。【内容简介】 有一个小型餐厅,现在这个餐厅打算使用自助点餐系统,方便顾客自己点餐,并提供对餐厅销售情况的统计和管理功能。【考核标准】该系统为两种角色的用户提供服务,一种是餐厅管理员,一种是顾客。餐厅管理员根据账号、密码登录系统。顾客无需登录即可使用系统。1、 顾客通过该餐厅在系统中提供的菜单为自己点餐,菜单以文件形式保存。系统能够根据顾客的要求正确打出订单,订单内容包括订单编号、菜品名称、每个菜品的价格、份数、折扣等;订单分两种,一种是在店消费,在店消费要求包括餐桌号,是否有包厢费,另一种是外卖,外卖要求包括送餐时间,送餐地点,客户手机号,外卖服务费。(要求用继承和多态实现),成绩60;2、 系统退出后能保存当天的订单信息,要求每天一个文档,文档名按照日期命名。餐厅管理员可以根据订单编号查找删除修改某个订单,订单可以按照下单时间先后排序,成绩70;3、 能够实现对餐厅菜式和价格的管理,包括对菜品和对应价格的增加、修改、删除、查找,折扣的设置,成绩80;4、 系统可根据历史记录对销售情况进行统计,根据餐厅管理员的输入日期统计某天的销售情况并显示(包括一共接了多少单,销售额是多少,各个菜品的销售情况,外卖和在店销售的占比),成绩90;要求:用面向对象的程序设计方法设计该系统。本系统涉及的基本对象有订单对象(包括外卖订单和在店消费订单)、订单管理对象、菜单对象、菜品对象、菜品管理对象、系统界面。实现对这些对象的合理抽象和封装,正确定义类之间的关系。界面合理,代码文件组织清晰,命名符合规范,代码注释清楚,课程设计报告质量高。面向对象程序课程设计目 录一、 题目有一个小型餐厅,现在这个餐厅打算使用自助点餐系统,方便顾客自己点餐,并提供对餐厅销售情况的统计和管理功能。二、 需求分析有一个小型餐厅,该餐厅提供即时就餐和外卖服务。方便顾客自己点餐,并提供对餐厅销售情况的统计和管理功能。1、根据顾客的选择正确打出订单。2、统计出每一天的订单并将之保存在文件中。3、可以通过管理员功能对订单,菜品等进行操作。三、 系统结构图四、 类的设计五、 程序代码与说明Face.h#ifndef Face_h#define Face_h#include "OrderMana.h"class Faceprivate:OrderMana shard;public:void start();/定义开始界面void Adm();/定义管理员登入界面void Adm1();/定义管理员界面void AdmOrder();/查找修改删除订单void AdmVege();/菜式和价格的管理void AdmSell();/查看销售情况void client();/定义客户界面void AdmVegeI();/添加菜品void AdmVegeII();/修改菜品void AdmVegeIII();/删除菜品void AdmVegeV();/查找菜品void AdmVegeVI();/设置折扣void AdmOrderI();/查找订单void AdmOrderII();/修改订单void AdmOrderIII();/删除订单;#endifMana.h#ifndef Mana_h#define Mana_h#include "menu.h"#include <string>#include <list>using namespace std;class Mana :public Menuprivate:string kind;/订单种类string tim, address, phone;/送餐时间,送餐地点,客户手机号int table, Allmoney;/座位号,总价bool a;/是否有包厢费public:string Numble;/订单编号Mana(string numble,string kind,string tim, string address, string phone);Mana(string numble, string kind,int table, bool a);void setAllmoney(int money);string getKind() return kind; ;string getTim() return tim; ;string getAddress() return address; ;string getphone() return phone; ;int getTable() return table; ;int getAllmoney() return Allmoney; ;bool getA() return a; ;string getNumble() return Numble; ;void insert(string Vege, double money, int num, double discount);#endifmenu.h#ifndef Menu_h#define Menu_h#include <list>#include <vector>#include "vegetalbe.h"using namespace std;class Menuprivate:Vegetalbe*p;public:list <Vegetalbe*> members;list <Vegetalbe*> ord;void insert(string Vege, int num);/记录顾客挑选菜单virtual void insert(string Vege, double money, int num, double discount);void txtinsert();/记录原有菜单void printmembers();/输出原有菜单void printord();/输出顾客菜单void pushnew(Vegetalbe &b);/添加菜单string number();/订单编码void dleinsert(string Vege);/删除菜品Menu();#endiforder.h#ifndef Order_h#define Order_h#include <string>using namespace std;class Orderprivate:string account;string code;public:Order(string account, string code);bool judge();#endifOrderMana.h#ifndef OrderMana_h#define OrderMana_h#include "Mana.h"#include "menu.h"#include <list>#include <vector>using namespace std;class OrderManaprivate:double BossMoney = 0;/销售额int Fre = 0;/接了多少单double Spec;/外卖和在店销售的占比double TakeOut=0;/外卖次数double InShop=0;/在店次数Mana *p;public:list <Mana*> members;list <Mana*> ord;double getBossMoney();/输出相应日期的销售金额void txtinsertI(Menu *p, string tim, string address, string phone, string number);/打印外卖订单void txtinsertII(Menu *p, bool a, int x, string number);/打印在店订单void txtinsertMana(string day);/获取本地订单void findMana(string numble);/查找订单void pushit(Mana*re);/输出订单void dleinsertM(string numble);/删除订单double getSpec() return TakeOut / InShop; ;double getTakeOut() return TakeOut; ;double getInShop() return InShop; ;int getFre() return Fre; ;#endifvegetalbe.h#ifndef Vegetalbe_h#define Vegetalbe_h#include <string>using namespace std;class Vegetalbeprivate:string name;double money;int num;double discount;public:Vegetalbe(string name, double money, double discount)this->name = name;this->money = money;this->discount = discount;Vegetalbe(string name, double money,int num, double discount)this->name = name;this->money = money;this->num = num;this->discount = discount;/修改菜品voidSetVegetalbe(string name, double money, double discount)this->name = name;this->money = money;this->discount = discount;string getname() return name; double getmoney() return money; void setnum(int x) this->num = x; int getnum() return num; double getdiscount() return discount; ;#endifinterface.cpp#include "Face.h"#include "order.h"#include "menu.h"#include <iostream>#include <fstream>#include<cstdlib>#include<ctime>using namespace std;/定义开始界面void Face:start()cout << endl;cout << "ttt欢迎使用自助点餐系统ttt" << endl;cout << "_" << endl;cout << "ttt请输入操作模式ttt" << endl;cout << "ttt1.管理员ttt" << endl;cout << "ttt2.顾客ttt" << endl;cout << "_" << endl;int m;cin >> m;if (m = 1)Adm();int i;cin >> i;switch (i)case 1:AdmOrder(); break;case 2:AdmVege(); break;case 3:AdmSell(); break;case 4:break;else client();/定义管理员登入界面void Face:Adm()string account, code;while (1)cout << "_" << endl;cout << "ttt请输入账号:"cin >> account;cout << "ttt请输入密码:"cin >> code;cout << "_" << endl;Order A(account, code);if (A.judge()this->Adm1();break;else cout << "ttt输入的账户或密码错误" << endl;this->Adm();/定义管理员界面void Face:Adm1()cout << "_" << endl;cout << "ttt请输入操作:" << endl;cout << "ttt1.查找修改删除订单" << endl;cout << "ttt2.菜式和价格的管理" << endl;cout << "ttt3.查看销售情况" << endl;cout << "ttt4.退出" << endl;cout << "_" << endl;int i;cin >> i;switch (i)case 1:AdmOrder(); break;case 2:AdmVege(); break;case 3:AdmSell(); break;case 4:start(); break;start();/查找修改删除订单void Face:AdmOrder()cout << "_" << endl;cout << "ttt请输入操作:" << endl;cout << "ttt1.查找订单" << endl;cout << "ttt2.修改订单" << endl;cout << "ttt3.删除订单" << endl;cout << "ttt4.退出" << endl;cout << "_" << endl;int i;cin >> i;switch (i)case 1:AdmOrderI(); break;case 2:AdmOrderII(); break;case 3:AdmOrderIII(); break;case 4:Adm1(); break;Adm1();/菜式和价格的管理void Face:AdmVege()cout << "_" << endl;cout << "ttt请输入操作:" << endl;cout << "ttt1.添加菜品" << endl;cout << "ttt2.修改菜品" << endl;cout << "ttt3.删除菜品" << endl;cout << "ttt4.查找菜品" << endl;cout << "ttt5.设置折扣" << endl;cout << "ttt6.退出" << endl;cout << "_" << endl;int i;cin >> i;switch (i)case 1:AdmVegeI(); break;case 2:AdmVegeII(); break;case 3:AdmVegeIII(); break;case 4:AdmVegeV(); break;case 5:AdmVegeVI(); break;case 6:Adm1(); break;Adm1();/查看销售情况void Face:AdmSell()cout << "_" << endl;cout << "ttt请输入查找日期:"string day;cin >> day;day = "D:" + day + ".txt"OrderMana pe;pe.txtinsertMana(day);cout << "订单数:" << pe.getFre()<<endl;cout << "销售额:" << pe.getBossMoney() << endl;cout << "外卖和在店销售的占比:" << pe.getSpec() << endl;Adm1();/定义客户界面void Face:client()cout << "_" << endl;cout << "ttt菜单" << endl;cout << "菜品名称t" << "价格tt" << "折扣" << endl;Menu pe;string number;double money = 0;pe.txtinsert();pe.printmembers();cout << "请输入购买菜品和份数:" << endl;while (1)string Vege;cin >> Vege;int num;cin >> num;pe.insert(Vege, num);cout << "是否继续购买(是/否):"string c;cin >> c;if (c = "否") break;cout << "ttt请选择消费模式" << endl;cout << "ttt1.外卖" << endl;cout << "ttt2.在店消费" << endl;int i;cin >> i;if (i = 1)string time, address, phone;cout << "请输入送餐时间:" << endl;cin >> time;cout << "请输入送餐地点:" << endl;cin >> address;cout << "请输入手机号:" << endl;cin >> phone;number = pe.number();cout << "ttt外卖" << endl;cout << "ttt编号:" << number << endl;cout << "送餐时间:" << time << "t送餐地点:" << address << "t客户手机号:" << phone << endl;cout << "菜品tt价格tt份数tt折扣" << endl;pe.printord();list<Vegetalbe*>:iterator it;for (it = pe.ord.begin(); it != pe.ord.end(); it+)money = (*it)->getmoney()*(*it)->getnum()*(*it)->getdiscount()*0.1 + money;cout << "总价:" << money + 5 << "元" << endl;shard.txtinsertI(&pe, time, address, phone,number);else if (i = 2)cout << "请问是否选择包厢(是/否):"string i;cin >> i;bool r = 0;if (i = "是")r = 1;int c;srand(unsigned)time(NULL);c = rand() % (50 - 1);number = pe.number();cout << "ttt在店消费" << endl;cout << "ttt订单编号:" << number << endl;cout << "包厢费:" << (int)r * 50 << "元" << endl;cout << "座位号:" << c << endl;cout << "菜品tt价格tt份数tt折扣" << endl;pe.printord();list<Vegetalbe*>:iterator it;for (it = pe.ord.begin(); it != pe.ord.end(); it+)money = (*it)->getmoney()*(*it)->getnum()*(*it)->getdiscount()*0.1 + money;cout << "总价:" << money + (int)r * 50 << "元" << endl;shard.txtinsertII(&pe, r, c, number);start();/添加菜品void Face:AdmVegeI()Menu pe;pe.txtinsert();string name;double money;double discount;cout << "请输入添加的菜品名称:"cin >> name;cout << "请输入价格:"cin >> money;cout << "请输入折扣:"cin >> discount;Vegetalbe b(name, money, discount);pe.pushnew(b);list<Vegetalbe*>:iterator it;ofstream outDate("D:菜单.txt", ios:trunc);for (it = pe.members.begin(); it != pe.members.end(); it+)outDate << (*it)->getname() << "tt" << (*it)->getmoney() << "tt" << (*it)->getdiscount() << endl;outDate.close();cout << "添加成功" << endl;AdmVege();/修改菜品void Face:AdmVegeII()Menu pe;pe.txtinsert();string name;double money;double discount;cout << "请输入需要修改的菜品名称:"cin >> name;list<Vegetalbe*>:iterator it;for (it = pe.members.begin(); it != pe.members.end(); it+)if (*it)->getname() = name)cout << "请输入修改价格:"cin >> money;cout << "请输入修改折扣:"cin >> discount;(*it)->SetVegetalbe(name, money, discount);break;ofstream outDate("D:菜单.txt", ios:trunc);for (it = pe.members.begin(); it != pe.members.end(); it+)outDate << (*it)->getname() << "tt" << (*it)->getmoney() << "tt" << (*it)->getdiscount() << endl;outDate.close();cout << "修改成功" << endl;AdmVege();/删除菜品void Face:AdmVegeIII()Menu pe;pe.txtinsert();string name;cout << "请输入需要删除的菜品名称:"cin >> name;pe.dleinsert(name);list<Vegetalbe*>:iterator it;ofstream outDate("D:菜单.txt", ios:trunc);for (it = pe.ord.begin(); it != pe.ord.end(); it+)outDate << (*it)->getname() << "tt" << (*it)->getmoney() << "tt" << (*it)->getdiscount() << endl;outDate.close();cout << "删除成功" << endl;AdmVege();/查找菜品void Face:AdmVegeV()Menu pe;pe.txtinsert();string name;cout << "请输入需要查找的菜品名称:"cin >> name;list<Vegetalbe*>:iterator it;for (it = pe.members.begin(); it != pe.members.end(); it+)if (*it)->getname() = name)cout << "菜品名称:" << (*it)->getname() << "t价格:" << (*it)->getmoney() << "元t" << (*it)->getdiscount() << "折" << endl;break;AdmVege();/设置折扣void Face:AdmVegeVI()Menu pe;pe.txtinsert();double discount;double money;string name;cout << "请输入需要修改的菜品名称:"cin >> name;list<Vegetalbe*>:iterator it;for (it = pe.members.begin(); it != pe.members.end(); it+)if (*it)->getname() = name)cout << "请输入修改折扣:"cin >> discount;money = (*it)->getmoney();(*it)->SetVegetalbe(name, money, discount);break;ofstream outDate("D:菜单.txt", ios:trunc);for (it = pe.members.begin(); it != pe.members.end(); it+)outDate << (*it)->getname() << "tt" << (*it)->getmoney() << "tt" << (*it)->getdiscount() << endl;outDate.close();cout << "修改成功" << endl;AdmVege();/查找订单void Face:AdmOrderI()cout << "请输入要查找订单的日期:"string day;cin >> day;day = "D:" + day + ".txt"cout << "输入查找订单编号:"string numble;cin >> numble;OrderMana pe;pe.txtinsertMana(day);pe.findMana(numble);AdmOrder();/修改订单void Face:AdmOrderII()cout << "请输入要修改订单的日期:"string day;cin >> day;day = "D:" + day + ".txt"cout << "输入查找订单编号:"string numble;cin >> numble;OrderMana pe;pe.txtinsertMana(day);/删除订单void Face:AdmOrderIII()cout << "请输入要删除订单的日期:"string day;cin >> day;day = "D:" + day + ".txt"cout << "输入删除订单编号:"string numble;cin >> numble;OrderMana pe;pe.txtinsertMana(day);ofstream outDate(day, ios:trunc);list<Mana*>:iterator it;for (it = pe.ord.begin(); it != pe.ord.end(); it+)if (*it)->getKind() = "外卖")outDate << "ttt外卖" << endl;outDate << "ttt编号 " << (*it)->getNumble() << endl;outDate << "送餐时间:" << (*it)->getTim() << "t送餐地点:" << (*it)->getAddress() << "t客户手机号:" << (*it)->getphone() << endl;outDate << "菜品tt价格tt份数tt折扣" << endl;list<Vegetalbe*>:iterator I;for (I = (*it)-