首页 > 其他分享 >对于超市系统功能的完善

对于超市系统功能的完善

时间:2024-03-06 20:23:41浏览次数:19  
标签:system 完善 cout int 功能 超市 cls store getchar

来源:学姐在大一下学期的期末大作业,超市系统
运行环境:VScode
运行结果截图






程序代码

点击查看代码
#include<iostream>
#include"box.h"
using namespace std;

int main() {
	set();
	huanying();
	huansong();
	get();
}
#include<iostream>
#include <stdlib.h>
#include<vector>
#include"DailyGoods.h"
#include"Food.h"
#include"ElectricalAppliance.h"
#include"Goods.h"
#include"Supermarket.h"
using namespace std;

int DailyGoods::count1 = 0;           //日用类商品样数
int Food::count2 = 0;                 //食物类商品样数
int ElectricalAppliance::count3 = 0;  //家电类商品样数

extern vector<DailyGoods> goods1;   // 超市的日用商品库存
extern vector<Food> goods2;
extern vector<ElectricalAppliance> goods3;
vector<Supermarket> store;

string Supermarket::get_name() {
    return name;
}
Supermarket::Supermarket(string s):name(s){
    DailyGoods a("模板",0);
    Food b("模板",0,0);
    ElectricalAppliance c("模板",0,"模板");
    goods1.push_back(a);
    goods2.emplace_back(b);
    goods3.emplace_back(c);
}

void Supermarket::Sale() {               // 卖出商品
    char m;
    xuanze:
     cout << "请选择要卖出的商品类别:" << endl;
     cout << "1.日用商品类" << endl;
     cout << "2.食物类" << endl;
     cout << "3.家电类" << endl;
     cout << "请输入:" << endl;
     int x = 0; cin >> x;
     switch (x) {
     case(1):
     {
         string s = "";
         int amount = 0, b = 0;
         int flag = 1;
         cout << "请输入商品名称:" << '\t';
         cin >> s; m=getchar();
         b = search01(s);
         if (b == 0) {
             cout << endl << "该商品不存在,请重新确认商品类别!" << endl;
             system("pause");
             system("cls");
             goto xuanze;
         }
      wojiuyaozhege1:
         cout << "请输入卖出的商品数量:" << '\t';
         cin >> amount; m=getchar();
         if (goods1[b].quantity >= amount) {
             goods1[b].quantity -= amount;
             cout << "成功卖出商品:" << goods1[b].name << endl;
         }
         else {
             cout << "商品"<< goods1[b].name<<"剩余量为:"<<goods1[b].quantity << ",库存不足,无法卖出!"  << endl;
         }
         cout << "若继续买出该商品,请按“1”;若重新选择商品,请按“2”;若退出商品买出界面,请按此外任意建:" << '\t';
         cin >> x; m=getchar();
         if (x == 1) {
             //system("cls");
             goto wojiuyaozhege1;
         }
         else if (x == 2) {
             system("cls");
             goto xuanze;
         }
         else {
             system("cls");
             break;
         }
     }
     case(2):
     {
         string s = "";
         int amount = 0, b = 0;
         int flag = 1;
         cout << "请输入商品名称:" << '\t';
         cin >> s; m=getchar();
         b = search02(s);
         if (b == 0) {
             cout << endl << "该商品不存在,请重新确认商品类别!" << endl;
             system("pause");
             system("cls");
             goto xuanze;
         }
     wojiuyaozhege2:
         cout << "请输入卖出的商品数量:" << '\t';
         cin >> amount; m=getchar();
         if (goods2[b].quantity >= amount) {
             goods2[b].quantity -= amount;
             cout << "成功卖出商品:" << goods2[b].name << endl;
         }
         else {
             cout << "商品" << goods2[b].name << "剩余量为:" <<goods2[b].quantity << ",库存不足,无法卖出!" << endl;
         }
         cout << "若继续卖出该商品,请按“1”;若重新选择商品,请按“2”;若退出商品卖出界面,请按此外任意建:" << '\t';
         cin >> x; m=getchar();
         if (x == 1) {
             system("cls");
             goto wojiuyaozhege2;
         }
         else if (x == 2) {
            // system("cls");
             goto xuanze;
         }
         else {
             system("cls");
             break;
         }
     }
     case(3):
     {
         string s = "";
         int amount = 0, b = 0;
         int flag = 1;
         cout << "请输入商品名称:" << '\t';
         cin >> s; m=getchar();
         b = search03(s);
         if (b == 0) {
             cout << endl << "该商品不存在,请重新确认商品类别!" << endl;
             system("pause");
             system("cls");
             goto xuanze;
         }
     wojiuyaozhege3:
         cout << "请输入卖出的商品数量:" << '\t';
         cin >> amount; m=getchar();
         if (goods3[b].quantity >= amount) {
             goods3[b].quantity -= amount;
             cout << "成功卖出商品:" << goods3[b].name << endl;
         }
         else {
             cout << "商品" << goods3[b].name << "剩余量为:" << goods3[b].quantity << ",库存不足,无法卖出!" << endl;
         }
         cout << "若继续卖出该商品,请按“1”;若重新选择商品,请按“2”;若退出商品卖出界面,请按此外任意建:" << '\t';
         cin >> x; m=getchar();
         if (x == 1) {
             system("cls");
             goto wojiuyaozhege3;
         }
         else if (x == 2) {
             //system("cls");
             goto xuanze;
         }
         else {
             system("cls");
             break;
         }
     }
     default:
         cout << "输入错误,请重新输入!";
     }
}

