饭卡管理系统&结构体

发布时间 2023-11-19 10:10:16作者: 王ys
#include<iostream>
using namespace std;
struct card{
	string name;
	int id;
	int money;
	bool build_card(int x_id,string x_name){
		name=x_name;
		id=x_id;
		return true;
	}
	bool chong(int x_money){
		money+=x_money;
		return true;
	}
	bool hua(int x_money){
		if(money>=x_money&&x_money>0){
			money-=x_money;
			return true;
		}
		return false;
	}
};
int main(){
	card cardlist[100];
	int firstid=1000;
	int number=0;
	while(1){
		cout<<"*饭卡管理系统*"<<endl<<"1.办卡"<<"2.充值"<<"3.消费"<<"4.查询余额"<<endl; 
		int index;
		cin>>index;
		card c;
		bool have=false;
		switch(index){
			case 1:				
				cout<<"请输入姓名:";
				cin>>c.name;
				c.id=firstid+number;
				cardlist[number]=c;
				cout<<"办卡成功"<<cardlist[number].name<<",你的卡号:"<<cardlist[number].id<<endl;
				number++;
				
				break;
			case 2:
				cout<<"请输入你的卡号:";
				int _cid;
				cin>>_cid;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
						cout<<cardlist[i].name<<"同学你好,请输入充值金额:";
						cin>>c.money;
						cardlist[number]=c;
						cout<<"充值成功,目前金额:"<<cardlist[number].money<<endl;
						have=true;
						break;
					} 
				} 
				if(have==false){
					cout<<"对不起,没有查询到该卡号"<<endl;
				}
				break;
			case 3:
				cout<<"请输入你的卡号:";
				cin>>_cid;
				have=false;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
						cout<<cardlist[i].name<<"同学你好,请输入花费金额:";
						cin>>c.money;
						cardlist[number]=c;
						cout<<"花费成功,目前金额:"<<cardlist[number].money<<endl;
						have=true;
						break;
					} 
				} 
				if(have==false){
					cout<<"对不起,没有查询到该卡号"<<endl;
				}
				break;
		}
	}
	return 0;
}