1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 using namespace std;
5 class card{
6 //属性
7 public:
8 string name;
9 int id;
10 string classroom;
11 float money;
12 int money_type;//0人民币 1美元 2 泰铢
13 string creat_time;
14 bool lost=false;
15 //方法
16 //开卡
17 bool creat(int i,string n,string c){
18 name=n;
19 classroom=c;
20 id=i;
21 return true;
22 }
23 //充钱
24 bool Recharge(int m){
25 money+=m;
26 return true;
27 }
28 //消费
29 bool consumption(float m){
30 if(money>=m && m>0.0){
31 money-=m;
32 return true;
33 }
34 return false;
35 }
36 };
37 int main(int argc, char** argv) {
38 string data;
39 ifstream file;
40 ofstream file2;
41 int length;
42 card c;
43 int _cid;
44 bool have;
45 string x;
46 int i=0;
47 float money;
48
49 card cardlist[100];
50 int startid=1000;
51 int number=0;//当前有几个人办卡
52 //getline获取文件的一行数据
53 file.open("1.txt");
54 while(getline(file,data)){
55 if(data.length()>5){
56 number++;
57 i=0;
58 do{
59 length=data.find("|");
60 if(i==0){
61 c.name=data.substr(0,length);
62 }else if(i==1){
63 c.classroom=data.substr(0,length);
64 }else if(i==2){
65 c.id=stoi(data.substr(0,length));
66 }
67 data=data.substr(length+1);
68 i++;
69 }while(length>0 && length<=data.length());
70 c.money=stod(data);
71 cardlist[number]=c;
72 cardlist[number].lost=false;
73 }
74 //eof 是否到了文件末尾
75 if(file.eof()){
76 cout<<"end"<<endl;
77 break;
78 }
79 }
80 file.close();
81 while(1){
82 system("cls");
83 cout<<"*太康一高附属学校充值系统**"<<endl;
84 cout<<"1.开卡"<<endl<<"2.充值"<<endl<<"3.消费"<<endl<<"4.查询余额"<<endl;
85 cout<<"5.挂失"<<endl<<"6.退钱"<<endl<<"7.查询现有多少人办卡"<<endl<<"8.查询信息"<<endl<<"9.修改信息"<<endl<<"10.退出系统";
86 cout<<endl;
87 int index;
88 cin>>index;
89 switch(index){
90 case 1:
91 cout<<"请输入姓名:";
92 cin>>c.name;
93 cout<<"请输入班级:";
94 cin>>c.classroom;
95 c.id=startid+number;
96 number++;
97 cardlist[number]=c;
98
99 cardlist[number].lost=false;
100 cout<<"创卡成功,您的卡号是:"<<c.id<<endl;
101 file2.open("1.txt");
102 file2<<cardlist[number].name<<"|"<<cardlist[number].classroom<<"|"<<cardlist[number].id<<"|"<<cardlist[number].money;
103 system("pause");
104 break;
105 case 2:
106 cout<<"请输入你的卡号:";
107
108 cin>>_cid;
109 have=false;
110 for(int i=0;i<=number;i++){
111 if(cardlist[i].id==_cid){
112 if(cardlist[i].lost){
113 cout<<"该卡已挂失,无法充值,请谅解"<<endl;
114 have=true;
115 break;
116 }
117 cout<<cardlist[i].name<<"同学你好,请输入充值金额:";
118 cin>>money;
119 c.money+=money;
120 cardlist[number]=c;
121 have=true;
122 break;
123 }
124 }
125 if(have==false){
126 cout<<"对不起,该同学没有创建卡号"<<endl;
127 }
128 system("pause");
129 break;
130 case 3:
131 cout<<"请输入你的卡号:";
132 cin>>_cid;
133 have=false;
134 for(int i=0;i<=number;i++){
135 if(cardlist[i].id==_cid){
136 if(cardlist[i].lost){
137 cout<<"该卡已挂失,无法消费,请谅解"<<endl;
138 have=true;
139 break;
140 }
141 cout<<"请输入消费金额:";
142 cin>>money;
143 if(cardlist[number].consumption(money)){
144 cout<<"消费成功,你的余额还剩:"<<cardlist[number].money<<endl;
145 }else{
146 cout<<"消费失败,你的余额不足,请尽快充值!"<<endl;
147 }
148 have=true;
149 break;
150 }
151 }
152 if(have==false){
153 cout<<"对不起,该同学没有创建卡号"<<endl;
154 }
155 system("pause");
156 break;
157 case 4:
158 cout<<"请输入你的卡号:";
159 cin>>_cid;
160 have=false;
161 for(int i=0;i<=number;i++){
162 if(cardlist[i].id==_cid){
163 if(cardlist[i].lost){
164 cout<<"该卡已挂失,无法查询,请谅解"<<endl;
165 have=true;
166 break;
167 }
168 cout<<"你的余额还剩:"<<cardlist[number].money<<endl;
169 have=true;
170 break;
171 }
172 }
173 if(have==false){
174 cout<<"对不起,该同学没有创建卡号"<<endl;
175 }
176 system("pause");
177 break;
178 case 5:
179 cout<<"请输入你要挂失的卡号:";
180 cin>>_cid;
181 have=false;
182 for(int i=0;i<=number;i++){
183 if(cardlist[i].id==_cid){
184 cout<<"挂失成功";
185 cardlist[i].lost=true;
186 have=true;
187 break;
188 }
189 }
190 if(have==false){
191 cout<<"对不起,该同学没有创建卡号"<<endl;
192 }
193 system("pause");
194 break;
195 case 6:
196 cout<<"请输入卡号:";
197 cin>>_cid;
198 have=false;
199 for(int i=0;i<=number;i++){
200 if(cardlist[i].id==_cid){
201 if(cardlist[i].lost){
202 cout<<"该卡已挂失,无法进行操作,请谅解"<<endl;
203 have=true;
204 break;
205 }
206 cout<<"请输入退钱金额:";
207 cin>>money;
208 if(cardlist[number].consumption(money)){
209 cout<<"退钱成功,你的余额还剩:"<<cardlist[number].money<<endl;
210 }else{
211 cout<<"退钱失败,你的余额不足"<<endl;
212 }
213 have=true;
214 break;
215 }
216 }
217 if(have==false){
218 cout<<"对不起,该同学没有创建卡号"<<endl;
219 }
220 system("pause");
221 break;
222 case 7:
223 cout<<"现有"<<number<<"人办卡"<<endl;
224 system("pause");
225 break;
226 case 8:
227 cout<<"请输入你要查询的人的卡号:";
228 cin>>_cid;
229 have=false;
230 for(int i=0;i<=number;i++){
231 if(cardlist[i].id==_cid){
232 system("cls");
233 cout<<"姓名:"<<cardlist[i].name<<endl;
234 cout<<"卡号:"<<cardlist[i].id<<endl;
235 cout<<"班级:"<<cardlist[i].classroom<<endl;
236 have=true;
237 break;
238 }
239 }
240 if(have==false){
241 cout<<"对不起,该同学没有创建卡号"<<endl;
242 }
243 system("pause");
244 break;
245 // case 9:
246 // cout<<"请输入你的卡号:";
247 // cin>>_cid;
248 // have=false;
249 // for(int i=0;i<=number;i++){
250 // if(cardlist[i].id==_cid){
251 // system("cls");
252 // cout<<"请输入你要修改的项:";
253 // cin>>x;
254 // if(x=="姓名"){
255 // cout<<"你要把它修改为:";
256 // cin>>x;
257 // cardlist[i].name=x;
258 // }else if(x=="班级"){
259 // cout<<"你要把它修改为:";
260 // cin>>x;
261 // cardlist[i].classroom=x;
262 // }else{
263 // cout<<"";
264 // }
265 // have=true;
266 // break;
267 // }
268 // }
269 if(have==false){
270 cout<<"对不起,该同学没有创建卡号"<<endl;
271 }
272 system("pause");
273 break;
274 case 10:
275 return 0;
276 }
277 }
278 /*
279 卡片:
280 属性:
281 姓名:string 张三
282 卡号:int 123456
283 班级:string 三2班
284 余额:float 0.2
285 余额单位: 元
286 办卡时间:string 2023 11 19 08 40
287 手机号:string
288 办卡地点:string 充值点
289 身份证:string
290 家庭住址:string
291 每日消费上限:int 50
292 消费记录: string[]
293 最后一次消费时间:string
294 充值记录:string[]
295 挂失状态:bool
296 方法:
297 开卡 参数1:姓名、班级、
298 充值 参数1:int 金额
299 刷卡 参数1:float 金额 参数2:string 地点
300 挂失: 参数1 卡号
301 余额查询:参数1 卡号
302 修改姓名:参数1 卡号 参数2 新名字
303 删除卡片:参数1 卡号
304 退钱:参数1 卡号 参数2 金额
305 增加利息:参数1 卡号 参数2 金额
306
307 */
308 return 0;
309 }