自助订餐系统

来源:互联网 发布:淘宝皮质特征 编辑:程序博客网 时间:2024/04/27 22:44
1. 实验目的
本实验面向C++语言的初学者。
结合所学的理论知识,开发小型应用系统,帮助学生掌握和运用C++的面向对象特性
——类的封装、继承和多态等。
要求学生熟悉基本控制结构,会简单的文件操作更好。
2. 实验环境
本实验基于 Visual Studio 平台开发,参考主流的编码规范,如Google C++ Style
Guide(中文版)
3.1 编程语言和开发工具
编程语言: ANSI C/C++
开发工具: Visual Studio (2010)
3.2 编码规范
要求遵循良好的程序设计风格来设计和编写程序。基本编码规范:
1. 标识符的命名要到达顾名思义的程度;
2. 关键代码提供清晰、准确的注释;
3. 程序版面要求:
a) 不同功能块用空行分隔;
b) 一般一个语句一行;
c) 语句缩进整齐、层次分明。
3. 实验内容
使用类实现一个点餐系统,包括客户与卖家两种用户角色。系统提供客户角色预订、退
订功能;给卖家角色提供添加/删除菜单,查看/修改订单功能。除基本功能外,可稍微
发挥想象力,添加其他合理的、人性化的功能。
3.1 实验题目
请设计一个点餐系统。程序运行后,首先选择用户类型,然后从文本文件读入菜单信息
进行初始化,根据用户类型不同在控制台界面上提供不同功能选择。用户选择某项功能
后,根据提示进行操作;操作完成后,能返回功能选择菜单重新选择,直至用户退出。
客户功能:
1) 预订——打印出可选菜单,提示用户选择;在用户选择后,提示用户输入个人
信息,记录下信息,并保存至本地文件。
2) 查询/退订——显示所有的已订的订单列表,提示输入退订订单;用户输入后,
如果卖家尚未确认订单,则成功退订并修改本地文件;否则提示退订失败。
卖家功能:
1) 添加/删除菜单——菜单根据文件初始化后,卖家可以对其进行修改,包括添加
和删除菜式等,修改后将新菜单保存至文件,下次初始化仍可用。
2) 查询/修改订单——读取本地文件,显示所有的订单及其状态,提示确认订单或
不进行操作;卖家选择订单后,修改该订单为确认状态。
3.2 实验要求
(1) 程序中需包含下面几个类。
User抽象类——必须包含一个public属性的纯虚函数成员modifyOrder(),该函
数参数为vector<Order*> order。
Seller类和Buyer类——继承自User类。modifyOrder()在两个类中有不同的实
现,分别为确认订单和取消订单。
Menu类——包含数据成员菜式名字/编号,价格等,每道菜就是一个类对象。可使
用对象数组或vector来存储类对象。
Order类——继承自Menu类。除菜式名字/编号、价格外,还需保存客户的个人信
息(如地址,姓名,联系方式),以及份数等。
上述类中,可以根据需要自主添加其他的数据成员和方法。
(2) 类的声明和实现分开
User、Seller和Buyer三个类的声明和实现分别放于User.h和User.cpp中,Order
类和Menu类的声明和实现分别放于Menu.h和Menu.cpp文件中。
程序的主函数(main)放于main.cpp文件中
(3) 提供友好的界面
提供简单的文本菜单。
提供恰当的用户输入提示信息以方便使用,使用户一目了然知道要做什么操作以及
如何做。
(4) 文件输入进行初始化
通过读取menu.txt和order.txt文件初始化菜单信息和订单信息,文件中内容的
格式可以自己定义。
3.3 提示
1. 用户个人信息、菜单信息由你自主确定。如用户个人信息可以简单地包含姓名,
菜单信息包含菜名、价格等。
2. 可发挥想象力,提高系统的交互体验和可用性。
3. 请独立完成,但允许和鼓励相互讨论后自己写程序。由于题目具有开放性,很
容易从程序看出是否抄袭。若发现抄袭,将导致抄袭双方或多方大扣分或直接零分。
3.4 程序测试
1. 请设计1组测试用例数据,包括至少6个菜单信息和4个订单信息,如卖家确
认订单后客户是否可以退订,多次下订单能否都显示出来等。测试用例数据尽量覆盖各
种情况。(若使用文件对数据进行保存,可以测试多个用户下单的情形)
2. 界面交互时,请检测用户输入的正确性,保证程序的健壮性。(在用户做出操作
后最好打印出提示语句。)
3. 在实验报告中分析测试意图和测试结果。如果通过测试发现程序错误,也分析