int Supermarket::search01(string s) {
    if (goods1.size() == 0) return 0;
     int i;
     for (i = 0; i < goods1.size(); i++)
         if (goods1[i].name == s) break;
     if (i < goods1.size()) return i;
     else return 0;
 }
int Supermarket::search02(string s) {
    if (goods2.size() == 0) return 0;
     int i;
     for (i = 0; i < goods2.size(); i++)
         if (goods2[i].name == s) break;
     if (i < goods2.size()) return i;
     else return 0;
 }
int Supermarket::search03(string s) {
    if (goods3.size() == 0) return 0;
     int i;
     for (i = 0; i < goods1.size(); i++)
         if (goods3[i].name == s) break;
     if (i < goods3.size()) return i;
     else return 0;
 }

void Supermarket::Search() {                 // 查询商品情况
    char m;
xuanze:
    cout << "请选择要查询的商品类别:" << endl;
    cout << "1.日用商品类" << endl;
    cout << "2.食物类" << endl;
    cout << "3.家电类" << endl;
    cout << "4.返回上一界面" << endl;
    cout << "请输入:" << endl;
    int x = 0;
    cin >> x; m=getchar();
    switch (x) {
    case(1):
        if (goods1.size() == 1) cout << "----------当前类无商品!----------" << endl;
        else {
            cout << "--------以下是超市" <<name<<"的所有日日常用品类商品--------"<< endl;
            cout << "当前日常用品类商品总数为:" <<goods1.size()-1<< endl;
            for (int i = 1; i < goods1.size(); i++)
            {
                goods1[i].ShowMe(); cout << endl;
            }
            cout << "----------查询完毕!----------" << endl;
        }
        cout << "若继续查询,请按“1”,若结束查询,请按此外任意键:" << endl;
        cin >> x; m=getchar();
        if (x == 1) {
            //system("pause");
            system("cls");
            goto xuanze;
        }
        else {
            system("cls");
            break;
        }
    case(2):
        if (goods2.size() == 1) cout << "----------当前类无商品!----------" << endl;
        else {
            cout << "--------以下是超市" << name << "的所有食物类商品--------" << endl;
            cout << "当前食物类商品总数为:" << goods2.size() - 1 << endl;
            for (int i = 1; i < goods2.size(); i++)
            {
                goods2[i].ShowMe(); cout << endl;
            }
            cout << "----------查询完毕!----------" << endl;
        }
        cout << "若继续查询,请按“1”,若结束查询,请按此外任意键:" << endl;
        cin >> x; m=getchar();
        if (x == 1)
        {
            //system("pause");
            system("cls");
            goto xuanze;
        }
        else {
            system("cls");
            break;
        }
    case(3):
        if (goods3.size() == 1) cout << "----------当前类无商品!----------" << endl;
        else {
            cout << "--------以下是超市" << name << "的所有电器类商品--------" << endl;
            cout << "当前电器类商品总数为:" << goods3.size() - 1 << endl;
            for (int i = 1; i < goods3.size(); i++)
            {
                goods3[i].ShowMe(); cout << endl;
            }
            cout << "----------查询完毕!----------" << endl;
        }
        cout << "若继续查询,请按“1”,若结束查询,请按此外任意键:" << endl;
        cin >> x; m=getchar();
        if (x == 1) {
            //system("pause");
            system("cls");
            goto xuanze;
        }
        else {
            system("cls");
            break;
        }
    default:
        cout << "输入错误,请重新输入!" << endl;
        goto xuanze;
    }
}
void Supermarket::Add() {             // 增加商品
    char m;
    caidan1:
    cout << "请按需求选择: " << endl;
    cout << "1.增加商品" << endl;
    cout << "2.增加商品数量" << endl;
    cout << "3.返回上一界面" << endl;
    cout << "请输入:" << endl;
    int x;
    cin >> x; m=getchar();
    switch (x) {
    case(1):
        caidan2:
        cout << "请选择要增加的商品类别: " << endl;
        cout << "1.日用商品类" << endl;
        cout << "2.食物类" << endl;
        cout << "3.家电类" << endl;
        cout << "4.返回上一界面" << endl;
        cin >> x; m=getchar();
        switch (x) {
        case(1):
        {
            DailyGoods d;
            cin >> d;
            int p = search01(d.name);
            if (p) {
                cout << "该商品已存在,不可重复添加!" << endl << "目前该商品的剩余量为";
                cout<< goods1[p].quantity << endl;
                cout << "若继续添加其数量,请按“1”,若停止请按此外任意键:";
                int q; cin >> q; m = getchar();
                if (q != 1) goto caidan2;
                else {
                    system("cls");
                    goto caidan1;
                }
            }
            else {
                goods1.push_back(d);
                DailyGoods::count1++;
                cout << "添加成功!" << endl;
            }
            cout << "若继续添加,请按“1”,如果直接退出添加界面,请按此外任意键:" << endl;
            cin >> x; m=getchar();
            if (x == 1) {
                system("cls");
                goto caidan1;
            }
            else {
                system("cls");
                break;
            }
        }
        case(2):
        {
            Food b;
            cin >> b;
            int p = search02(b.name);
            if (p) {
                cout << "该商品已存在,不可重复添加!" << endl << "目前该商品的剩余量为";
                cout << goods2[p].quantity << endl;
                cout << "若继续添加其数量,请按“1”,若停止请按此外任意键:";
                int q; cin >> q; m = getchar();
                if (q != 1) goto caidan2;
                else {
                    system("cls");
                    goto caidan1;
                }
            }
            else {
                goods2.push_back(b);
                Food::count2++;
                cout << "添加成功!" << endl;
            }
            cout << "若继续添加,请按“1”,如果直接退出添加界面,请按此外任意键:" << endl;
            cin >> x; m=getchar();
            if (x == 1) {
                system("cls");
                goto caidan1;
            }
            else {
                system("cls");
                break;
            }
        }
        case(3):
        {
            ElectricalAppliance c;
            cin >> c;
            int p = search03(c.name);
            if (p) {
                cout << "该商品已存在,不可重复添加!" << endl << "目前该商品的剩余量为";
                cout << goods3[p].quantity << endl;
                cout << "若继续添加其数量,请按“1”,若停止请按此外任意键:";
                int q; cin >> q; m = getchar();
                if (q != 1) goto caidan2;
                else {
                    system("cls");
                    goto caidan1;
                }
            }
            else {
                goods3.emplace_back(c);
                ElectricalAppliance::count3++;
                cout << "添加成功!" << endl;
            }
            cout << "若继续添加,请按“1”,如果直接退出添加界面,请按此外任意键:" << endl;
            cin >> x; m=getchar();
            if (x == 1) {
                system("cls");
                goto caidan1;
            }
            else {
                system("cls");
                break;
            }
        }
        case(4):
            //system("pause");
            system("cls");
            goto caidan1;
        default:
            cout << "输入错误,请重新输入!";
            goto caidan2;
        }
        goto caidan1;
    default:
        cout << "输入错误,请重新输入!";
        goto caidan1;
    }
}
#include"Goods.h"
#include<iostream>
#include<string>
#include "Food.h"
#include"Supermarket.h"

using namespace std;

istream& operator >>(istream &is, Goods& goods){
    char m;
    cout << "请输入商品名称: " << endl;
    is >> goods.name; m=getchar();
    cout << "请输入商品数量: " << endl;
    is >> goods.quantity; m=getchar();
    return is;
}
#include<iostream>
#include"Food.h"
#include<vector>
using namespace std;


void Food::ShowMe(){
    cout << "商品名称:" << name << endl;
    cout << "商品现有数量:" << quantity << endl;
    cout << "保质期:" << shelfLife << " 天" << endl;
}
istream& operator >>(istream& is, Food& food) {
    char m;
    cout << "请输入商品名称: " << endl;
    is >> food.name; m=getchar();
    cout << "请输入商品数量: " << endl;
    is >> food.quantity;m=getchar();
    cout << "请输入商品保质期(单位/天): " << endl;
    is >> food.shelfLife;m=getchar();
    return is;
}
ostream& operator<<(ostream& output, Food& food) {
    output << "商品名称:" << food.name << endl;
    output << "商品现有数量:" << food.quantity << endl;
    output << "保质期:" << food.shelfLife << " 天" << endl;
    return output;
}
#include"ElectricalAppliance.h"
#include<iostream>
#include<vector>
using namespace std;

void ElectricalAppliance::ShowMe(){
    cout << "商品名称:" << name << endl;
    cout << "商品现有数量:" << quantity << endl;
    cout << "颜色:" << color << endl;
}
istream& operator >>(istream& is, ElectricalAppliance& appliance) {
    char m;
    cout << "请输入商品名称: " << endl;
    is >> appliance.name; m=getchar();
    cout << "请输入商品数量: " << endl;
    is >> appliance.quantity; m=getchar();
    cout << "请输入商品颜色: " << endl;
    is >> appliance.color; m=getchar();
    return is;
}
ostream& operator<<(ostream& output, ElectricalAppliance& appliance) {
    output << "商品名称:" << appliance.name << endl;
    output << "商品现有数量:" << appliance.quantity << endl;
    output << "颜色:" << appliance.color << endl;
    return output;
}
#include<iostream>
#include <stdlib.h >
#include <windows.h>
#include<string>
#include<vector>
#include<fstream>
#include"Supermarket.h"
#include"Food.h"
#include"box.h"
using namespace std;

extern vector<Supermarket> store;

int search_store(string s) {
	int i;
	for (i = 0; i < store.size(); i++) {
		if (s == store[i].name) break;
	}
	if (i < store.size()) return i;
	else return 0;
}
void huansong() {
	cout << "----------***感谢您的使用!***----------" << endl;
}
/*void Buy() {
	Supermarket a;
	cout << "请输入您所买商品的名称: " << endl;
	string s;
	cin >> s;getchar();
	cout << "请输入您要购买的数量: " << endl;
	int n = 0;
	cin >> n;getchar();
	a.Sale(s,n);
}*/

void set() {
	Supermarket w("模板");
	store.push_back(w);
	ifstream ifs;
	ifs.open("商品.text", ios::in);
	int n=0,a=0,b=0,c=0;
	ifs >> n;
	for (int i = 1; i < n; i++) {
		string y;ifs >> y;
		Supermarket w(y);
		ifs >> a ;
		DailyGoods::count1 = a;
		for (int j = 1; j < a; j++)
		{
			string s; int x;
			ifs >> s;
			ifs >>x;
			DailyGoods a(s, x);
			w.goods1.push_back(a);
		}
		ifs >>b;
		Food::count2 = b;
		for (int j = 1; j < b; j++)
		{
			string s; int x, h;
			ifs >>s;
			ifs >>x;
			ifs>>h;
			Food a(s, x, h);
			w.goods2.push_back(a);
		}
		ifs >> c;
		ElectricalAppliance::count3 = c;
		for (int j = 1; j < c; j++)
		{
			string s, l; int x;
			ifs >>s;
			ifs >>x;
			ifs >>l;
			ElectricalAppliance a(s, x, l);
			w.goods3.push_back(a);
		}
		store.push_back(w);
	}
	ifs.close();
}

void get() {
	ofstream ofs;
	ofs.open("商品.text", ios::out);
	ofs << store.size() << endl;
	for (int i = 1; i < store.size(); i++) {
		ofs << store[i].name << endl;
		ofs << store[i].goods1.size() << endl;
		for (int j = 1; j < store[i].goods1.size(); j++)
		{
			ofs << store[i].goods1[j].name<<endl;
			ofs << store[i].goods1[j].quantity << endl;
		}
		ofs << store[i].goods2.size() << endl;
		for (int j = 1; j < store[i].goods2.size(); j++)
		{
			ofs << store[i].goods2[j].name << endl;
			ofs << store[i].goods2[j].quantity << endl;
			ofs << store[i].goods2[j].shelfLife << endl;
		}
		ofs << store[i].goods3.size() << endl;
		for (int j = 1; j < store[i].goods3.size(); j++)
		{
			ofs << store[i].goods3[j].name << endl;
			ofs << store[i].goods3[j].quantity << endl;
			ofs << store[i].goods3[j].color << endl;
		}
	}
	ofs.close();
}

void add_store() {
	char m;
	cout << "----------***欢迎创建您的超市***-----------" << endl;
	cout << "请输入您的新超市名称:" << '\t';
	string s; 
	cin >> s; m=getchar();
	Supermarket a(s);
	store.push_back(a);
	cout << "恭喜您拥有自己的第" <<store.size()-1<<"家超市!" << endl;
	long time;
	{
		for (time = 0; time < 3; time++)
			system("color 0F");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0A");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0B");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0C");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0D");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0E");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0D");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0B");
		Sleep(50);
		for (time = 0; time < 3; time++)
			system("color 0F");
		Sleep(50);
	}
}

void delete_store() {
	char m;
	cout << "请输入您要解散的超市名称:" << endl;
	string s;
	cin >> s; m = getchar();

	for (auto it = store.begin(); it != store.end();)
	{
		if (s == it->name) {
			it = store.erase(it);
		}
		else {
			++it;
		}
	}
	cout << "------***解散成功!***-------" << endl;
}

void hb() {
	int flag = 1; char m;
	int x, y;
	//输入被解散的超市a
	while (flag) {
		cout << "您想要取消的超市是:";
		string a;
		cin >> a; m = getchar();
		x = search_store(a);
		if (x == 0) {
			cout << "您输入的超市不存在,请重新输入!" << endl;
			flag++;
			if (flag == 3) {
				cout << "您已输入错误三次!" << endl;
				cout << "若您选择返回上一界面,请按“1”,若选择继续输入,请按此外任意键:" << endl;
				int x;
				cin >> x; m = getchar();
				if (x == 1) exit(6);
				else flag = 1;
			}
		}
		else flag = 0;
	}
	flag = 1;
	//输入被加入的超市b
	while (flag) {
		cout << "您想要将前者合并到超市:";
		string b;
		cin >> b; m = getchar();
		y = search_store(b);
		if (y == 0) {
			cout << "您输入的超市不存在,请重新输入!" << endl;
			flag++;
			if (flag == 3) {
				cout << "您已输入错误三次!" << endl;
				cout << "若您选择返回上一界面,请按“1”,若选择继续输入,请按此外任意键:" << endl;
				int x;
				cin >> x; m = getchar();
				if (x == 1) exit(6);
				else flag = 1;
			}
		}
		else flag = 0;
	}
	//a有b也有的商品,只加数量
	for (int j = 1; j < store[x].goods1.size(); j++) {
		int g = store[y].search01(store[x].goods1[j].name);
		if (g != 0) {
			store[y].goods1[g].quantity += store[x].goods1[j].quantity;
			auto it = store[x].goods1.begin();
			int w = 0;
			while (w != g) {
				it++;
				w++;
			}
			store[x].goods1.erase(it);
		}
	}
	for (int j = 1; j < store[x].goods2.size(); j++) {
		int g = store[y].search02(store[x].goods2[j].name);
		if (g != 0) {
			store[y].goods2[g].quantity += store[x].goods2[j].quantity;
			auto it = store[x].goods2.begin();
			int w = 0;
			while (w != g) {
				it++;
				w++;
			}
			store[x].goods2.erase(it);
		}
	}
	for (int j = 1; j < store[x].goods3.size(); j++) {
		int g = store[y].search03(store[x].goods3[j].name);
		if (g != 0) {
			store[y].goods3[g].quantity += store[x].goods3[j].quantity;
			auto it = store[x].goods3.begin();
			int w = 0;
			while (w != g) {
				it++;
				w++;
			}
			store[x].goods3.erase(it);
		}
	}
	//a有b没有的整个加入
	for (int j = store[x].goods1.size() - 1; j > 0; j--) {
		store[y].goods1.push_back(store[x].goods1[j]);
		store[x].goods1.pop_back();
	}
	for (int j = store[x].goods2.size() - 1; j >0; j--) {
		store[y].goods2.push_back(store[x].goods2[j]);
		store[x].goods2.pop_back();
	}
	for (int j = store[x].goods3.size() - 1; j >0; j--) {
		store[y].goods3.push_back(store[x].goods3[j]);
		store[x].goods3.pop_back();
	}
	auto it = store.begin();
	int w = 0;
	while (w != x) {
		w++;
		it++;
	}
	store.erase(it);
	cout << "-----***合并成功!***-----" << endl;
}

