#include <bits/stdc++.h>
using namespace std;
struct card{
//属性
string name;
int id;
string classroom;
float money;
int money_type;//0人民币 1美元 2 泰铢
string creat_time;
string tellphone;
string creat_date;
//方法
//开卡
bool creat(int i,string n,string c){
name=n;
id=i;
classroom=c;
return true;
}
//充钱
bool Recharge(int m){
money+=m;
}
//消费
bool consumption(int m){
if(money>=m && m>0){
money-=m;
return true;
}
return false;
}
};
int main(){
card cardlist[100];
int startid=1000;
int number=0;//当前有几个人办卡
//
string name;
int Id;
double Money;
ifstream file;
string data;
file.open("1.txt");
//getline获取文件的一行数据
while(getline(file,data)){
if(data.length()>5){
int length=data.find("|");
name=data.substr(0,length);
cout<<name<<endl;
data=data.substr(length+1);
length=data.find("|");
Id=stoi(data.substr(0,length));
cout<<Id<<endl;
data=data.substr(length+1);
length=data.find("|");
Money=stoi(data.substr(0,length));
cout<<Money<<endl;
cardlist[number].name=name;
cardlist[number].id=Id;
cardlist[number].money=Money;
// do{
// length=data.find("|");
// cout<<data.substr(0,length)<<endl;
// data=data.substr(length+1);
// cout<<data<<endl;
// }while(length>0 && length<data.length());
}
//eof 是否到了文件末尾
if(file.eof()){
cout<<"end"<<endl;
break;
}
}
file.close();
int die=0;
while(1){
cout<<"***一高附属学校充值系统***"<<endl;
cout<<"1.开卡"<<endl<<"2.充值"<<endl<<"3.查询余额"<<endl<<"4.消费"<<endl;
cout<<"5.挂失"<<endl<<"6.退钱"<<endl<<"7.退出系统";
cout<<endl;
int index;
cin>>index;
card c;
bool have=false;
int _cid;
switch(index){
case 1:
cout<<"请输入姓名:";
cin>>c.name;
c.id=startid+number;
cardlist[number]=c;
cout<<"办卡成功!,你的卡号为"<<c.id<<endl;
number++;
break;
case 2:
cout<<"请输入你的卡号:"<<endl;
cin>>_cid;
for(int i=0;i<=number;i++){
if(cardlist[i].id==_cid){
if(die==1){
cout<<cardlist[i].name<<"同学的卡以挂失"<<endl;
}else{
cout<<cardlist[i].name<<"同学你好,请输入充值金额:";
int c_money;
cin>>c_money;
c.money+=c_money;
cout<<"充卡成功!目前你的卡里拥有"<<c.money<<"元"<<endl;
}
have=true;
break;
}
}
if(have==false){
cout<<"对不起,该同学没有创建卡号"<<endl;
}
break;
case 3:
cout<<"请输入你的卡号:"<<endl;
cin>>_cid;
for(int i=0;i<=number;i++){
if(cardlist[i].id==_cid){
if(die==1){
cout<<cardlist[i].name<<"同学的卡以挂失"<<endl;
}else{
cout<<cardlist[i].name<<"同学你好,你的余额为:"<<c.money<<"元"<<endl;
have=true;
break;
}
}
}
if(have==false){
cout<<"对不起,该同学没有创建卡号"<<endl;
}
break;
case 4:
cout<<"请输入你的卡号:"<<endl;
int XF;
cin>>_cid;
have=false;
for(int i=0;i<=number;i++){
if(cardlist[i].id==_cid){
if(die==1){
cout<<cardlist[i].name<<"同学的卡以挂失"<<endl;
}else{
cout<<"输入你消费的金额";
cin>>XF;
c.money-=XF;
cout<<cardlist[i].name<<"你的余额为"<<c.money<<endl;
have=true;
break;
}
}
}
if(have==false){
cout<<"对不起,该同学没有创建卡号"<<endl;
}
break;
case 5:
cout<<"请输入你的卡号:"<<endl;
cin>>_cid;
for(int i=0;i<=number;i++){
if(cardlist[i].id==_cid){
die=1;
cout<<"已成功挂失"<<cardlist[i].name<<"同学的饭卡,余额为"<<c.money<<"元"<<endl;
have=true;
break;
}
}
if(have==false){
cout<<"对不起,该同学没有创建卡号"<<endl;
}
break;
}
}
return 0;
}