上订餐系统

软件工程综合实践专题第一次作业

上订餐系统

                                                                                                                                                                                                                                                                          —-来自于班中同学的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<<“tt请输入用户名:“;

cin>>name;

cout<<“tt请输入密码:“;

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<<“tttt欢迎进入 上点餐系统tttt”<<endl;

    cout<<“ttt1.查看菜单信息ttt”<<endl;

    cout<<“ttt2.增加订单信息ttt”<<endl;

    cout<<“ttt3.查看费用信息ttt”<<endl;

cout<<“ttt4.确认订单情况ttt”<<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<<“nn请输入编 : “;

        cin>>number;

 

 

        //  功能1 : 查看菜单信息

         if(number==1) {

            cout<<“ntttt菜单信息: nn”;

            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 filen”;

                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()<<““<<“nn”;

                

  else if(m[i].buyerId1==2)

    cout<<endl<<“姓名为:”<<m[i].name1<<“的顾客需要支付: “<<c[1]->getPrice()<<““<<“nn”;

 

 

 

  }

 

  else if(m[i].huiyuan==2)

  {

      if(m[i].buyerId1==1)

                cout<<endl<<“姓名为:”<<m[i].name1<<“的顾客需要支付: “<<(c[0]->getPrice())*0.9<<““<<“nn”;

  else if(m[i].buyerId1==2)

    cout<<endl<<“姓名为:”<<m[i].name1<<“的顾客需要支付: “<<(c[1]->getPrice())*0.9<<““<<“nn”;

 

 

  }

}

 

            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)tt”;

        cin>>flag;

        if (flag==1) {

            continue;

        }

        else if (flag==0) {

            break;

        }

        else cout<<“输入错误!“;

    }

    return 0;

}

 

 

修改后程序代码:

main.cpp

 

 

 

buy.h

 

 

Menudishes.h

 

 

 

 

 

 

 上订餐系统

 

6.功能完善

   随着生活节奏的不断加快,外卖订餐成了许多人必不可少的需求之一。本程序功能比较单一,首先,只能实现账 用户的登录才能使用此app,单并未提供用户注册功能,然后本app的 上点餐的菜单功能单一,应该添加更多的菜单内容。此外会员和普通人的区别并没有完全体现出来,计算价格时没有详细的说明。更重要的一点是 上订餐忽略了最重要也是最令人在意的一点——时间观念,所以本app应该添加外卖的送货时间功能,或者给予外卖员GPS定位系统,连接卫星地图等让顾客可以随时看到外卖的实时配送情况。最后一点,支付方式可以做一个分类,然后自动连接到对应的支付软件上。对于当下潮流,此app一定会得到良好的发展。

 

文章知识点与官方知识档案匹配,可进一步学习相关知识MySQL入门技能树数据库组成31364 人正在系统学习中 相关资源:校园自助点餐APP的开发.rar-互联 文档类资源-CSDN文库

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年2月3日
下一篇 2019年2月3日

相关推荐