void huanying() {
	char m;
	if (store.size() ==1) {
		cout << "----------***欢迎来到超市经营系统***----------" << endl;
		cout << "请先创建您的第一个超市!" << endl;
		cout << "请输入您的超市名称:" << '\t';
		string s;
		cin >> s; m=getchar();
		Supermarket w(s);
		store.push_back(w);
		cout << "---------*创建成功*----------!" << endl;
		cout << "*******恭喜您拥有自己的第一个超市!*******" << endl;
		long time;
		{
			for(time=0;time<3;time++)
				system("color A8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color B8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color C8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color D8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color E8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color D8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color E8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color F8");
			Sleep(50);
			for (time = 0; time < 3; time++)
				system("color 0F");
			Sleep(50);
		}
		system("pause");
		system("cls");
		
		goto zhucaidan;
	}
	else {
	zhucaidan:
		cout << "----------***欢迎来到超市经营系统***----------" << endl;
		cout << "请选择按需求选择您的操作:" << endl;
		cout << "1.管理物资" << endl;
		cout << "2.增加新店" << endl;
		cout << "3.解散店铺" << endl;
		cout << "4.合并店铺" << endl;
		cout << "5.查看已有店铺" << endl;
		cout << "6.退出系统" << endl;
		cout << "请输入:" << endl;
		int x;
		cin >> x; m=getchar();
		switch (x) {
		case(1):
		{
			cout << "请输入您要管理的超市名称:" << endl;
			string s;
			cin >> s; m=getchar();
			int i = search_store(s);
			if (i == 0) {
				cout << "该商店不存在!" << endl;
				system("pause");
				system("cls");
				goto zhucaidan;
			}
			else {
				caidan1:
				cout << "请选择按需求选择您的操作:" << endl;
				cout << "1.查询商品" << endl;
				cout << "2.返回上一界面" << endl;
				cout << "请输入:" << endl;
				cin >> x;m=getchar();
				system("cls"); 
				switch (x) {
				case(1):
				{
					store[i].Add();
					cout << "如果您想继续在运行该超市,请按“1”,否则请按此外任意按键:" << '\t';
					int y = 0;
					cin >> y; m=getchar();
					if (y == 1) {
						system("cls");
						goto caidan1;
					}
					else goto zhucaidan;
				}
				case(2):
				{
					store[i].Search();
					cout << "如果您想继续在运行该超市,请按“1”,否则请按此外任意按键:" << '\t';
					int y = 0;
					cin >> y; m=getchar();
					if (y == 1) {
						system("cls");
						goto caidan1;
					}
					else goto zhucaidan;
				}
				case(3):
				{
					store[i].Sale();
					cout << "如果您想继续在运行该超市,请按“1”,否则请按此外任意按键:" << '\t';
					int y = 0;
					cin >> y; m=getchar();
					if (y == 1) {
						goto caidan1;
						system("cls");
					}
					else goto zhucaidan;
				}
				case(4):
					goto zhucaidan;
				default:
					cout << "输入错误,请重新输入!" << endl;
					goto caidan1;
				}
			}
			}
		case(2):
			add_store();
			system("pause");
			system("cls");
			goto zhucaidan;
		case(3):
			delete_store();
			system("pause");
			system("cls");
			goto zhucaidan;
		case(4):
			hb();
			system("pause");
			system("cls");
			goto zhucaidan;
		case(5):
			cout << "----------***欢迎查看您的资产***----------" << endl;
			for (int i = 1; i < store.size(); i++) {
				cout <<"第"<<i<<"家超市名称为" << store[i].get_name() << endl;
			}
			system("pause");
			system("cls");
			goto zhucaidan;
		case(6):
			break;
		default:
			cout << "输入错误,请重新输入!" << endl;
			goto zhucaidan;
		}
	}
}

主要问题改善
增加了二级界面的返回功能,并分成直接返回最开始界面还是该超市界面

新代码截图



总结
这一次的体会让我深刻意识到为何有些公司面对多年运行下来的屎山代码无能为力的感觉。在面对其他同学的代码时,想要读懂他所写的代码和他的运行逻辑就不是一件简单的事情,在最开始的更改中,常常会改了一小点之后就导致整个程序报错无法运行,因而只能磕磕绊绊地一点点修改些细枝末节的地方,对于代码的主干要吗进行全部推倒重构,要么只能选择敬而远之。不过我在这次的经历中也收获不少,在读了同学的代码后,我也感觉到了写代码时规范的重要性,规范的写法才能使程序员更好读懂你语句的含义。希望自己以后能在这方面尽可能的做好

标签:system,完善,cout,int,功能,超市,cls,store,getchar
From: https://www.cnblogs.com/ywsheng226/p/18057439

