/****************************************************************************** ** program name: Restaurant order system ** ** Author: ** Date: 2014/06/21 ** ** Description: This program imitating restaurant order system ** ******************************************************************************/ #include <iostream> #include <string> #include <fstream> #include <windows.h> using namespace std; // ==============================Menu class===================================== class Menu { private: string m_strFoodName; // save food name int m_nFoodNum; // save food number float m_fPrice; // save food price string m_strKind; // sacve food kind int m_nFoodCount; // count how many foods have been selceted public: void drawFoodMenu();// display a food data menu void drawSelectedMenu(); // display a food data menu that has been selected string getName(); // return the food name int getNum(); // return the food number float getPrice(); string getKind(); int getCount(); void setName(string name); void setNum(int num); void setPrice(float price); void setKind(string kind); void setCount(int count); public: Menu(); ~Menu(); }; Menu::Menu(){} Menu::~Menu(){} // display the number,kind,name and price of food menu void Menu::drawFoodMenu() { cout<<m_nFoodNum<<"\t "<<m_strKind<<"\t "<<m_strFoodName<<"\t "<<m_fPrice<<endl; } // display the food list data that have been selected void Menu::drawSelectedMenu() { cout<<m_nFoodNum<<"\t "<<m_strKind<<"\t "<<m_strFoodName<<"\t "<<m_fPrice<<"\t "<<m_nFoodCount<<endl; } int Menu::getCount() { return m_nFoodCount; } string Menu::getKind() { return m_strKind; } string Menu::getName() { return m_strFoodName; } int Menu::getNum() { return m_nFoodNum; } float Menu::getPrice() { return m_fPrice; } void Menu::setCount(int count) { m_nFoodCount = count; } void Menu::setKind(string kind) { m_strKind = kind; } void Menu::setName(string name) { m_strFoodName = name; } void Menu::setNum(int num) { m_nFoodNum = num; } void Menu::setPrice(float price) { m_fPrice = price; } // ========================================================================== // ============================Function Definition=========================== void drawMainMenu(); // display main menu void getFoodDataFromFile(char* file,Menu menu[],int n); // get the data from file and return with menu array void showRecommendedFood(Menu menu[]); void showNewFood(Menu menu[]); void showAllFood(Menu menu[],int n); void selectFood(Menu menu[]); void drawSubMenu(); void showSelectedFood(int arr1[],int arr2[],Menu menu[],int n); void countMoney(Menu menu[],int arr1[],int arr2[],int n); // ============================================================================= // ============================Function implementation======================= void drawMainMenu() { system("cls"); cout<<"\t********************************************************"<<endl; cout<<"\t Welcome to our restaurant"<<endl; cout<<"\t********************************************************"<<endl; cout<<endl; cout<<"\t 1 > * Recommended food * "<<endl; cout<<"\t 2 > * New food * "<<endl; cout<<"\t 3 > * All food * "<<endl; cout<<"\t 4 > * Select food * "<<endl; cout<<"\t 0 > * Exit * "<<endl; cout<<endl; } void getFoodDataFromFile(char* file,Menu menu[],int n) { int num; string name,kind; float price; ifstream f(file); // open file for(int i = 0;i < n;i++) { f>>num>>kind>>name>>price; // cout<<"\t"<<num<<"\t "<<kind<<"\t "<<name<<"\t "<<price<<endl; menu[i].setNum(num); menu[i].setKind(kind); menu[i].setName(name); menu[i].setPrice(price); } f.close(); } void showRecommendedFood(Menu menu[]) { cout<<"Number"<<"\t "<<"Kind"<<"\t "<<"FoodName"<<"\t "<<"Price"<<endl; cout<<"------------------------------------------------------------"<<endl; for(int i = 0;i < 15;i++) { if(0 == i % 2) menu[i].drawFoodMenu(); } } void showNewFood(Menu menu[]) { cout<<"Number"<<"\t "<<"Kind"<<"\t "<<"FoodName"<<"\t "<<"Price"<<endl; cout<<"------------------------------------------------------------"<<endl; for(int i = 0;i < 5;i++) menu[i].drawFoodMenu(); } void showAllFood(Menu menu[],int n) { cout<<"Number"<<"\t "<<"Kind"<<"\t "<<"FoodName"<<"\t "<<"Price"<<endl; cout<<"------------------------------------------------------------"<<endl; for(int i = 0;i < n;i++) menu[i].drawFoodMenu(); } void selectFood(Menu menu[]) { int food_all; int food_count; int food_number; int food_count_arr[10]; int food_number_arr[10]; int choice; showAllFood(menu,15); cout<<"how many dishes do you want(<=10): "<<endl; cin>>food_all; for(int i = 0;i < food_all;i++) { cout<<"please input No."<<i+1<<"food number: "; cin>>food_number; cout<<"and input how many this dishes you want: "; cin>>food_count; food_count_arr[i] = food_count; food_number_arr[i] = food_number; } drawSubMenu(); cout<<"please enter choice: "; cin>>choice; while(1) { switch(choice) { case 0: break; case 1: showSelectedFood(food_number_arr,food_count_arr,menu,food_all); break; case 2: countMoney(menu,food_number_arr,food_count_arr,food_all); break; default: cout<<"wrong choice,please chose again"<<endl; Sleep(2000); break; } cout<<"any nuber key(1~9) to go on,0 back: "; cin>>choice; if(0 == choice) break; } } void drawSubMenu() { cout<<"-----------------------------"<<endl; cout<<"\t 1 > Out put selected dishes"<<endl; cout<<"\t 2 > Calculation of consumption"<<endl; cout<<"\t 0 > Back"<<endl; cout<<"-----------------------------"<<endl; } void showSelectedFood(int arr1[],int arr2[],Menu menu[],int n) { cout<<"Number"<<"\t "<<"Kind"<<"\t "<<"FoodName"<<"\t "<<"Price"<<"\t"<<"Count"<<endl; for(int i = 0;i < n;i++) { for(int j = 0;j < 15;j++) { if(arr1[i] == menu[j].getNum()) { menu[j].setCount(arr2[i]); menu[j].drawSelectedMenu(); } } } } void countMoney(Menu menu[],int arr1[],int arr2[],int n) { int sum = 0; for(int i = 0;i < n;i++) { for(int j = 0;j < 15;j++) { if(arr1[i] == menu[j].getNum()) { menu[j].setCount(arr2[i]); sum += sum + menu[j].getPrice() * menu[j].getCount(); } } } cout<<"you shoule pay ¥:"<<sum<<endl; } // ============================MAIN function================================= void main() { int choice; // save user choice Menu menu[15]; // create 15 menu class object getFoodDataFromFile("menu.txt",menu,15); while(1) { drawMainMenu(); cout<<"chose menu number: "; cin>>choice; switch(choice) { case 0: break; case 1: showRecommendedFood(menu); break; case 2: showNewFood(menu); break; case 3: showAllFood(menu,15); break; case 4: selectFood(menu); drawMainMenu(); break; default: cout<<"wrong choice,please chose again"<<endl; Sleep(2000); break; } cout<<"any nuber key(1~9) to go on,0 exit: "; cin>>choice; if(0 == choice) break; } cout<<"**************************************************"<<endl; cout<<"\tThank you for your arraival"<<endl; cout<<"**************************************************"<<endl; return ;
}
<img src="http://img.blog.csdn.net/20140621203443984?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyMDM0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<img src="http://img.blog.csdn.net/20140621203514375?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyMDM0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<img src="http://img.blog.csdn.net/20140621203538328?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyMDM0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<img src="http://img.blog.csdn.net/20140621203556078?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyMDM0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<img src="http://img.blog.csdn.net/20140621203609734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyMDM0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<img src="http://img.blog.csdn.net/20140621203632546?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDAyMDM0MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />