软件工程综合实践专题第一次作业
网上订餐系统
----来自于班中同学的c++作业
1.原代码程序:
//main.cpp
# include "iostream"
# include "fstream"
#include<string>
using namespace std;
# include "buyer.h"
# include "menudishes.h"
# include "strclass.h"
int check_user() {
char name[10], password[10];
int n=1,ret=0;
system("cls"); //windows下清屏
system("color 0F");
putchar('\n');
cout<<"\t| 欢迎使用网上订餐系统 |\n";
cout<<"\t| ******************************** |\n";
cout<<"\t| 上海海洋大学17级软工2班 |\n";
cout<<"\t| XXX |\n";
cout<<"\t| OOO |\n";
cout<<"\t| 2018年联合开发 |\n";
cout<<"\t| ********************************|\n";
cout<<"\t ------------------------------------\n";
do
{
cout<<"\t\t请输入用户名:";
cin>>name;
cout<<"\t\t请输入密码:";
cin>>password;
if (strcmp(name, "a") == 0 && strcmp(password, "123")==0)
ret=1;
else
{
ret=0;
if (n<3) printf("\t注意:您输入的用户名或秘密有误,您还有%d机会!\n",3-n);
}
n++;
}while (ret==0&&n<=3);
return ret;
}
// 系统界面
void systemsurface()
{
cout<<"\t\t\t\t欢迎进入网上点餐系统\t\t\t\t"<<endl;
cout<<"\t\t\t1.查看菜单信息\t\t\t"<<endl;
cout<<"\t\t\t2.增加订单信息\t\t\t"<<endl;
cout<<"\t\t\t3.查看费用信息\t\t\t"<<endl;
cout<<"\t\t\t4.确认订单情况\t\t\t"<<endl;
}
dindan m[15];
int len=0;
void Scandindan()
{
ifstream fin("D:\\dazuoye\\booking_meals_system\\dindan.txt",ios::in);
if(fin)
cout<<"文件打开成功"<<endl;
else
cout<<"文件打开失败"<<endl;
int i;
for(i=0;i<len;i++){
fin>>m[i].name1>>m[i].buyerId1>>m[i].huiyuan;
}
fin.close();
}
// 增加普通顾客
void addNormalBuyer()
{
normalBuyer b4 = normalBuyer();
b4.addBuyer(b4);
ofstream file;
file.open("customer.txt",ios_base::app);
if (!file.is_open()) {
cout<<"cannot find the opening file"<<endl;
}
file<<"顾客姓名: "<<b4.getBuyName()<<"\t菜品编号: "<<b4.getId()<<"\t顾客为普通人 \n"
<<"地址: "<<b4.getAddress()<<"\t"<<"电话号码: "<<b4.getPhoneNumber()<<"\n"<<endl;
file.close();
}
// 增加会员
void addMember()
{
member b5 = member();
b5.addBuyer(b5);
ofstream file;
file.open("customer.txt",ios_base::app);
if (!file.is_open()) {
cout<<"cannot find the opening file"<<endl;
}
file<<"顾客姓名: "<<b5.getBuyName()<<"\t菜品编号: "<<b5.getId()<<"\t顾客为会员\n"
<<"地址: "<<b5.getAddress()<<"\t"<<"电话号码: "<<b5.getPhoneNumber()<<"\n"<<endl;
file.close();
}
// 增加dindan
void adddindan()
{
dindan b6 = dindan();
b6.addBuyer(b6);
ofstream file;
file.open("dindan.txt",ios_base::app);
if (!file.is_open()) {
cout<<"cannot find the opening file"<<endl;
}
file<<b6.getBuyName1()<<"\t"<<b6.getId1()<<"\t"<<b6.gethuiyuan()<<"\n"<<endl;
file.close();
}
//系统原有菜单信息
staplefood c1("主食","番茄肉酱意面","20分钟",200,2,1);
desert c2("小吃","黑森林慕斯蛋糕","10分钟",288,2,2);
menudishes *c[2]={&c1,&c2};
int main()
{
int i=0,flag=0,number=0,temp;
// 用户验证
if (!check_user()) {
printf("\t对不起,您不是合法用户,按任意键退出!\a");
fflush(stdin); // 清除缓冲区
getchar(); // 等待用户按键
return 0;
}
system("cls");
for (; number!=5 ; ) {
systemsurface();
cout<<"\n\n请输入编号: ";
cin>>number;
// 功能1 : 查看菜单信息
if(number==1) {
cout<<"\n\t\t\t\t菜单信息: \n\n";
for (i=0; i<2; i++) {
c[i]->display();
}
}
// 功能2 : 增加订单信息(区别普通和会员)
else if (number==2) {
cout<<"输入顾客类型(普通=1 or 会员=2)";
cin>>temp;
len++;
// 普通顾客
if(temp==1) {
addNormalBuyer();
}
// 会员顾客
else if(temp==2) {
addMember();
}
adddindan();
}
// 功能3 : 查看费用信息 并将内容写入文件
else if (number==3) {
ofstream fout("f1.txt",ios::out);
if(!fout) { // 是否打开成功
cout<<"cannot open output file\n";
return 1;
}
Scandindan();
int i;
for(i=0;i<len;i++)
{
if(m[i].huiyuan==1)
{
if(m[i].buyerId1==1)
cout<<endl<<"姓名为:"<<m[i].name1<<"的顾客需要支付: "<<c[0]->getPrice()<<"元"<<"\n\n";
else if(m[i].buyerId1==2)
cout<<endl<<"姓名为:"<<m[i].name1<<"的顾客需要支付: "<<c[1]->getPrice()<<"元"<<"\n\n";
}
else if(m[i].huiyuan==2)
{
if(m[i].buyerId1==1)
cout<<endl<<"姓名为:"<<m[i].name1<<"的顾客需要支付: "<<(c[0]->getPrice())*0.9<<"元"<<"\n\n";
else if(m[i].buyerId1==2)
cout<<endl<<"姓名为:"<<m[i].name1<<"的顾客需要支付: "<<(c[1]->getPrice())*0.9<<"元"<<"\n\n";
}
}
fout.close();
}
// 功能4 : 确认订单情况
else if (number==4) {
// 通过文件读写的方式 显示原有顾客信息 便于数据的增加
ifstream in("customer.txt"); // 打开文件输入流
if (! in.is_open()) // 检测是否打开成功
{
cout << "Error opening file";
exit (1);
}
string s;
while(getline(in,s))
{
cout<<s<<endl;
}
in.close(); //关闭文件输入流
}
else cout<<"输入错误!"<<endl;
// 功能6 : 是否继续查询
cout<<"是否继续查询?(是--1/否--0)\t\t";
cin>>flag;
if (flag==1) {
continue;
}
else if (flag==0) {
break;
}
else cout<<"输入错误!";
}
return 0;
}
修改后程序代码:
main.cpp
buy.h
Menudishes.h
2.系统环境:
软件环境:Visualc++ 6.0
硬件环境:处理器:Inter(R)Core(TM)i5-7300HQ CPU @ 2.50GHz
系统类型:64位操作系统,基于x64的处理器
3.功能说明
buyer.h 实现对顾客的姓名,菜的编号,地址,价格,手机号的定义。定义普通人类,会员类为buyer类的子类,定义订单类,定义基类buyer类。
menudishes.h 定义menudishes类 以及子类stablefood类desert类
main.cpp 实现登录系统界面,以及功能系统界面,void addNormalBuyer(),void addMember(),void adddindan()分别将顾客信息读入文件,再显示系统原有菜单信息,通过输入1或2区别是否是会员。查看费用信息,通过读取之前文件存储的信息来进行费用的计算。并进行订单的确认,通过文件读写显示之前所有订单的信息。
4.功能改查
修改后的main程序上新添加了退出程序的功能在main.cpp中。
用户可以进行点餐后随意退出程序。
5.功能演示
6.功能完善
随着生活节奏的不断加快,外卖订餐成了许多人必不可少的需求之一。本程序功能比较单一,首先,只能实现账号用户的登录才能使用此app,单并未提供用户注册功能,然后本app的网上点餐的菜单功能单一,应该添加更多的菜单内容。此外会员和普通人的区别并没有完全体现出来,计算价格时没有详细的说明。更重要的一点是网上订餐忽略了最重要也是最令人在意的一点——时间观念,所以本app应该添加外卖的送货时间功能,或者给予外卖员GPS定位系统,连接卫星地图等让顾客可以随时看到外卖的实时配送情况。最后一点,支付方式可以做一个分类,然后自动连接到对应的支付软件上。对于当下潮流,此app一定会得到良好的发展。