相关文章

  • 简单实现邮件模板功能
    系统中经常有需要发送提醒邮件的需求,而且邮件类型和内容往往又不同,有些还需要跟业务字段做关联。这种情况下,就需要用到邮件模板功能,可以通过在模板中定义业务字段标记,通过模板引擎或自定义代码来实现这些字段的填充。下面是一个自己写的简单的,字符串替换方式实现的邮件模板功能。......
  • ChatGPT 新增朗读功能;微软 Win11 鼠标悬停自动打开 Copilot 丨 RTE 开发者日报 Vol.15
      开发者朋友们大家好: 这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE(RealTimeEngagement)领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表编辑的个人观点......
  • 让运维无忧,实战解析巡检报告功能实现方案
    随着大数据技术的演进和信息安全性需求的提升,数据规模的持续扩张为数据运维工作带来了严峻考验。面对海量数据所形成的繁重管理压力,运维人员面临效率瓶颈,而不断攀升的人力成本也使得单纯依赖扩充运维团队来解决问题变得不再实际可行。由此可见,智能化与高效便捷是运维发展的必然方......
  • odoo group by 汇总功能
    汇总字段属性有哪些:#validSQLaggregationfunctionsVALID_AGGREGATE_FUNCTIONS={'array_agg','count','count_distinct','bool_and','bool_or','max','min','avg','su......
  • 功能测试、自动化测试、性能测试的区别
    按测试执行的类型来分:功能测试、自动化测试、性能测试1.功能测试功能测试俗称点点点测试。初级测试人员的主要测试任务就是执行测试工程师所写的测试用例,记录用例的执行状态及bug情况。与开发人员进行交互直到bug被修复。功能测试理论上是指通过测试来检测系统每个功能是否都能......
  • shell邮件功能-2
    场景:应用服务域名对应多台负载机,当某台出现CPU或RAM资源阻塞时,如果服务器并未死机,根据负载策略(类似ping或telnet),服务器可能仍然是可用的,新的访问仍然有分配到这台机器处理的可能,但实际又不可用,体验不好,且不能及时发送故障通知。新的负载策略是访问指定页面(类似curl命令),检查返......
  • shell邮件功能-2
    场景:应用服务域名对应多台负载机,当某台出现CPU或RAM资源阻塞时,如果服务器并未死机,根据负载策略(类似ping或telnet),服务器可能仍然是可用的,新的访问仍然有分配到这台机器处理的可能,但实际又不可用,体验不好,且不能及时发送故障通知。新的负载策略是访问指定页面(类似curl命令),检查返回结......
  • 借助 Terraform 功能协调部署 CI/CD 流水线-Part 1
    在当今快节奏的开发环境中,实现无缝、稳健的CI/CD流水线对于交付高质量软件至关重要。在本文中,我们将向您介绍使用BitbucketPipeline、ArgoCDGitOps和AWSEKS设置部署的步骤,所有步骤都将利用Terraform的强大功能进行编排。在Part1里,将主要介绍通过Terraform创建和部署......
  • 易基因:妊娠期母体甲基供体摄入对IUGR猪模型回肠DNA甲基化和功能影响|项目文章
    出生体重较低的宫内生长受限(Intrauterinegrowthrestriction,IUGR)影响肠道的生长、形态和功能,导致生长性能不佳和高死亡率。最近研究表明,IUGR导致肠道中不同的DNA甲基化,可能在IUGR肠道损伤中起关键作用。母体营养可以通过表观遗传修饰(例如DNA甲基化和组蛋白乙酰化)导致后代的永久表......
  • lazarus在银河麒麟国产操作系统linux下,使用TListView 使用图标样式 BUG完善
    lazarus在银河麒麟国产操作系统linux下,使用TListView使用TListViewvsIcon样式,文本长了会是这样效果尝试设置OwnerDraw属性为True自己定义方法DrawItem不起效果也尝试修改TCustomListView源代码也不起效果,搞了半天,后发现坑了,没仔细看帮助WhensettoTrue,theOn......