#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");
}
/*
卡片:
属性:
姓名:string 张三
卡号:int 123456
班级:string 三2班
余额:float 0.2
余额单位: 元
办卡时间:string 2023 11 19 08 40
手机号:string
办卡地点:string 充值点
身份证:string
家庭住址:string
每日消费上限:int 50
消费记录: string[]
最后一次消费时间:string
充值记录:string[]
挂失状态:bool
方法:
开卡 参数1:姓名、班级、
充值 参数1:int 金额
刷卡 参数1:float 金额 参数2:string 地点
挂失: 参数1 卡号
余额查询:参数1 卡号
修改姓名:参数1 卡号 参数2 新名字
删除卡片:参数1 卡号
退钱:参数1 卡号 参数2 金额
增加利息:参数1 卡号 参数2 金额
*/
return 0;
}