c++大作业 超市货物管理系统

        这是一个只在小黑框里运行的C++程序,是大一时候的大作业,所以写的比较菜。我修改了当时的实验报告一同附了上来,供学弟学妹救急。

目录

题目说明及功能模块

程序的控制流程图或者结构图

下面是象征性的截图,具体演示还是自己写吧!

 源代码


题目说明及功能模块

(1) 实现描述超市的类Supermarket,其中定义了add开头的函数可以增加新的商品,app开头的函数可以增加已有商品的数量,按照商品名称卖出商品的sale开头的函数(如果商品现有数量少于卖出数量,则不能继续卖出商品,并给出提示信息),按照商品类别查询商品情况的函数Search,并显示查询结果(每类商品中有哪些商品,每种商品的名称和现有数量)。

(2) 定义商品类Goods,包含属性名称和商品现有数量,以及纯虚函数ShowMe

(3) 从基类Goods中派生日常用品类DailyGoods、食品类Food和家电类ElectricalAppliance,其中食品类商品拥有保质期属性,家电类商品拥有颜色属性,具体实现上述纯虚函数ShowMe,显示商品的名称、现有数量和食品类商品的保质期,以及家电类商品的颜色。

(4) 重载输入“>>”操作符,使得可以通过cin直接读入上述日常用品类、食品类和家电类的对象值。<<同理,写入文件或者展示时都可以一次性输出。

(5) 编写main函数,测试上述所要求的各种功能,即可以根据菜单命令增加、卖出和查询各类商品,其中的商品可以是日常用品、食品和家用电器。

程序的控制流程图或者结构图

 

 

下面是象征性的截图,具体演示还是自己写吧!

 

 源代码

