#include <iostream> using namespace std; struct card{ //属性 string name; int id; string classroom; float money; string creat_time; bool lost = true; //方法 //开卡 bool creat(int i,string n,string c){ name = n; classroom = c; id = i; return true; } //充钱 bool Recharge(int m){ money += m; return true; } //消费 bool consumption(int m){ if(money>=m && m>0){ money -= m; return true; } return false; } }; int main(int argc, char** argv) { card cardlist[100]; int startid = 1000; int number = 0;//当前有几个人办卡 while(1){ cout<<"太康一高附属学校充值系统"<<endl <<"*********1.开卡*********"<<endl <<"*********2.充值*********"<<endl <<"*********3.消费*********"<<endl <<"*********4.查询余额*****"<<endl <<"*********5.挂失*********"<<endl <<"*********6.退钱*********"<<endl <<"*********7.退出系统*****"<<endl; int index; cin>>index; card c; bool have; int _cid; switch(index){ case 1: cout<<"请输入姓名:"; cin>>c.name; c.id = startid+number; cardlist[number] = c; cout<<c.name<<"同学你好,你的卡号是:"<<c.id<<endl; number++; break; case 2: cout<<"请输入你的卡号:"; cin>>_cid; have = false; for(int i = 0;i<=number;i++){ if(!cardlist[i].lost){ cout<<cardlist[i].name<<"同学,该卡号已挂失"<<endl; have = true; break; } if(cardlist[i].id==_cid){ cout<<cardlist[i].name<<"同学你好,请输入充值金额:"; int money; cin>>money; cardlist[i].money += money; have = true; cout<<"充值成功"<<endl; 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<<"同学你好,请输入消费金额:"; int money; cin>>money; if(cardlist[i].consumption(money)){ cardlist[i].consumption(money); }else{ cout<<"您的余额不足"<<endl; break; } have = true; cout<<"消费成功"<<endl; break; } } if(have==false){ cout<<"对不起,没有该卡号"<<endl; } break; case 4: cout<<"请输入你的卡号:"; cin>>_cid; have = false; for(int i = 0;i<=number;i++){ if(cardlist[i].id==_cid){ cout<<cardlist[i].name<<"同学你好,你的余额是:"<<cardlist[i].money<<endl; have = true; break; } } if(have==false){ cout<<"对不起,没有该卡号"<<endl; } break; case 5: cout<<"请输入你要挂失的卡号:"; cin>>_cid; have = false; for(int i = 0;i<=number;i++){ if(cardlist[i].id==_cid){ cardlist[i].lost = false; cout<<"挂失成功"<<endl; have = true; break; } } if(have==false){ cout<<"对不起,没有该卡号"<<endl; } break; case 7: system("pause"); return 0; } system("pause"); system("cls"); } return 0; }