个人银行账户管理的C++程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includeiostream#includestring#includestdlib.h#includefstreamusingnamespacestd;classconsumer;classYH{public:YH();voidset_account();//ÒøÐпª»§voiddel_account();voidtransfer(int);//תÕËvoidenter_account();voidaddmoney(int,float);voidexitYH();//Í˳öϵͳvoidfunctionshow();voidsave();voidload();//¹¦ÄܽçÃæprotected:consumer*account[20];staticintacnum;//ÕË»§Êý};intYH::acnum=0;YH::YH(){//for(inti=0;i20;i++)//{//account[i]=NULL;//}}classconsumer:publicYH{public:friendclassYH;consumer(intid,stringName,stringPassWord,floatm){ID=id;name=Name;money=m;passwd=PassWord;}consumer(){ID=0;name='0';money=0;passwd='0';}intget_id(){returnID;}voidsavemoney();//´æÇ®stringget_passwd(){returnpasswd;}//È¡µÃÃÜÂëvoiddisplay();voidfetchmoney();//È¡Ç®voidchange_passwd();voidadd_money(float);voiddec_money(float);floatget_money();//¿¨¿¨×ªÕÊprivate:intID;//¿ª»§ÕʺÅstringpasswd;//Óû§ÃÜÂëstringname;//Óû§ÐÕÃûfloatmoney;};voidYH::save(){ofstreamofile(bankdat.dat,ios::out);ofstreamoutfile(bankdat.dat,ios::out);intn=0;outfileacnum;for(;nacnum;n++){outfileaccount[n]-ID;outfileaccount[n]-money;outfileaccount[n]-name;outfileaccount[n]-passwd;}outfile.close();//__page_break__}voidYH::load(){ifstreaminfile(bankdat.dat,ios::in);if(!infile){cerr¶ÁÈ¡´íÎó,ÎÞ×ÊÁÏÖÐ!endl;return;}intn=0;intid,m;stringnam,passw;infileacnum;for(;nacnum;n++){infileid;infilem;infilenam;infilepassw;account[n]-passwd;consumer*acc=newconsumer(id,nam,passw,m);account[n]=acc;}infile.close();cout¶ÁÈ¡×ÊÁÏÕý³£!endl;}voidYH::transfer(intx){intid;coutÇëÊäÈëÕʺÅ:;cinid;intflag=1;inti=0;while((iacnum)&&(flag)){if(id==account[i]-get_id())flag=0;elsei++;}if(flag){coutÕʺŲ»´æÔÚ!endlendl;return;}floatb;coutendlÇëÊäÈëÄãҪתÕʵĽð¶î:;cinb;while(b=0){coutÇëÊäÈëÕýÈ·µÄÊý×Ö!endl;cout$;cinb;}if(account[x]-get_money()b)cout¶Ô²»Æð,½ð¶î²»¹»!!endl;else{account[x]-dec_money(b);account[i]-add_money(b);coutתÕʳɹ¦!;}return;}voidconsumer::add_money(floatx){money=x+money;}voidconsumer::dec_money(floatx){money=money-x;}voidYH::addmoney(intx,floaty){account[x]-money=account[x]-money-y;}floatconsumer::get_money(){returnmoney;}voidmain(){YHyh;yh.functionshow();}voidYH::functionshow(){intn;do{system(cls);load();coutendlÇëÄãÊäÈëÏàÓ¦µÄ²Ù×÷ÐòºÅ½øÐвÙ×÷:endl;cout1)Óû§¿ª»§endl2)ÕË»§µÇ½endl3)ÕÊ»§×¢Ïúendl4)Í˳öϵͳendl;cout$;cinn;while(n1||n4){coutÇëÊäÈëÕýÈ·µÄ²Ù×÷ÐòºÅ!endl;cout$;cinn;}switch(n){case1:set_account();break;case2:enter_account();break;case3:del_account();break;case4:exitYH();break;}cin.get();}while(true);}voidYH::enter_account(){intid;coutÇëÊäÈëÕʺÅ:;cinid;intflag=1;inti=0;//__page_break__while((iacnum)&&(flag)){if(id==account[i]-get_id())flag=0;elsei++;}if(flag){coutÕʺŲ»´æÔÚ!endlendl;return;}coutÇëÊäÈëÃÜÂë:;stringpassw;cinpassw;if(passw!=account[i]-get_passwd())return;account[i]-display();cin.get();cin.get();intn;do{system(cls);coutÇëÑ¡ÔñÄãÒª½øÐеIJÙ×÷:endl1)²é¿´ÐÅÏ¢endl2)È¡¿îendl3)´æ¿îendl4)ÐÞ¸ÄÃÜÂëendl5)תÕËendl6)·µ»Øendl;cinn;switch(n){case1:account[i]-display();break;case2:account[i]-fetchmoney();save();break;case3:account[i]-savemoney();save();break;case4:account[i]-change_passwd();save();break;case5:transfer(i);save();break;case6:return;}cin.get();cin.get();}while(1);}voidYH::set_account(){intid;stringnam;stringpassw;floatm;coutendlÇëÊäÈ뿪»§ºÅ£º;cinid;coutendlÇëÊäÈ뿪»§ÈËÐÕÃû£º;cinnam;coutendlÇëÊäÈ뿪»§ÃÜÂ룺;cinpassw;coutendlÇëÊäÈë´æÈë½ð¶î:;cinm;while(m=0){coutÇëÊäÈëÕýÈ·µÄÊý×Ö!endl;cinm;}consumer*acc=newconsumer(id,nam,passw,m);account[acnum]=acc;cout¿ª»§³É¹¦!!endlendl;acnum++;save();cin.get();return;}voidYH::del_account(){intid;coutendlÇëÊäÈëÄãҪעÏúµÄÕÊ»§ºÅ:;cinid;intflag=1;inti=0;while((iacnum)&&(flag)){if(id==account[i]-get_id()){flag=0;}else{i++;}}if(flag){coutÕʺŲ»´æÔÚ!endlendl;return;}for(intj=i;jacnum;j++){account[j]=account[j+1];}account[acnum-1]=NULL;acnum--;cout×¢Ïú³É¹¦!!endlendl;save();cin.get();return;}voidconsumer::change_passwd(){stringpwd,repwd;coutÇëÊäÈëÐÂÃÜÂ룺;cinpwd;coutÇëÔÙÊäÈëÒ»´ÎÐÂÃÜÂ룺;cinrepwd;if(pwd!=repwd)coutÄãÊäÈëµÄÁ½´ÎÃÜÂë²»Ò»Ñù,ÇëÖØÐÂÊäÈë!endl;passwd=pwd;coutÃÜÂëÐ޸ijɹ¦£¬ÇëÀμÇ!endl;cin.get();}voidconsumer::fetchmoney(){floatm;charch;do{coutendlÄãҪȡ¶àÉÙÇ®:$endl;//__page_break__cinm;while(m=0){coutÇëÊäÈëÕýÈ·µÄÊý×Ö!endl;cout$;cinm;}if(moneym){cout¶Ô²»Æð£¬ÄãµÄÓà¶î²»×ã!endl;}else{money=money-m;coutendl²Ù×÷³É¹¦£¬ÇëÊÕºÃÇ®!endl;}coutÊÇ·ñÒª¼ÌÐø¸ÃÏî²Ù×÷£º(Y/N)endl;cout$;cinch;while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y'){cout$;cinch;}}while(ch=='y'||ch=='Y');}voidconsumer::savemoney(){floatc;charch;do{coutendlÄãÒª´æ¶àÉÙÇ®:$endl;cinc;while(c=0){coutÇëÊäÈëÕýÈ·µÄÊý×Ö!endl;cout$;cinc;}money=money+c;cout²Ù×÷Òѳɹ¦!endl;coutÊÇ·ñÒª¼ÌÐø¸ÃÏî²Ù×÷£º(Y/N)endl;cout$;cinch;while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y'){cout$;cinch;}}while(ch=='y'||ch==

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功