#include <iostream> #include <windows.h> #include <fstream> using namespace std; struct card{ //属性 string name; int id; string classroom; float money=0; string creat_time; bool gua=0;//是否挂失 //方法 //开卡 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; } //退钱 bool tuiqian(int m){ if(money-m<0){ return false; }else{ money-=m; return true; } } //挂失 bool guashi(bool m){ gua=m; return true; } }; void fen(){ ifstream file; string data; file.open("1.txt"); //getline获取文件的一行数据 while(getline(file,data)){ if(data.length()>5){ string classroom,id,name; double money; int length; do{ length=data.find("|"); cout<<data.substr(0,length)<<" "; data=data.substr(length+1); }while(length>0 && length<data.length()); } //eof 是否到了文件末尾 if(file.eof()){ cout<<"end"<<endl; break; } } file.close(); } int main(int argc, char** argv) { card cardlist[100]; int startid=1000; int number=0;//当前有几个人办卡 fen(); while(1){ cout<<"**太康一高附属学校充值系统**"<<endl; cout<<"*****1.开卡*****"<<endl; cout<<"*****2.充值*****"<<endl; cout<<"*****3.消费*****"<<endl; cout<<"***4.查询余额***"<<endl; cout<<"*****5.挂失*****"<<endl; cout<<"*****6.退钱*****"<<endl; cout<<"***7.退出系统***"<<endl; cout<<endl; int index; cin>>index; card c; int a;//充值,消费金额,退钱 int _cid;//卡号 bool t=0;//挂失 bool have=false; switch(index){ case 1: cout<<"请输入姓名:"; cin>>c.name; c.id=startid+number; cardlist[number]=c; cout<<"你的学号为"<<cardlist[number].id<<"你的金额为"<<cardlist[number].money; number++; break; case 2: cout<<"请输入你的卡号:"; cin>>_cid; for(int i=0;i<=number;i++){ if(cardlist[i].id==_cid){ if(cardlist[i].gua==1){ cout<<"对不起,该同学的卡已挂失"; }else{ cout<<cardlist[i].name<<"同学你好,请输入充值金额:"; cin>>a; cardlist[i].Recharge(a); cout<<"你的金额有:"<<cardlist[i].money; have=true; break; } } } if(have==false){ cout<<"对不起,该同学没有创建卡号"<<endl; } break; case 3: cout<<"请输入你的卡号"; cin>>_cid; for(int i=0;i<=number;i++){ if(cardlist[i].id==_cid){ if(cardlist[i].gua==1){ cout<<"对不起,该同学的卡已挂失"; }else{ cout<<cardlist[i].name<<"同学你好,请输入消费金额: 上限为500"<<endl; cin>>a; if(a>500){ cout<<"充值超过上限"; }else{ cardlist[i].consumption(a); cout<<"你的剩余金额:"<<cardlist[i].money; } have=true; break; } } } if(have==false){ cout<<"对不起,该同学没有创建卡号"<<endl; } break; case 4: cout<<"请输入你的卡号"; cin>>_cid; for(int i=0;i<=number;i++){ if(cardlist[i].id==_cid){ cout<<cardlist[i].name<<"同学你好,你的余额为"<<cardlist[i].money; have=true; break; } } if(have==false){ cout<<"对不起,该同学没有创建卡号"<<endl; } break; case 5: cout<<"请输入你的卡号"; cin>>_cid; for(int i=0;i<=number;i++){ if(cardlist[i].id==_cid){ cout<<cardlist[i].name<<"同学你好,请输入你要退多少钱"<<endl; cin>>a; if(cardlist[i].tuiqian(a)==0){ cout<<"同学,你的余额不足"; } have=true; cout<<cardlist[i].name<<"同学,你的余额为"<<cardlist[i].money; break; } } if(have==false){ cout<<"对不起,该同学没有创建卡号"<<endl; } break; case 6: cout<<"请输入你的卡号"; cin>>_cid; for(int i=0;i<=number;i++){ if(cardlist[i].id==_cid){ t=1; cardlist[i].guashi(t); cout<<"同学,你的卡已挂失"; have=true; break; } } if(have==false){ cout<<"对不起,没有该卡"<<endl; } break; case 7: return 0; break; } Sleep(500); system("cls"); } return 0; }
标签:饭卡,string,cid,int,money,bool,cout From: https://www.cnblogs.com/boyeyuan/p/17991093