#include<iostream>
#include<vector>
#include<string>
#include<fstream>
#include<stdlib.h>
#include<iomanip>
using namespace std;
class Goods {											//货物类(基类)
protected:
	string name;
	int number;
public:
	Goods() {}
	Goods(string Name, int Num) {
		name = Name;
		number = Num;
	}
	virtual void ShowMe() = 0;
	string getname() {								//取商品名称函数
		return name;
	}
	int getnumber() {								//取数量函数
		return number;
	}
	void add(Goods &a) {							//添加货物
		number += a.getnumber();
	}
	void min(Goods &a) {							//售出货物
		number -= a.getnumber();
	}
};
class DailyGoods :public Goods {							//日常用品类
public:
	DailyGoods() {};
	DailyGoods(string Name, int Num) :Goods(Name, Num) {
		name = Name;
		number = Num;
	}
	virtual void ShowMe();
	friend istream& operator >>(istream &cin, DailyGoods &a);
	friend ostream& operator <<(ostream &cout, DailyGoods &a);
	friend ostream& operator <<(ofstream &fout, DailyGoods &a);
};
class Food :public Goods {								//食物类
protected:
	string deadline;
public:
	Food() {};
	Food(string Name, int Num, string Deadline) :Goods(Name, Num) {
		name = Name;
		number = Num;
		deadline = Deadline;
	}
	virtual void ShowMe();
	string getdeadline() {
		return deadline;
	}
	friend istream& operator >>(istream &cin, Food &a);
	friend ostream& operator <<(ostream &cout, Food &a);
	friend ostream& operator <<(ofstream &fout, Food &a);
};
class ElectricalAppliance :public Goods {				//电器类
protected:
	string color;
public:
	ElectricalAppliance() {};
	ElectricalAppliance(string Name, int Num, string Color) :Goods(Name, Num) {
		name = Name;
		number = Num;
		color = Color;
	}
	virtual void ShowMe();
	string getcolor() {
		return color;
	}
	friend istream& operator >>(istream &cin, ElectricalAppliance &a);
	friend ostream& operator <<(ostream &cout, ElectricalAppliance &a);
	friend ostream& operator <<(ofstream &fout, ElectricalAppliance &a);
};
vector<DailyGoods> dailygoods;
vector<Food> food;
vector<ElectricalAppliance> electricalappliance;
istream& operator >>(istream &cin, DailyGoods &a) {				//输入输出符重载
	string Name;												//日用品重载
	int Num;
	cin >> Name >> Num;
	a.name = Name;
	a.number = Num;
	return cin;
}
ostream& operator <<(ostream &cout, DailyGoods &a) {
	cout.fill(' ');
	cout.setf(ios::left);
	cout.width(40);
	cout << a.name;
	cout.width(40);
	cout << a.number << endl;
	return cout;
}
ostream& operator <<(ofstream &fout, DailyGoods &a) {
	fout << a.name << " " << a.number << endl;
	return fout;
}
istream& operator >>(istream &cin, Food &a) {
	string Name, Deadline;										//食品类重载
	int Num;
	cin >> Name >> Deadline >> Num;
	a.name = Name;
	a.number = Num;
	a.deadline = Deadline;
	return cin;
}
ostream& operator <<(ostream &cout, Food &a) {
	cout.fill(' ');
	cout.setf(ios::left);
	cout.width(40);
	cout << a.name;
	cout.width(40);
	cout << a.deadline;
	cout.width(40);
	cout << a.number;
	return cout;
}
ostream& operator <<(ofstream &fout, Food &a) {
	fout << a.name << " " << a.number << "	" << a.deadline << endl;
	return fout;
}
istream& operator >>(istream &cin, ElectricalAppliance &a) {
	string Name, Color;											//电器类重载
	int Num;
	cin >> Name >> Color >> Num;
	a.name = Name;
	a.number = Num;
	a.color = Color;
	return cin;
}
ostream& operator <<(ostream &cout, ElectricalAppliance &a) {
	cout.fill(' ');
	cout.setf(ios::left);
	cout.width(40);
	cout << a.name;
	cout.width(40);
	cout << a.color;
	cout.width(40);
	cout << a.number;
	return cout;
}
ostream& operator <<(ofstream &fout, ElectricalAppliance &a) {
	fout << a.name << " " << a.number << "	" << a.color << endl;
	return fout;
}
//保存到文件
void saveFood() {												//保存食物
	ofstream fout;
	fout.open("Food.txt", ios::out);
	if (!fout) {
		cout << "食物类保存失败!" << endl;
		system("pause");
	}
	else {
		for (vector<Food>::iterator it = food.begin(); it != food.end(); it++) {
			fout << *it;
		}
		cout << "食物类已保存" << endl;
		system("pause");
		fout.close();
	}
}
void saveDailygoods() {											//保存日用品
	ofstream fout;
	fout.open("Dailygoods.txt", ios::out);
	if (!fout) {
		cout << "日用品保存失败!" << endl;
		system("pause");
	}
	else {
		for (vector<DailyGoods>::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
			fout << *it;
		}
		cout << "日用品已保存" << endl;
		system("pause");
		fout.close();
	}
}
void saveElectrical() {											//保存电器类
	ofstream fout;
	fout.open("Electricalappliance.txt", ios::out);
	if (!fout) {
		cout << "电器类保存失败!" << endl;
		system("pause");
	}
	else {
		for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
			fout << *it;
		}
		cout << "电器类已保存" << endl;
		system("pause");
		fout.close();
	}
}
//读取文件
void readDailygoods() {										//读取并展示日用品函数
	ifstream fin;
	string NAME;
	int NUM;
	fin.open("Dailygoods.txt", ios::in);
	if (!fin) {
		cout << "日用品类打开失败" << endl;
		system("pause");
	}
	else if (fin.peek() == EOF) {
		cout << "内容如下:" << endl;
		cout << "空" << endl;
		cout << endl << endl;
		system("pause");
		fin.close();
		return;
	}
	else {
		while (fin >> NAME >> NUM)
		{
			DailyGoods s(NAME, NUM);
			dailygoods.push_back(s);
		}
		cout << "内容如下:" << endl;
		for (vector<DailyGoods>::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
			cout << *it;
		}
		cout << endl << endl;
		fin.close();
	}
}
void readFood() {										//读取并展示食品函数
	ifstream fin;
	string NAME, DEADLINE;
	int NUM;
	fin.open("Food.txt", ios::in);
	if (!fin) {
		cout << "食品类打开失败" << endl;
		system("pause");
	}
	else if (fin.peek() == EOF) {
		cout << "内容如下:" << endl;
		cout << "空" << endl;
		cout << endl << endl;
		system("pause");
		fin.close();
		return;
	}
	else {
		while (fin >> NAME >> NUM >> DEADLINE)
		{
			Food s(NAME, NUM, DEADLINE);
			food.push_back(s);
		}
		cout << "内容如下:" << endl;
		for (vector<Food>::iterator it = food.begin(); it != food.end(); it++) {
			cout << *it;
		}
		cout << endl << endl;
		fin.close();
	}
}
void readElectrical() {										//读取并展示电器类函数
	ifstream fin;
	string NAME, COLOR;
	int NUM;
	fin.open("Electricalappliance.txt", ios::in);
	if (!fin) {
		cout << "电器类打开失败" << endl;
		system("pause");
	}
	else if (fin.peek() == EOF) {
		cout << "内容如下:" << endl;
		cout << "空" << endl;
		cout << endl << endl;
		system("pause");
		fin.close();
		return;
	}
	else {
		while (fin >> NAME >> NUM >> COLOR)
		{
			ElectricalAppliance s(NAME, NUM, COLOR);
			electricalappliance.push_back(s);
		}
		fin.close();
		cout << "内容如下:" << endl;
		for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
			cout << *it;
		}
		cout << endl << endl;
	}
}
//展示
void DailyGoods::ShowMe() {											//展示日用品
	ifstream fin;//input 读 //output 写    //cin   istream//file
	string NAME;
	int NUM;
	fin.open("Dailygoods.txt", ios::in);//方式    只读
	if (!fin) {
		cout << "日用品类列表还未建立" << endl;
		cout << "日用品类建立中..." << endl;
		ofstream fint;
		fint.open("Dailygoods.txt", ios::out);
		fint.close();
		cout << "日用品类已建立文件" << endl;
		system("pause");
	}
	else {
		while (fin >> NAME >> NUM)
		{
			DailyGoods s(NAME, NUM);
			dailygoods.push_back(s);
		}
		cout << "商品名称" << "\t\t\t\t" << "现有数量" << endl << endl;
		for (vector<DailyGoods>::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
			cout << *it;
		}
		system("pause");
		dailygoods.clear();
	}
	fin.close();
}
void Food::ShowMe() {											//展示食品类
	ifstream fin;
	string NAME, DEADLINE;
	int NUM;
	fin.open("Food.txt", ios::in);
	if (!fin) {
		cout << "食品类列表还未建立" << endl;
		cout << "食品类建立中..." << endl;
		ofstream fint;
		fint.open("Food.txt", ios::out);
		fint.close();
		cout << "食品类已建立文件" << endl;
		system("pause");
	}
	else if (fin.peek() == EOF) {
		cout << "空" << endl;
		system("pause");
		fin.close();
		return;
	}
	else {
		while (fin >> NAME >> NUM >> DEADLINE)
		{
			Food s(NAME, NUM, DEADLINE);
			food.push_back(s);
		}
		cout << "商品名称" << "\t\t\t\t" << "保质期" << "\t\t\t\t\t" << "现有数量" << endl << endl;
		for (vector<Food>::iterator it = food.begin(); it != food.end(); it++) {
			cout << *it;
		}
		system("pause");
		food.clear();
	}
	fin.close();
}
void ElectricalAppliance::ShowMe() {											//展示电器类
	ifstream fin;
	string NAME, COLOR;
	int NUM;
	fin.open("Electricalappliance.txt", ios::in);
	if (!fin) {
		cout << "电器类列表还未建立" << endl;
		cout << "电器类建立中..." << endl;
		ofstream fint;
		fint.open("Electricalappliance.txt", ios::out);
		fint.close();
		cout << "电器类已建立文件" << endl;
		system("pause");
	}
	else if (fin.peek() == EOF) {
		cout << "空" << endl;
		system("pause");
		fin.close();
		return;
	}
	else {
		while (fin >> NAME >> NUM >> COLOR)
		{
			ElectricalAppliance s(NAME, NUM, COLOR);
			electricalappliance.push_back(s);
		}
		cout << "电器名称" << "\t\t\t\t" << "颜色" << "\t\t\t\t\t" << "现有数量" << endl << endl;
		for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
			cout << *it;
		}
		system("pause");
		electricalappliance.clear();
	}
	fin.close();
}
//添加商品类别
void addDaily() {												//添加日常用品类
	readDailygoods();
	int open = 0;
	cout << "请输入货物名称、要添加的数量:" << endl;
	DailyGoods newdailygoods;
	cin >> newdailygoods;
	for (vector<DailyGoods>::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
		if (it->getname() == newdailygoods.getname()) {
			it->add(newdailygoods);
			cout << "仓库已有此商品,已更新数量" << endl;
			system("pause");
			open = 1;
			break;
		}
	}
	if (open == 0) {
		dailygoods.push_back(newdailygoods);
	}
	saveDailygoods();
	dailygoods.clear();
}
void addFood() {												//添加食品类
	readFood();
	int open = 0;
	cout << "请输入货物名称、食品保质期、要添加的数量" << endl;
	Food newfood;
	cin >> newfood;
	for (vector<Food>::iterator it = food.begin(); it != food.end(); it++) {
		if (it->getname() == newfood.getname() && it->getdeadline() == newfood.getdeadline()) {
			it->add(newfood);
			cout << "仓库已有此商品,已更新数量" << endl;
			system("pause");
			open = 1;
			break;
		}
	}
	if (open == 0) {
		food.push_back(newfood);
	}
	saveFood();
	food.clear();
}
void addElectrical() {												//添加电器
	readElectrical();
	int open = 0;
	cout << "请输入商品名称、电器的颜色、要添加的数量:" << endl;
	ElectricalAppliance newelectricalappliance;
	cin >> newelectricalappliance;
	for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
		if (it->getname() == newelectricalappliance.getname() && it->getcolor() == newelectricalappliance.getcolor()) {
			it->add(newelectricalappliance);
			cout << "仓库已有此商品,已更新数量" << endl;
			system("pause");
			open = 1;
			break;
		}
	}
	if (open == 0) {
		electricalappliance.push_back(newelectricalappliance);
	}
	saveElectrical();
	electricalappliance.clear();
}
//上货
void loadDaily() {													//日用品类上货
	DailyGoods appointeddailygoods;
	int result = 0;
	system("cls");
	cout << "请输入货物名称、要添加的数量:" << endl;
	readDailygoods();
	cin >> appointeddailygoods;
	for (vector<DailyGoods>::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
		if (it->getname() == appointeddailygoods.getname()) {
			it->add(appointeddailygoods);
			result = 1;
		}
	}
	if (result == 0) {
		cout << "未查询到商品" << endl;
		system("pause");
		system("cls");
	}
	saveDailygoods();
	dailygoods.clear();
}
void loadFood() {													//食品类上货
	string NAME, DEADLINE;
	int result = 0, NUMBER;
	system("pause");
	cout << "请输入食品名称、保质期、要添加的数量" << endl;
	readFood();
	cin >> NAME >> DEADLINE >> NUMBER;
	Food appointedfood(NAME, NUMBER, DEADLINE);
	for (vector<Food>::iterator it = food.begin(); it != food.end(); it++) {
		if (it->getname() == appointedfood.getname() && it->getdeadline() == appointedfood.getdeadline()) {
			it->add(appointedfood);
			result = 1;
		}
	}
	if (result == 0) {
		cout << "未查询到商品" << endl;
		system("pause");
		system("cls");
	}
	saveFood();
	food.clear();
}
void loadElectrical() {													//电器类上货
	string NAME, COLOR;
	int NUMBER;
	int result = 0;
	system("pause");
	cout << "请输入电器名称、电器颜色、要添加的数量" << endl;
	readElectrical();
	cin >> NAME >> COLOR >> NUMBER;
	ElectricalAppliance appointedelectrical(NAME, NUMBER, COLOR);
	for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
		if (it->getname() == appointedelectrical.getname() && it->getcolor() == appointedelectrical.getcolor()) {
			it->add(appointedelectrical);
			result = 1;
		}
	}
	if (result == 0) {
		cout << "未查询到商品" << endl;
		system("pause");
		system("cls");
	}
	saveElectrical();
	electricalappliance.clear();
}
//出售
void saleDaily() {									//售出日用品
	DailyGoods appointeddailygoods;
	int result = 0;
	cout << "请输入货物名称、要卖出的数量:" << endl;
	readDailygoods();
	cin >> appointeddailygoods;
	for (vector<DailyGoods> ::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
		if (it->getname() == appointeddailygoods.getname()) {
			if (appointeddailygoods.getnumber() > it->getnumber()) {
				cout << "没有充足数量的商品!" << endl;
				result = 1;
				system("pause");
			}
			else {
				it->min(appointeddailygoods);
				result = 1;
			}
		}
	}
	if (result == 0) {
		cout << "未查询到商品" << endl;
		system("pause");
		system("cls");
	}
	saveDailygoods();
	dailygoods.clear();
}
void saleFood() {									//售出食品
	Food appointedfood;
	int result = 0;
	cout << "请输入食品名称、要卖出的数量、食物保质期:" << endl;
	readFood();
	cin >> appointedfood;
	for (vector <Food>::iterator it = food.begin(); it != food.end(); it++) {
		if (it->getname() == appointedfood.getname()) {
			if (appointedfood.getnumber() > it->getnumber()) {
				cout << "没有充足数量的商品" << endl;
				result = 1;
				system("pause");
			}
			else {
				it->min(appointedfood);
				result = 1;
			}
		}
	}
	if (result == 0) {
		cout << "未查询到商品" << endl;
		system("pause");
		system("cls");
	}
	saveFood();
	food.clear();
}
void saleElectrical() {									//售出食品
	ElectricalAppliance appointedelectrical;
	int result = 0;
	cout << "请输入电器名称、要卖出的数量、电器颜色:" << endl;
	readElectrical();
	cin >> appointedelectrical;
	for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
		if (it->getname() == appointedelectrical.getname()) {
			if (appointedelectrical.getnumber() > it->getnumber()) {
				cout << "没有充足数量的商品" << endl;
				result = 1;
				system("pause");
			}
			else {
				it->min(appointedelectrical);
				result = 1;
			}
		}
	}
	if (result == 0) {
		cout << "未查询到商品" << endl;
		system("pause");
		system("cls");
	}
	saveElectrical();
	electricalappliance.clear();
}
//查询
void searchDaily() {								//搜索日用品
	string appointeddailygoods;
	int result = 0;
	system("cls");
	readDailygoods();
	cout << "请输入货物名称" << endl;
	cin >> appointeddailygoods;
	for (vector<DailyGoods>::iterator it = dailygoods.begin(); it != dailygoods.end(); it++) {
		if (it->getname() == appointeddailygoods) {
			cout << it->getname() << "\t" << it->getnumber() << " 件\t" << endl;
			result = 1;
		}
	}
	if (result == 0) {
		cout << "未搜索到商品" << endl;
		system("pause");
	}
	saveDailygoods();
	dailygoods.clear();
}
void searchFood() {									//搜索食品
	string appointedfood;
	int result = 0;
	system("cls");
	readFood();
	cout << "请输入食物名称" << endl;
	cin >> appointedfood;
	for (vector<Food>::iterator it = food.begin(); it != food.end(); it++) {
		if (it->getname() == appointedfood) {
			cout << it->getname() << "\t" << it->getnumber() << " 件\t" << it->getdeadline() << "前食用" << endl;
			result = 1;
		}
	}
	if (result == 0) {
		cout << "未搜索到商品" << endl;
		system("pause");
	}
	saveFood();
	food.clear();
}
void searchElectrical() {									//搜索电器
	string appointedelectrical;
	int result = 0;
	system("cls");
	readElectrical();
	cout << "请输入电器名称" << endl;
	cin >> appointedelectrical;
	for (vector<ElectricalAppliance>::iterator it = electricalappliance.begin(); it != electricalappliance.end(); it++) {
		if (it->getname() == appointedelectrical) {
			cout << it->getname() << "\t" << it->getnumber() << " 件\t" << it->getcolor() << " 色" << endl;
			result = 1;
		}
	}
	if (result == 0) {
		cout << "未搜索到商品" << endl;
		system("pause");
	}
	saveElectrical();
	electricalappliance.clear();
}
//主菜单界面
void Menu() {
	cout.unsetf(ios::left);
	cout << endl;
	cout << setw(65) << "超市货物管理系统" << endl;
	cout << endl << endl << endl;
	cout << setw(50) << "请选择你要进行的操作:" << endl;
	cout << setw(64) << "1.查看商品情况" << endl;
	cout << setw(64) << "2.更新商品信息" << endl;
	cout << setw(64) << "3.查找商品信息" << endl;
	cout << setw(60) << "0.退出系统" << endl << endl;
}
//更新商品界面
void Menu2() {
	cout.unsetf(ios::left);
	cout << endl;
	cout << setw(63) << "更新商品信息" << endl;
	cout << endl << endl << endl;
	cout << setw(50) << "请选择你要进行的操作:" << endl;
	cout << setw(63) << "1.添加商品类" << endl;
	cout << setw(65) << "2.添加商品数量" << endl;
	cout << setw(61) << "3.出售商品" << endl;
	cout << setw(57) << "0.返回" << endl;
}
//展示商品界面
void Menu3() {
	cout.unsetf(ios::left);
	cout << endl;
	cout << setw(67) << "请输入你要查看的商品类型:" << endl;
	cout << endl << endl;
	cout << setw(60) << "1.日用品类" << endl;
	cout << setw(58) << "2.食品类" << endl;
	cout << setw(58) << "3.电器类" << endl;
	cout << setw(56) << "0.返回" << endl;
}
//查找商品界面
void Menu4() {
	cout.unsetf(ios::left);
	cout << endl;
	cout << setw(67) << "请输入你要查找商品的所属类型:" << endl;
	cout << endl << endl;
	cout << setw(60) << "1.日用品类" << endl;
	cout << setw(58) << "2.食品类" << endl;
	cout << setw(58) << "3.电器类" << endl;
	cout << setw(56) << "0.返回" << endl;
}
//功能类
class Supermarket {									//调用功能函数
public:
	//添加新商品
	void Add() {									//添加商品类函数
		int choice4;
		while (1) {
			cout << "请输入要添加商品的类别:\n\n1 ->日常用品\n2 ->食品\n3 ->电器类\n0->返回" << endl;
			cin >> choice4;
			switch (choice4)
			{
			case 1:
				addDaily();
				cout << "添加完成" << endl;
				return;
			case 2:
				addFood();
				cout << "添加完成" << endl;
				return;
			case 3:
				addElectrical();
				cout << "添加完成" << endl;
				return;
			case 0:
				return;
			default:
				cout << "输入有误,请选择1、2、3、0输入" << endl;
				system("pause");
				system("cls");
				break;
			}
		}
	}
	//商品上货
	void Load() {									//商品上货
		int choice5;
		while (1) {
			cout << "请输入要补充商品的类别: 1 ->日常用品\n2 ->食品\n3 ->电器类\n0->返回" << endl;
			cin >> choice5;
			switch (choice5)
			{
			case 1:
				loadDaily();
				cout << "上货完成" << endl;
				system("pause");
				return;
			case 2:
				loadFood();
				cout << "上货完成" << endl;
				system("pause");
				return;
			case 3:
				loadElectrical();
				cout << "上货完成" << endl;
				system("pause");
				return;
			case 0:
				return;
			default:
				cout << "请选择已有选项!!" << endl;
				system("pause");
				system("cls");
				break;
			}
		}
	};
	//出售商品
	void Sale() {									//售卖商品函数
		int choice6;
		while (1) {
			cout << "请输入要售卖商品的类别: \n\n1->日常用品\n2 ->食品\n3 ->电器类\n0->返回" << endl;
			cin >> choice6;
			switch (choice6)
			{
			case 1:
				saleDaily();
				cout << "出售完成" << endl;
				return;
			case 2:
				saleFood();
				cout << "出售完成" << endl;
				return;
			case 3:
				saleElectrical();
				cout << "出售完成" << endl;
				return;
			case 0:
				return;
			default:
				cout << "请选择已有选项!!" << endl;
				system("pause");
				system("cls");
				break;
			}
		}
	}
	//查询商品
	void Search() {									//查询商品函数
		while (1) {
			system("cls");
			Menu4();
			string choice6;
			cin >> choice6;
			if (choice6 == "1") {											//搜索日用品
				searchDaily();
			}
			else if (choice6 == "2") {									//搜索食物
				searchFood();
			}
			else if (choice6 == "3") {									//搜索电器
				searchElectrical();
			}
			else if (choice6 == "0") {									//返回主界面
				return;
			}
			else {														//重新选择展示
				cout << "请输入已有选项!!" << endl;
				system("pause");
			}
		}
	}
};
int main() {				/*主函数*/
	int first = 0;
	string choice;
	DailyGoods good1;
	Food good2;
	ElectricalAppliance good3;
	Menu();												//主界面
	cin >> choice;
	do
	{
		if (first != 0) {
			system("cls");
			Menu();
			cin >> choice;
		}
		Supermarket supermarket;
		while (choice == "1") {						//展示商品情况
			system("cls");
			Menu3();
			string choice3;
			cin >> choice3;
			if (choice3 == "1") {											//展示日用品
				good1.ShowMe();
			}
			else if (choice3 == "2") {									//展示食物
				good2.ShowMe();
			}
			else if (choice3 == "3") {									//展示电器
				good3.ShowMe();
			}
			else if (choice3 == "0") {									//返回主界面
				break;
			}
			else {														//重新选择展示
				cout << "请输入已有选项!!" << endl;
			}
		}
		while (choice == "2") {						//更新商品信息
			system("cls");
			Menu2();
			string choice2;
			cin >> choice2;
			if (choice2 == "1") {											//添加商品类
				system("cls");
				supermarket.Add();
			}
			else if (choice2 == "2") {									//商品上货
				system("cls");
				supermarket.Load();
			}
			else if (choice2 == "3") {									//售出商品
				system("cls");
				supermarket.Sale();
			}
			else if (choice2 == "0") {									//返回主界面
				break;
			}
			else {														//重新选择展示
				cout << "请输入已有选项!!" << endl;
				system("pause");
			}
		}
		while (choice == "3") {			//查找商品
			supermarket.Search();
			break;
		}
		first++;
	} while (choice != "0");
	cout << "退出系统" << endl;
	return 0;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值