活期储蓄账目管理系统
生活随笔
收集整理的這篇文章主要介紹了
活期储蓄账目管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
基本要求:實現儲戶開戶、銷戶、存入、支出等活動。要求能查找儲戶的賬戶,實現存款、
取款、插入、刪除等操作。具體功能如下:
(1)實現儲戶開戶。
(2)實現儲戶銷戶。
(3)向某賬戶存款。
(4)從某賬戶取款。
(5)排序顯示所有賬戶信息。
(6)查詢某賬戶余額。
(7)查詢某賬戶交易記錄。
?
1 #include<iostream> 2 #include<fstream> 3 #include<iomanip> 4 #include<string.h> 5 using namespace std; 6 #include<windows.h> 7 #define MAX 500 8 9 struct record 10 { 11 char name[20]; 12 char cardno[20]; 13 int card; 14 char money[20]; 15 }; 16 17 //用戶類,包含用戶的姓名,卡號,密碼,賬戶余額 18 class account 19 { 20 public: 21 char name[50]; 22 int card; 23 int password; 24 float balance; 25 account(){card=0;password=123456;balance=0;}; 26 friend istream& operator >>(istream& in,account &temple); 27 friend ostream& operator <<(ostream& out,account &temple); 28 }; 29 30 //重載輸入運算符 31 istream& operator >>(istream& in,account &temple) 32 { 33 cout<<"姓名 卡號 密碼 開戶金額"<<endl; 34 in>>temple.name>>temple.card>>temple.password>>temple.balance; 35 cout<<endl; 36 return in; 37 } 38 39 //重載輸出運算符 40 ostream& operator <<(ostream& out,account &temple) 41 { 42 out<<temple.name<<setw(8)<<temple.card<<setw(10)<<temple.password<<setw(8)<<temple.balance<<endl; 43 return out; 44 } 45 46 //顯示所有賬戶的信息 47 void display(account user[],int total) 48 { 49 int i,j; 50 account templeuser; 51 if(total==0) 52 { 53 cout<<"無賬戶信息"<<endl<<endl; 54 } 55 else 56 { 57 cout<<"所有用戶信息:"<<endl; 58 for(i=0;i<total-1;i++) 59 { 60 for(j=0;j<total-1-i;j++) 61 { 62 if(user[j].card>user[j+1].card) 63 { 64 templeuser=user[j]; 65 user[j]=user[j+1]; 66 user[j+1]=templeuser; 67 } 68 } 69 } 70 for(i=0;i<total;i++) 71 { 72 cout<<"姓名:"<<user[i].name<<' '<<"卡號:"<<user[i].card<<' '<<"密碼:"<<user[i].password<<' '<<"余額:"<<user[i].balance<<"元"<<endl; 73 } 74 } 75 } 76 77 //查找卡號 78 int searchcard(account user[],int total,int templecard) 79 { 80 int i=0; 81 while((i<total)&&(user[i].card!=templecard)) 82 { 83 i++; 84 } 85 if(i>total-1) 86 { 87 return -1; 88 } 89 else 90 { 91 return i; 92 } 93 } 94 95 int main() 96 { 97 system("color f3"); 98 record c[MAX]; 99 int i,total=0,templecard,k,m; 100 float money,templemoney; 101 account temple,user[MAX]; 102 int select=0; 103 do 104 { 105 system("cls"); 106 cout<<"*******************************"<<endl; 107 cout<<"* 活期儲蓄賬目管理系統 *"<<endl; 108 cout<<"*******************************"<<endl; 109 cout<<"*1--------------------儲戶開戶*"<<endl; 110 cout<<"*2--------------------儲戶銷戶*"<<endl; 111 cout<<"*3------------------------存款*"<<endl; 112 cout<<"*4------------------------取款*"<<endl; 113 cout<<"*5------------顯示所有賬戶信息*"<<endl; 114 cout<<"*6--------------------查詢余額*"<<endl; 115 cout<<"*7----------------查詢交易記錄*"<<endl; 116 cout<<"*0------------------------退出*"<<endl; 117 cout<<"*******************************"<<endl<<endl; 118 cout<<"請輸入您的選擇:"; 119 cin>>select; 120 switch(select) 121 { 122 case 1:cout<<endl<<"開戶:"<<endl; 123 cout<<"請輸入您的基本信息:"<<endl; 124 cin>>temple; 125 i=0; 126 while((i<total)&&(user[i].card!=temple.card)) 127 { 128 i++; 129 } 130 if(i>total-1) 131 { 132 user[total]=temple; 133 system("cls"); 134 cout<<"您已經成功開戶!"<<endl<<"您的基本信息為:"<<endl; 135 cout<<"姓名 卡號 密碼 賬戶余額"<<endl; 136 cout<<user[total]; 137 total++; 138 system("pause"); 139 system("cls"); 140 { 141 ofstream out("user.txt",ios::app);//打開輸出文件流 142 if(out)//如果打開成功 143 { 144 out<<"姓名:"<<temple.name<<' '<<"卡號:"<<temple.card<<' '<<"密碼:"<<temple.password<<' '<<"余額:"<<temple.balance<<"元"<<endl;//向文件輸入信息 145 out.close();//關閉 146 } 147 } 148 { 149 ofstream out("record.txt",ios::app); 150 if(out) 151 { 152 out<<"姓名:"<<temple.name<<' '<<"卡號:"<<' '<<temple.card<<' '<<"存入"<<temple.balance<<"元"<<endl; 153 out.close(); 154 } 155 } 156 } 157 else 158 { 159 system("cls"); 160 cout<<"賬戶已經存在,開戶失敗!!"<<endl; 161 system("pause"); 162 } 163 break; 164 case 2:cout<<endl<<"銷戶:"<<endl; 165 cout<<"請輸入要注銷的卡號:"; 166 cin>>templecard; 167 k=searchcard(user,total,templecard); 168 if(k==-1) 169 { 170 system("cls"); 171 cout<<"輸入有誤,賬戶不存在"<<endl; 172 system("pause"); 173 } 174 else 175 { 176 system("cls"); 177 cout<<"您的賬戶已經成功注銷!并返還您"<<user[k].balance<<"元."<<endl; 178 system("pause"); 179 { 180 ofstream out("record.txt",ios::app); 181 if(out) 182 { 183 out<<"姓名:"<<user[k].name<<' '<<"卡號:"<<' '<<user[k].card<<' '<<"注銷賬戶,并返還"<<user[k].balance<<"元."<<endl; 184 out.close(); 185 } 186 } 187 for(i=k+1;i<total;i++) 188 { 189 user[i-1]=user[i]; 190 } 191 total--; 192 { 193 ofstream out("user.txt"); 194 if(out) 195 { 196 for(i=0;i<total;i++) 197 { 198 out<<"姓名:"<<user[i].name<<' '<<"卡號:"<<user[i].card<<' '<<"密碼:"<<user[i].password<<' '<<"余額:"<<user[i].balance<<"元"<<endl; 199 out.close(); 200 } 201 } 202 } 203 } 204 cout<<endl; 205 break; 206 case 3:cout<<endl<<"存款:"<<endl; 207 cout<<"請輸入您的卡號:"; 208 cin>>templecard; 209 k=searchcard(user,total,templecard); 210 if(k==-1) 211 { 212 system("cls"); 213 cout<<"輸入有誤,賬戶不存在"<<endl; 214 system("pause"); 215 } 216 else 217 { 218 cout<<"請輸入要存入的金額:"; 219 cin>>money; 220 user[k].balance=user[k].balance+money; 221 system("cls"); 222 cout<<"您已經成功存入"<<money<<"元,卡上還余"<<user[k].balance<<"元."<<endl; 223 { 224 ofstream out("record.txt",ios::app); 225 if(out) 226 { 227 out<<"姓名:"<<user[k].name<<' '<<"卡號:"<<' '<<user[k].card<<' '<<"存入"<<money<<"元"<<endl; 228 out.close(); 229 } 230 } 231 { 232 ofstream out("user.txt"); 233 if(out) 234 { 235 for(i=0;i<total;i++) 236 { 237 out<<"姓名:"<<user[i].name<<' '<<"卡號:"<<user[i].card<<' '<<"密碼:"<<user[i].password<<' '<<"余額:"<<user[i].balance<<"元"<<endl; 238 } 239 out.close(); 240 } 241 } 242 system("pause"); 243 } 244 break; 245 case 4:cout<<endl<<"取款:"<<endl; 246 cout<<"請輸入您的卡號:"; 247 cin>>templecard; 248 k=searchcard(user,total,templecard); 249 if(k==-1) 250 { 251 system("cls"); 252 cout<<"輸入有誤,賬戶不存在"<<endl; 253 system("pause"); 254 } 255 else 256 { 257 cout<<"請輸入要取的金額:"; 258 cin>>money; 259 if(user[k].balance<money) 260 { 261 cout<<"您的賬戶僅余"<<user[k].balance<<"元"<<endl; 262 cout<<"是否繼續領取?(是按1,否按0):"; 263 cin>>m; 264 if(m==0) 265 { 266 cout<<endl; 267 break; 268 } 269 else 270 { 271 templemoney=user[k].balance; 272 user[k].balance=0; 273 { 274 ofstream out("record.txt",ios::app); 275 if(out) 276 { 277 out<<"姓名:"<<user[k].name<<' '<<"卡號:"<<' '<<user[k].card<<' '<<"取出"<<templemoney<<"元"<<endl; 278 } 279 out.close(); 280 } 281 { 282 ofstream out("user.txt"); 283 if(out) 284 { 285 for(i=0;i<total;i++) 286 { 287 out<<"姓名:"<<user[i].name<<' '<<"卡號:"<<user[i].card<<' '<<"密碼:"<<user[i].password<<' '<<"余額:"<<user[i].balance<<"元"<<endl; 288 } 289 out.close(); 290 } 291 } 292 system("cls"); 293 cout<<"您已成功取出"<<templemoney<<"元,卡上還余"<<user[k].balance<<"元."<<endl; 294 system("pause"); 295 } 296 } 297 else 298 { 299 user[k].balance=user[k].balance-money; 300 { 301 ofstream out("record.txt",ios::app); 302 if(out) 303 { 304 out<<"姓名:"<<user[k].name<<' '<<"卡號:"<<' '<<user[k].card<<' '<<"取出"<<money<<"元"<<endl; 305 out.close(); 306 } 307 } 308 { 309 ofstream out("user.txt"); 310 if(out) 311 { 312 for(i=0;i<total;i++) 313 { 314 out<<"姓名:"<<user[i].name<<' '<<"卡號:"<<user[i].card<<' '<<"密碼:"<<user[i].password<<' '<<"余額:"<<user[i].balance<<"元"<<endl; 315 } 316 out.close(); 317 } 318 } 319 system("cls"); 320 cout<<"您已成功取出"<<money<<"元,卡上還余"<<user[k].balance<<"元."<<endl; 321 system("pause"); 322 } 323 } 324 break; 325 case 5:system("cls"); 326 display(user,total); 327 system("pause"); 328 break; 329 case 6:cout<<endl<<"查詢余額:"<<endl; 330 cout<<"請輸入您的卡號:"; 331 cin>>templecard; 332 k=searchcard(user,total,templecard); 333 if(k==-1) 334 { 335 system("cls"); 336 cout<<"輸入有誤,賬戶不存在"<<endl; 337 system("pause"); 338 } 339 else 340 { 341 system("cls"); 342 cout<<"您的賬戶余額為:"<<user[k].balance<<"元"<<endl; 343 system("pause"); 344 } 345 break; 346 case 7:cout<<endl<<"查詢交易記錄:"<<endl; 347 cout<<"請輸入要查詢的卡號:"; 348 cin>>templecard; 349 k=searchcard(user,total,templecard); 350 if(k==-1) 351 { 352 system("cls"); 353 cout<<"輸入有誤,賬戶不存在"<<endl; 354 system("pause"); 355 } 356 else 357 { 358 ifstream in("record.txt",ios::app);//打開輸入文件流 359 if(in)//如果打開成功 360 { 361 for(i=0;i<MAX;i++) 362 { 363 in>>c[i].name>>c[i].cardno>>c[i].card>>c[i].money;//從文件讀取信息 364 } 365 system("cls"); 366 for(i=0;i<MAX;i++) 367 { 368 if(c[i].card==templecard) 369 { 370 cout<<c[i].name<<' '<<' '<<c[i].cardno<<c[i].card<<' '<<' '<<c[i].money<<endl;//顯示 371 } 372 } 373 in.close();//關閉 374 system("pause"); 375 } 376 } 377 break; 378 } 379 }while(select!=0); 380 system("cls"); 381 cout<<"歡迎使用本系統!!"<<endl; 382 return 0; 383 }?
轉載于:https://www.cnblogs.com/xautlmx/p/3493417.html
總結
以上是生活随笔為你收集整理的活期储蓄账目管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到好多桃子意味着什么
- 下一篇: 做梦梦到别人砍人是什么意思