学校食堂简易点餐管理系统(含用户登录且密码隐藏)C++
生活随笔
收集整理的這篇文章主要介紹了
学校食堂简易点餐管理系统(含用户登录且密码隐藏)C++
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?系統運行步驟陳述:
?源程序里面的注釋我都給的很詳細,就不在這里一一介紹啦,還是那句老話,寫的很倉促,存在很多問題,希望大家不要見笑哈!下面給出代碼。
源代碼如下:?
//ordersystem //author:babysen //date:2022/01/05-07#include <iostream> #include <string> #include <fstream> #include <conio.h>using namespace std;const int strsize = 30; const string flavor[8] = {"三鮮", "甜", "微微辣", "微辣", "麻辣", "中辣", "超辣", "番茄"}; //口味//構造顯示函數: void display_menu(); //顯示菜單 void display_name(); //菜名 void display_preference(); //顯示咸淡口味//void display_sex(); //統計男女生人數 //構建結構體,其中s是性別的另一種表達,s=0,1;0為女性,1為男性struct order {char fullname[strsize]; //菜全名int b; //菜編號int price; //價格 };//輸入結構體數組的內容//熱賣推薦菜單 order hsr[6] ={{"香鍋", 1, 15},{"肉夾饃", 2, 7},{"羊肉泡饃", 3, 24},{"洛陽燴菜", 4, 7},{"砂鍋米線", 5, 7},{"泡面加蛋", 6, 6}};//餃子菜單 order dump[8] ={{"大份大肉蓮菜", 7, 10},{"小份大肉蓮菜", 8, 8},{"大份韭菜雞蛋", 9, 10},{"小份韭菜雞蛋", 10, 8},{"大份大蔥牛肉", 11, 12},{"小份大蔥牛肉", 12, 10},{"大份大蔥羊肉", 13, 12},{"小份大蔥羊肉", 14, 10}};//面食菜單 order noodle[10] ={{"大碗三合一面", 15, 11},{"小碗三合一面", 16, 10},{"大碗二合一面", 17, 10},{"小碗二合一面", 18, 9},{"大碗油潑面", 19, 9},{"小碗油潑面", 20, 8},{"大碗拉條子面", 21, 9},{"小碗拉條子面", 22, 8},{"大碗棍棍面", 23, 9},{"小碗棍棍面", 24, 8}};//米飯菜單 order rice[7] ={{"兩葷兩素", 25, 8},{"一葷三素", 26, 8},{"一葷兩素", 27, 7},{"三樣素菜", 28, 6},{"小炒肉蓋澆飯", 29, 11},{"茄子蓋澆飯", 30, 9},{"番茄雞蛋蓋澆飯", 31, 9}};//特色小吃菜單 order spes[4] ={{"一份油條", 32, 4},{"陜西涼皮", 33, 6},{"豆腐腦", 34, 2},{"葫蘆頭泡饃", 35, 13}};//定義菜單函數 void display_menu() {cout << "-----------------------------------------" << endl;cout << "| 餐廳菜單表 |" << endl;cout << "-----------------------------------------" << endl;cout << "| a.熱賣推薦 |" << endl;cout << "-----------------------------------------" << endl;cout << "| b.餃子 |" << endl;cout << "-----------------------------------------" << endl;cout << "| c.面條 |" << endl;cout << "-----------------------------------------" << endl;cout << "| d.米飯 |" << endl;cout << "-----------------------------------------" << endl;cout << "| e.特色小吃 |" << endl;cout << "-----------------------------------------" << endl;cout << "| q.退出并統計 |" << endl;cout << "-----------------------------------------" << endl; }//定義菜名函數 void display_name() {cout << "a.熱賣推薦菜單如下: " << endl;for (int i = 0; i < 6; i++)cout << "菜名: " << hsr[i].fullname << ","<< "編號: " << hsr[i].b << ","<< "單價: " << hsr[i].price << "元" << endl;cout << "b.餃子: " << endl;for (int i = 0; i < 8; i++)cout << "菜名: " << dump[i].fullname << ","<< "編號: " << dump[i].b << ","<< "單價: " << dump[i].price << "元" << endl;cout << "c.面條: " << endl;for (int i = 0; i < 10; i++)cout << "菜名: " << noodle[i].fullname << ","<< "編號: " << noodle[i].b << ","<< "單價: " << noodle[i].price << "元" << endl;cout << "d.米飯: " << endl;for (int i = 0; i < 7; i++)cout << "菜名: " << rice[i].fullname << ","<< "編號: " << rice[i].b << ","<< "單價: " << rice[i].price << "元" << endl;cout << "e.特色小吃: " << endl;for (int i = 0; i < 4; i++)cout << "菜名: " << spes[i].fullname << ","<< "編號: " << spes[i].b << ","<< "單價: " << spes[i].price << "元" << endl; }//定義個人口味函數 void display_preference() {cout << "--------------------------------------" << endl;cout << "| 1.三鮮, 2.甜, 3.微微辣, 4.微辣 |" << endl;cout << "| 5.麻辣, 6.中辣, 7.超辣, 8.番茄 |" << endl;cout << "--------------------------------------" << endl; }//統計男女生人數函數 /* void display_sex() {for (int i = 0; i < NUM; i++)cout << people[i].fullname << " 's sex is: " << people[i].sex << endl; } *///主函數 int main() {//數據寫入文件ofstream outfile("statis.txt", ios::trunc); //輸出結果存儲在statis文件中if (!outfile){cerr << "打開錯誤!" << endl;exit(1);}//1.初始化,設定賬號和密碼。long int ID = 20220106;int num = 6; //輸入密碼次數//2.建立存儲信息的變量。long int id;//3.完成do-while循環結構中輸入的內容cout << "請輸入賬號: ";cin >> id;int i = 0;//初始化一個空字符串,s是密碼字符串string pwd = "", s = "666666";cout << "請輸入密碼: ";char c;while (true){c = getch();if (c != 13) //如果不是回車,就不斷往string類型的pwd內添加c{pwd = pwd + c;cout << "*";}else{if (pwd == s && id == ID){cout << endl;cout << " 登陸成功 " << endl;cout << "-----------------------------------------" << endl;char ch; //菜種類選擇序號int nn; //口味選擇序號double p0[6]; //a類菜的價錢double p1[8]; //b類菜的價錢double p2[10]; //c類菜的價錢double p3[7]; //d類菜的價錢double p4[4]; //e類菜的價錢long int total[35] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //各菜初始點餐數量 //long int total[]={};cout << "歡迎光臨大學食堂就餐,菜單如下: " << endl;display_menu();cout << endl;display_name();cout << endl;display_preference();cout << "______________________________" << endl;cout << "______________________________" << endl;cout << "請用字母輸入您想吃哪個種類的菜品: " << endl;while (cin >> ch && ch != 'q' && ch != 'Q'){cout << "輸入菜名簡稱" << endl;int bi; //菜編號switch (ch) //case分支大括號可以不要,這里為了方便觀看加上了{case 'a':case 'A':{cin >> bi;if (bi == 1)total[0]++;else if (bi == 2)total[1]++;else if (bi == 3)total[2]++;else if (bi == 4)total[3]++;else if (bi == 5)total[4]++;else if (bi == 6)total[5]++;}break;case 'b':case 'B':{cin >> bi;if (bi == 7)total[6]++;else if (bi == 8)total[7]++;else if (bi == 9)total[8]++;else if (bi == 10)total[9]++;else if (bi == 11)total[10]++;else if (bi == 12)total[11]++;else if (bi == 13)total[12]++;else if (bi == 14)total[13]++;}break;case 'c':case 'C':{cin >> bi;if (bi == 15)total[14]++;else if (bi == 16)total[15]++;else if (bi == 17)total[16]++;else if (bi == 18)total[17]++;else if (bi == 19)total[18]++;else if (bi == 20)total[19]++;else if (bi == 21)total[20]++;else if (bi == 22)total[21]++;else if (bi == 23)total[22]++;else if (bi == 24)total[23]++;}break;case 'd':case 'D':{cin >> bi;if (bi == 25)total[24]++;else if (bi == 26)total[25]++;else if (bi == 27)total[26]++;else if (bi == 28)total[27]++;else if (bi == 29)total[28]++;else if (bi == 30)total[29]++;else if (bi == 31)total[30]++;}break;case 'e':case 'E':{cin >> bi;if (bi == 32)total[31]++;else if (bi == 33)total[32]++;else if (bi == 34)total[33]++;else if (bi == 35)total[34]++;}break;}cout << "輸入口味選項:" << endl;cin >> nn;while (nn != 0){switch (nn){case 1:cout << flavor[0] << endl;break;case 2:cout << flavor[1] << endl;break;case 3:cout << flavor[2] << endl;break;case 4:cout << flavor[3] << endl;break;case 5:cout << flavor[4] << endl;break;case 6:cout << flavor[5] << endl;break;case 7:cout << flavor[6] << endl;break;case 8:cout << flavor[7] << endl;break;default:cout << "選擇錯誤" << endl;}break;}cout << "請繼續用字母輸入您想吃哪個種類的菜品: " << endl;}for (int i = 0; i < 6; i++){p0[i] = total[i] * hsr[i].price;outfile << "a類各菜品點餐數如下: " << endl;outfile << hsr[i].fullname << " " << total[i] << " 份" << endl;outfile << "a類各菜品銷售額如下: " << endl;p0[i] = total[i] * hsr[i].price;outfile << hsr[i].fullname << " " << p0[i] << " 元" << endl;}for (int i = 0; i < 8; i++){outfile << "b類各菜品點餐數如下: " << endl;outfile << dump[i].fullname << " " << total[i + 5] << " 份" << endl;outfile << "b類各菜品銷售額如下: " << endl;p1[i] = total[i + 5] * dump[i].price;outfile << dump[i].fullname << " " << p1[i] << " 元" << endl;}for (int i = 0; i < 10; i++){outfile << "c類各菜品點餐數如下: " << endl;outfile << noodle[i].fullname << " " << total[i + 13] << " 份" << endl;outfile << "c類各菜品銷售額如下: " << endl;p2[i] = total[i + 13] * noodle[i].price;outfile << noodle[i].fullname << " " << p2[i] << " 元" << endl;}for (int i = 0; i < 7; i++){outfile << "d類各菜品點餐數如下: " << endl;outfile << rice[i].fullname << " " << total[i + 23] << " 份" << endl;outfile << "d類各菜品銷售額如下: " << endl;p3[i] = total[i + 23] * rice[i].price;outfile << rice[i].fullname << " " << p3[i] << " 元" << endl;}for (int i = 0; i < 4; i++){outfile << "e類各菜品點餐數如下: " << endl;outfile << spes[i].fullname << " " << total[i + 30] << " 份" << endl;outfile << "e類各菜品銷售額如下: " << endl;p4[i] = total[i + 30] * spes[i].price;outfile << spes[i].fullname << " " << p4[i] << " 元" << endl;}break;}else{if (num == 1){cout << "今日次數已用完!";break;}else{cout << endl;cout << "賬戶或密碼錯誤,還剩余" << --num << "次機會" << endl;cout << "請輸入賬號: ";cin >> id;cout << "請輸入密碼: ";pwd = "";}}}}outfile.close();cout << "處理完畢,請打開文件查看結果!" << endl;void free();system("pause");//請按任意鍵繼續system("cls");//清屏操作return 0; }?結果顯示如下:
陳述在該系統所存在的問題:
總結
以上是生活随笔為你收集整理的学校食堂简易点餐管理系统(含用户登录且密码隐藏)C++的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 遥感领域多模态综述论文翻译
- 下一篇: QT安装段错误segmentation