c++实现餐厅点餐功能

还没来得及学习太多,保存着,等慢慢补充吧。
#include "iostream"
#include "stdlib.h"
#include "iomanip"
using namespace std;
const int NUM = 3;
class Guest;
class Food
{
private:
	int Fnum;                  //菜编号
	char Fname[10];			  // 菜名
	char Fclasses[10];        // 菜类别
	double Fprice;            //菜单价
public:
	Food(char *fclasses = NULL, int fnum = 0, char *fname = NULL,  double fprice = 0) {};
	friend class Shop;
	friend class Guest;
};
class Shop
{
private:
	Food f[NUM];          //餐厅食物样数
	int num;              //实际样数
public:
	Shop();
	void Food_delete(int fnum);
	void Food_amend(int fnum);
	void Food_find(int fnum);
	void Show_menu();
	friend class Guest;
};
class Guest
{
private:
	int Tnum;                     //桌号
	Food g_food[NUM];            //所点菜的信息
	int f_num[NUM];             //份数
	int S;                      //点餐的菜的样数
public:
	Guest(Shop p,int tnum = 0, int num_g = 0);
	void account();            //结账
};
void menu()
{
	cout << "........请选择......" << endl;
	cout << "---------1、删除商品---------" << endl;
	cout << "---------2、修改商品---------" << endl;
	cout << "---------3、查询商品---------" << endl;
	cout << "---------0、退出---------" << endl;
	cout << endl;
}
void out_menu()
{
	cout << "-----------请  选  择-----------" << endl;
	cout << "-----------1、商店操作----------" << endl;
	cout << "-----------2、顾客操作----------" << endl;
	cout << "-----------0、退   出-----------" << endl;
}
int main()
{
	int n,m;
	int flag = 1,out_flag=1;
	Shop s;
	out_menu();
	while (out_flag)
	{
		cout << "请输入你的选择" << endl;
		cin >> n;
		int flag = 1;
		switch (n)
		{
		case 1:
		{
			s.Show_menu();
			menu();
			while (flag)
			{
				cout << "请输入你的选择" << endl;
				cin >> m;
				switch (m)
				{
				case 1:
				{
					int num;
					cout << "请输入要删除商品的编号" << endl;
					cin >> num;
					s.Food_delete(num);
					s.Show_menu();
					break;
				}
				case 2:
				{
					int num;
					cout << "请输入要修改商品的编号" << endl;
					cin >> num;
					s.Food_amend(num);
					s.Show_menu();
					break;
				}
				case 3:
				{
					int num;
					cout << "请输入要查询商品的编号" << endl;
					cin >> num;
					s.Food_find(num);
					s.Show_menu();
					break;
				}
				case 0:
				{
					out_menu();
					flag = 0;
					break;
				}
				}
			}
			break;	
		}
		case 2:
		{
			Guest g(s);
			g.account();
			out_menu();
			break;
		}
		case 0:
		{
			out_flag = 0;
			break;
		}
		}
	}
system("pause");
return 0;
}
/*Food::Food(int fnum, char *fname, char *fclasses, double fprice)
{

}*/
Shop::Shop()
{
	cout << "请输入类别、编号、名称、单价(用空格隔开)" << endl;
	for (int i = 0; i < NUM; i++)
	{
		cin >> f[i].Fclasses >> f[i].Fnum >> f[i].Fname >> f[i].Fprice;
	}
	num = NUM;
}
void Shop::Food_delete(int fnum)
{
	num--;
	for (int i = 0; i < num; i++)
	{
		if (f[i].Fnum ==fnum)
		{
			for (int j = i; j < num; j++)
			{
				f[j] = f[j + 1];
			}
		}
	}
}
void Shop::Food_amend(int fnum)
{
	for (int i = 0; i < num; i++)
	{
		if (f[i].Fnum == fnum)
		{
			double y;
			cout << "请输入新的价格" << endl;
			cin >> y;
			f[i].Fprice = y;
		}
	}
}
void Shop::Food_find(int fnum)
{
	for (int i = 0; i < num; i++)
	{
		if (f[i].Fnum == fnum)
		{
			cout << "类别" << "编号" << "菜名" << "价格" << endl;
			cout <> Tnum;
	cout << "请输入点菜的样数" << endl;
	cin >>S;

	for (int i = 0; i < S; i++)
	{
		cout << "请输入商品编号" << endl;
		cin >>j;
		for (int k = 0; k < p.num; k++)
		{
			if (j == p.f[k].Fnum)
				g_food[i] = p.f[k];
		}
		cout << "请输入份数:" << endl;
		cin >> num_g;
		f_num[i] = num_g;
	}

}
void Guest::account()
{
	double sum=0;
	char select;
	cout << "是否为会员 y:是  n:不是 " << endl;
	cin >> select;
	cout << "----------消费单-----------" << endl;
	cout << "桌号:" << Tnum << endl;
	cout << "菜名" << setw(8) << "数量" << setw(8) << "价格" << endl;
	for (int i = 0; i < S; i++)
	{
		cout << g_food[i].Fname << setw(8) << f_num[i] << setw(4) << g_food[i].Fprice << endl;
	}
	if (select == 'n' || select == 'N')
	{
		for (int i = 0; i < S; i++)
		{
			sum = sum + f_num[i] * g_food[i].Fprice;
		}
		cout << "总价:" << sum << endl;
	}
	else if (select == 'y' || select == 'Y')
	{
		for (int i = 0; i < S; i++)
		{
			sum = sum + f_num[i] * g_food[i].Fprice;
		}
		cout << "总价:" << sum << endl;
		cout << "折后价:" << sum*0.8 << endl;
	}
}

你可能感兴趣的:(c++实现餐厅点餐功能)