错误原因、改正方法等,并在实验报告中体现。


代码过多,打包在此:

http://download.csdn.net/detail/jcjc918/5759735


贴个主函数:

#include<iostream>#include<fstream>#include<cstring>#include<string>#include<vector>#include "Menu.h"#include "User.h"using namespace std;fstream finout;vector<Order>order;vector<Menu>menu;void seviceForSeller();void seviceForBuyer();int main(){string n;bool success = 0;cout<<setw(55)<<"Welcome to the MyBooking system!"<<endl;cout<<"          ----------------------------------------------------------"<<endl;//1为买家,2为卖家,3为退出系统 cout<<right;cout<<endl<<setw(25)<<"1.Buyer"<<setw(15)<<"2.Seller"<<setw(15)<<"3.Exit"<<endl;while(cin>>n){order.clear();menu.clear();if(n == "3") break;//处理错误输入 if(n != "1" && n != "2"){    cout<<endl<<"Invalid number!Please input again :"<<endl;cout<<endl<<setw(25)<<"1.Buyer"<<setw(15)<<"2.Seller"<<setw(15)<<"3.Exit"<<endl;continue;}if(n == "1") seviceForBuyer();else seviceForSeller();cout<<right;cout<<endl<<setw(25)<<"1.Buyer"<<setw(15)<<"2.Seller"<<setw(15)<<"3.Exit"<<endl;}return 0;}//用于读取文件中的菜单 Menu inputMenu(){Menu iMenu;string dishID,dishName;double price = -1;finout>>dishID;if(dishID == " " || dishID == "\n"){iMenu.setDishID("-1");return iMenu;}finout>>dishName>>price;if(price < 0 || price > 100000){iMenu.setDishID("-1");return iMenu;}iMenu.setDishID(dishID);iMenu.setDishName(dishName);iMenu.setPrice(price);return iMenu;}//用于读取文件中的订单 Order inputOrder(){string dishID,dishName,name,adress,phone;double price = -1;int year,month,day,hour,modify,num;finout>>dishID;if(dishID == " " || dishID == "\n"){Order iOrder;iOrder.setDishID("-1");return iOrder;}finout>>dishName>>price>>num>>name>>adress>>phone;if(price < 0 || price > 100000){Order iOrder;iOrder.setDishID("-1");return iOrder;}finout>>year>>month>>day>>hour>>modify;Date date(year,month,day,hour);Order iOrder(dishName,dishID,price,name,adress,phone,date);iOrder.setnum(num);if(!modify) iOrder.setModify();return iOrder;}//卖家 void seviceForSeller(){Seller iSeller;Order iOrder;Menu iMenu;//验证密码 string password;finout.open("password.txt",ios::in);if(finout.fail()){cout<<endl<<"The system can't find the file!"<<endl;return;}finout>>password;finout.close();iSeller.setPassword(password);cout<<endl<<"Please input your password ( default is 888888 ) :";string str;int num = 5;cin>>str;while(num-- && str != iSeller.getPassword()){cout<<endl<<"The password is wrong!\nPlease input again : ";cin>>str;}if(num <= 0){cout<<endl<<"You have input wrong password five times!"<<endl;return;}//1为增加菜单,2为删除菜单,3为查询订单,4为确认订单,5为设置密码,6返回主菜单 cout<<endl<<"Please choose the function you want :"<<endl;cout<<left;    cout<<endl<<"           "<<setw(30)<<"1. Append menu"<<setw(20)<<"2. Cancel menu"<<endl;cout<<"           "<<setw(30)<<"3. Inquire"<<setw(20)<<"4.Modify"<<endl;cout<<"           "<<setw(30)<<"5.Set password"<<setw(20)<<"6.Main Menu"<<endl;string choice;while(cin>>choice){if(choice == "6"){return;}//处理错误输入 if(choice != "1" && choice != "2" && choice != "3" && choice != "4" && choice != "5")    {    cout<<endl<<"Invalid input!Please input anain!"<<endl;cout<<endl<<"           "<<setw(30)<<"1. Append menu"<<setw(20)<<"2. Cancel menu"<<endl;        cout<<"           "<<setw(30)<<"3. Inquire"<<setw(20)<<"4.Modify"<<endl;        cout<<"           "<<setw(30)<<"5.Set password"<<setw(20)<<"6.Main Menu"<<endl;    continue;    }    //从文件读取以初始化菜单信息和订单信息 order.clear();finout.open("order.txt",ios::in);if(finout.fail()){cout<<endl<<"The system can't find the file!"<<endl;break;}while(!finout.eof()){iOrder = inputOrder();if(iOrder.getDishID() == "-1") break;order.push_back(iOrder);}finout.close();menu.clear();finout.open("menu.txt",ios::in);if(finout.fail()){cout<<endl<<"The system can't find the file!"<<endl;break;}while(!finout.eof()){iMenu = inputMenu();if(iMenu.getDishID() == "-1") break;menu.push_back(iMenu);}finout.close();if( choice == "1")    iSeller.appendMenu(menu);else if(choice == "2")iSeller.cancelMenu(menu);else if(choice == "3")iSeller.inquireOrder(order);else if(choice == "4")iSeller.modifyOrder(order);else{            //修改密码 string str1,str2;cout<<right;cout<<endl<<setw(35)<<"1.Continue"<<setw(20)<<"2.return"<<endl;while(cin>>str1){if(str1 == "2") break; //处理错误输入 if(str1 != "1"){cout<<"Invalid input!"<<endl;cout<<endl<<setw(35)<<"1.Continue"<<setw(20)<<"2.return"<<endl;continue;}cout<<"Please input your old password : ";cin>>str1;if(str1 == iSeller.getPassword()) break;else {cout<<right;cout<<endl<<"Wrong!"<<endl;    cout<<endl<<setw(35)<<"1.Continue"<<setw(20)<<"2.return"<<endl;}}if(str1 == "2"){cout<<left;cout<<endl<<"           "<<setw(30)<<"1. Append menu"<<setw(20)<<"2. Cancel menu"<<endl;            cout<<"           "<<setw(30)<<"3. Inquire"<<setw(20)<<"4.Modify"<<endl;            cout<<"           "<<setw(30)<<"5.Set password"<<setw(20)<<"6.Main Menu"<<endl;continue;}cout<<endl<<"Please input your new password : ";cin>>str1;cout<<endl<<"Please input again :";cin>>str2;//两次输入的新密码一样,则修改密码,写入文件 if(str1 == str2 ){finout.open("password.txt",ios::out);            if(finout.fail())            {             cout<<endl<<"The system can't find the file!"<<endl;             return;            }            finout<<str1;            finout.close();iSeller.setPassword(str1);cout<<endl<<"The new password have benn set!"<<endl;}else {    cout<<endl<<"The new password you have input twice times is different !"<<endl;}}cout<<left;cout<<endl<<"           "<<setw(30)<<"1. Append menu"<<setw(20)<<"2. Cancel menu"<<endl;    cout<<"           "<<setw(30)<<"3. Inquire"<<setw(20)<<"4.Modify"<<endl;    cout<<"           "<<setw(30)<<"5.Set password"<<setw(20)<<"6.Main Menu"<<endl;}if(choice == "6"){    return;}}void seviceForBuyer(){Buyer ibuyer;Menu iMenu;    Order iOrder;string n;// 1为点菜,2为查询订单,3为修改订单 ,4返回主菜单 cout<<left;cout<<endl<<"Please continue to choose the function you want:"<<endl;cout<<endl<<"           "<<setw(20)<<"1. Order"<<setw(20)<<"2. Inquire"<<endl;cout<<"           "<<setw(20)<<"3. Cancel"<<setw(20)<<"4.Main Menu"<<endl;cin>>n;    while(n!="4"){        //处理错误输入     if(n != "1" && n != "2" && n!= "3" ){cout<<endl<<"Invalid input!Please input anain!"<<endl;cin>>n;continue;}//从文件读取以初始化菜单信息和订单信息 order.clear();finout.open("order.txt",ios::in);if(finout.fail()){cout<<endl<<"The system can't find the file!"<<endl;break;}while(!finout.eof()){iOrder = inputOrder();if(iOrder.getDishID() == "-1") break;order.push_back(iOrder);}finout.close();menu.clear();finout.open("menu.txt",ios::in);if(finout.fail()){cout<<endl<<"The system can't find the file!"<<endl;break;}while(!finout.eof()){iMenu = inputMenu();if(iMenu.getDishID() == "-1") break;menu.push_back(iMenu);}finout.close();if(n=="1")ibuyer.bookOrder(menu,order);else if(n=="2")ibuyer.inquireOrder(order);else if(n=="3")    ibuyer.modifyOrder(order);cout<<left;cout<<endl<<"Please continue to choose the function you want:"<<endl;cout<<endl<<"           "<<setw(20)<<"1. Order"<<setw(20)<<"2. Inquire"<<endl;    cout<<"           "<<setw(20)<<"3. Cancel"<<setw(20)<<"4.Main Menu"<<endl;cin>>n;}if(n =="4") return ;}



原创粉丝点击