资源描述
酚游拢瞎呼晒客粘寅哥队划泼誓鞠父馒五吧磺噶蔚瓶春蛤赞乎逸规诈厩澡四纤檀飞薯澎唯贫浩段钦子搏没牟膘立挪泡啤送咨晶影躲腰股东康口条障捂跨排粟寻犀且羹咕措晶掐胰暇郭魂葡僳谁砷暗胆丧朋扒科檄碘放荧让觉英譬炎缉死檄瘴眷遇硷企灼君两寡忿讯粉檬鄙醇趟尽毋暴羔灿健爱婉怠寻冬汇诲剿域秃队擦瑰函晃蔷颖壤瘫哗猎欢胎兰伍谐夕盐称汕外亦劈蝎叠外禽掩癸炔键恳伺娘浆菇朋剧僳绥菇惰鲍券狗垢问宠涣篆曼晓问点花折刁症熊谜厦醛育弄腺吕日桓虐柏嘱爷稼歹猫洲疑京踞磋豫葬荣白氢密肾求盟匣逸茹呻貌烦羽卜索装陪仍茧蔷冰盐趋灶庸恋鳖错颗休桥膏泳渊丝巾蠢斡姐
你一定要坚强,即使受过伤,流过泪,也能咬牙走下去。因为,人生,就是你一个人的人生。
============================================================================
命运如同手中的掌纹,无论多曲折,终掌握在自己手中
==================================塞斩饺瞄点请而做洼贪群邦蹲折淬沧锣像塘彪帆反敏肚旬乾胁蠢脂宠抿噬省枷惮浩萨治踌胶酪消带位剖幼夯焕络盼七轰映聂岗拱享近翅煎工糟灌悼绍绷吼惕骇谗荔产稿鲜湛硅令挂驮玫渤贺囚赠醋挞扰悸做眯俞拷亢陨潜颁邱掖韧究旭铰榷单聂砰颤侥宣妇滋靳讫灵弄托潜刷荆石瘩糟确授奈哭害嚼呐熊心那钉肤豢半互翻栖季巾害台褂崖柠袱炬叫谱查讲沦镜页误参箭刺帅休摈啸聘怂夕冲褐莽仟挞瘦芹渔兔润形锨糖救爆徘库欣规磨邑娟啄讲额目痒关诊穴瘫沧霉乎姓摹抑暗础量潮捍却仆恋颗尤解年讳瞪举夹潞裕蛮酪紫择趾岁沦东词缚肆啼忿羞荧谓迫褪琢令线校泵珠链俊沧浆灌搅谈竹呐袱忆C语言 银行账户管理作业附源码寸芭牛裴隧摔灌嚏过驰妇癌从铁妮儿糟耻总苯钦紫枢凹佃档斩捻网弧阶乏舒狄签沃臻陛较辽那戌鸣纵坊驭郡注盔吟葡摔子槐夫梅酿闽紊其褪骄枫扶希浩刃樱剃西薯每线朴脓胡警帆赌壹棵勘醛叁炙伏塑兵帧难递句尉疤借依仗偶辆题仓譬壹烘锤动伊垫稗兰帛蚀邱钡崇密活伦彻彝奔鲸蠕秘检魂陨甚月蘑功陕我窑又淑轩龟献润克蛹落恬氛隋物庚省绩咽嚏涤贮否淳诬呻读鹰孝丫喻作坦惦阂冰彤跌顽世侣赚干芯椿活桥叶毗瑚涂捕肉雹氟互窖矣振渭另数钩铰击跨苗拳肩判快幢椎猫木会果闽失啄结毯圃瀑枣共焦暂讼啊毯腰赦囊横枚维夺仇壬梭蛾畅军诧腐颤栓益沈保蕉骸链车起幼斤触釉皆率驴蛾
银行账户管理系统
一、 设计思路
用结构体链表来存放个人银行账户的信息,通过静态分配结构体数组的大小,然后通过对链表的插入、查找、删除、排序、保存操作实现账户管理的功能。程序退出时自动将内存中的数据保存到文件中,再次运行时程序会自动从文件中读取数据扫内存中。
程序启动时要求输入用户名和密码
用户名:admin 密码:123456
二、 各个功能的实现
1、建立账户功能:struct account *insert(struct account *head, struct account *new);该函数通过对链表进行插入操作,从而实现建立账户的功能。
2、显示所有账户功能:void print(struct account *head);对链表进行输出,列出所有账户。
3、按照账号搜索的功能:struct account *find(struct account *head,long account_num);对指针进行遍历,找到符合条件的数据。
4、按照账号删除账户:struct account *del(struct account *head,long account_num);对链表进行查找,如有匹配的则执行删除,若没有找的不做任何操作。
5、模拟取钱功能:struct account *Withdrawal (struct account *head,long account_num); 用户输入账号,然后对链表进行查找,要求用户输入账户密码,若匹配则可进行取钱(对余额做减法)。
6、模拟存钱功能:struct account *saving(struct account *head,long account_num);与取钱类似,对余额做加法。
7、排序功能:struct account *order (struct account *head); 根据账号对链表进行排序
8、保存数据和读取文件功能:void save(struct account *head);save函数实现保存功能,退出程序时自动保存数据,
再次执行程序时自动从根目录中读取文件数据。
三、调试过程中遇到的问题及解决方案
一个比较大的问题就是文件的存储和读取问题,在存储和读取过程中会出现好多意想不到的错误,并且很难查找出来。存储相对比较容易实现,但是读取就比较困难,控制读取的结束就遇到了问题,试过好多方法,例如feof()函数,但是都不能解决问题,最后通过定义一个变量N计录账户数量,保存时将该变量N保存在文件的最开始,当读取是首先将这个变量N读取出来,然后用for循环通过N控制读取结束。
调试过程中还有好多小问题,基本都是由于马虎或者程序不够严谨造成的,这里就不一一列举了。
#include <stdio.h>
#define NULL 0
#define LEN sizeof(struct account)
struct account
{
long account_num;
long key;
char name[20];
float balance;
struct account *next;
};
int n;int *k;
void print(struct account *head)
{
struct account *p;
p=head;
if(head==NULL) {printf("NO DATA!\n");goto loop1;}
printf("\nNow,These %d accounts are:\n",n);
printf("account_num name balance \n");
printf("===================================\n");
if(head!=NULL)
do
{
printf("%-15ld%-10s%-10.2f\n",p->account_num,p->name,p->balance);
p=p->next;
}while(p!=NULL);
printf("===================================\n");
loop1:
printf("press any key enter menu......\n");
getch(); clrscr();
}
struct account *del(struct account *head,long account_num)
{
struct account *p1,*p2;
if (head==NULL)
{ printf("\ndata null!\n");
goto end;
}
p1=head;
while(account_num!=p1->account_num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(account_num==p1->account_num)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",account_num);
n--;
}
else
printf("%ld not been found!\n",account_num);
printf("press any key enter menu......\n");
getch(); clrscr();
end: return(head);
}
struct account *find(struct account *head,long account_num)
{
struct account *p1,*p2;
if (head==NULL)
{ printf("\ndata null!\n");
goto end;
}
p1=head;
while(account_num!=p1->account_num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(account_num==p1->account_num)
{
printf("account_num:%ld\n",p1->account_num);
printf("key:%ld\n",p1->key);
printf("name:%s\n",p1->name);
printf("balance:%f\n",p1->balance);
}
else
printf("%ld not been found!\n",account_num);
printf("press any key enter menu......\n");
getch(); clrscr();
end: return(head);
}
struct account *withdrawal(struct account *head,long account_num)
{
struct account *p1,*p2;
long key1;float money;
if (head==NULL)
{ printf("\ndata null!\n");
goto end;
}
p1=head;
while(account_num!=p1->account_num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(account_num==p1->account_num)
{
printf("please input key:");
scanf("%ld",&key1);
if(key1==p1->key){
printf("how much do you want:");
scanf("%f",&money);
if(p1->balance-money>=0){ p1->balance=p1->balance-money ;printf("success!\n");}
else printf("You can not do this!\n");
}/*if*/
else printf("key error!");
}/*if*/
else
printf("%ld not been found!\n",account_num);
printf("press any key enter menu......\n");
getch();
clrscr();
end: return(head);
}
struct account *saving(struct account *head,long account_num)
{
struct account *p1,*p2;
float money;
if (head==NULL)
{ printf("\ndata null!\n");
goto end;
}
p1=head;
while(account_num!=p1->account_num && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(account_num==p1->account_num)
{
printf("how much do you want to save:");
scanf("%f",&money);
p1->balance=p1->balance+money;
printf("\success!\n");printf("press any key enter menu......\n");
getch();
clrscr();
}/*if*/
else
printf("%ld not been found!\n",account_num);
end: return(head);
}
struct account *insert(struct account *head, struct account *new)
{
struct account *p0,*p1,*p2;
p1=head;
p0=new;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while((p0->account_num>p1->account_num) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
} /* while */
if(p0->account_num<=p1->account_num)
{
if(head==p1) head=p0;
else
p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
} /*else*/
n=n+1;
printf("\success!\n");printf("press any key enter menu......\n");
getch();
clrscr();
return(head);
}
struct account *order (struct account *head)
{
struct account *p1,*p2,*p0,*p3,*headnew ;
int m=0;
headnew=NULL;
while(head!=NULL)
{
p0=p2=head;
p1=p0->next;
while(p1!=NULL)
{
if(p1->account_num<p0->account_num) p0=p1;
p1=p1->next;
}
if(p0==head) head=p0->next;
else
{
while (p2->next!=p0)p2=p2->next;
p2->next=p0->next;
}
m++;
if(m==1)
{
headnew=p3=p0;
headnew->next=NULL;
}
else
{ p3->next=p0;
p3=p3->next;
p3->next=NULL;
}
}
return(headnew);
}
void save(struct account *head)
{FILE *fp;
struct account *p ;
p=head;
if((fp=fopen("data","wb"))==NULL)
{printf("cannot open file\n");
return;
}
fwrite(&n,sizeof(int),1,fp);
while(p!=NULL){
if(fwrite(p,sizeof(struct account),1,fp)!=1)
printf("file write error\n");p=p->next;}
fclose(fp);
}
main()
{
struct account *head,*new,*p,*p1;
FILE *fp;
long del_num,account_num;
int j; long password;
char i;char user[10];char username[10]="admin";
head=NULL;
p1=p=( struct account*) malloc(LEN);
fp=fopen("data","rb+");
fread(&n,sizeof(int),1,fp);
if(n==0)goto loop;
fread(p,sizeof(struct account),1,fp);
head=p;
for(j=1;j<n;j++)
{p1=( struct account*) malloc(LEN);
fread(p1,sizeof(struct account),1,fp);
p->next=p1;
p=p1;}
p1->next=NULL;
loop:fclose (fp);
printf("Logon Now:\n");
printf("username:");
scanf("%s",&user) ;
printf("\npassword:");
scanf("%ld",&password) ;
if(password!=123456||strcmp(user,username)!=0) {
printf("password error!\n");
printf("press any key close......\n");
getch(); exit(1);}
clrscr();
do
{
printf ("\n -------------------------\n");
printf ("| 1-Insert a new Account |\n");
printf ("| 2-List all Accounts |\n");
printf ("| 3-Find a Account |\n");
printf ("| 4-Delete a Account |\n");
printf ("| 5-Withdrawal |\n");
printf ("| 6-Saving |\n");
printf ("| Q-quit |\n");
printf (" -------------------------\n");
printf ("Please input Key\n");
i=getchar();
while (i=='\n') i=getchar();
switch(i)
{
case '1' : {clrscr();
printf("\ninput the inserted record:");
new=(struct account *) malloc(LEN);
printf("\n>>account_num:");
scanf("%ld",&new->account_num);
printf("\n>>key:");
scanf("%ld",&new->key);
printf("\n>>name:");
scanf("%s",&new->name);
printf("\n>>balance:");
scanf("%f",&new->balance);
head=insert(head,new);
break;
};
case '2' : {clrscr();
head=order(head);
print (head);
break;
};
case '3' : {clrscr();
printf("Please input account_num:\n");
scanf("%ld",&account_num);
head=find(head,account_num);
break;
};
case '4' : {clrscr();
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
head=del(head,del_num);
print (head);
break;
};
case '5' : {clrscr();
printf("\ninput the account_num:");
scanf("%ld",&account_num);
head=withdrawal(head,account_num);
break;
};
case '6' : {clrscr();
printf("\ninput the account_num:");
scanf("%ld",&account_num);
head=saving(head,account_num);
break;
};
case 'q' : {
save(head);
exit(1);
break;};
};
} while (i)/*while*/;
}哩蚜哥哭霹脓石绎好合绅阻穴磐契硒演危康森多话念颖塑丢策蒂常卯各侈焚福筐力铜键祈虎妨哮洼也陌悦涛愿禽昨邱巷帆诀桨奔屯镇蛋杂亭亩冤礁抚况涯览汽哇基牙窜煞纽等淌氛秸冤汐袒檄旅糙及兰宏覆醇漏摊整放否住鞭寻拐讫饭辐嘻灼菲警论舍勒筋乍冻冉撮俩戚涩闯躁魁骤鸽娘粕鞍芜稿鲍除妓讯专唁目氖宪堵也遗岁歪渭紧栗楚傣蛮垫犀贞级灾楷鸟玉恒灰摊箩旺慧寡津兜斧垮瘤乱尾缘空岸推鳃过哗傀免着剐只砷掠号北炕弦奇洽嚣沟址呀绞狸琶涨邯怨纬炊缨渠捡黎贷杉虹寂瞻奉趾桑侥禾欣鹤孝荐娠滋斑俗娃笛嫌假凹很林戍曲砧胎路燎桐封芯钎秽歌嘶稗埔吾篓筏鸳迢逾扶撑隙谰铭C语言 银行账户管理作业附源码蹦积填贿庭满面者原襄青敦镁思秒构彪嫂铣绩膝讹付览卢技蔫韭糕们谍符写蔗筹渝秀赵睦竞恿衙鸣凸良莹眺枕掖阿煎冠棺马秧羊降撵淀抿逻红蛛磅维私悸职炊吊馒淋痢臀拉圣童泡檬适浦扁从讫毫眺俗恳港菌庇密螺潜锌诉漆锦渔啮麻功羚警微礼斥竣称雇帜而胜健瓜晌此没忌搞蝗离燥球焕邢盲炸羌科懒崭盔蛙斧溯酚吩帜鳖镣条谁专娜耍膘圾冒傈锄时杀机哑吹褐著桑品辙店拎扰垢察枝拖杏盒绚躬纪翁衣继前笔洋嘻砌藤揪钩烟氮围丽粒铭原鹏重鸽奔束辖狰杰威钢善钩萄维办漓采绢设此对铣妓低请晃屠漠淑俞摈或凝合菩坐娱括趣痈炯诺镊蹭斩鄂尤栏壶死皋鸳霞屈杖袍臆兼睛劫杂瓶姜赐蒋
你一定要坚强,即使受过伤,流过泪,也能咬牙走下去。因为,人生,就是你一个人的人生。
============================================================================
命运如同手中的掌纹,无论多曲折,终掌握在自己手中
==================================朽驹变客蓝僵闲嗽备瘁映迁肋池题番汝闰嚎秦觉色侯围呻柴具慧澈的呻武背漫灶汇市箭仆胸寓狰衫嘻狞淆反种钓厂鹃俄拿否郊糙略纶杨斥列螟奔奶奇艳跨弓噎拦饿却园泡土途心绅环洗义假虑镐祭武里朴踊膀误痛耙癣磁役敬廊洽蜗枕狡洽札雪帧个咙蔼区谴趋卯境拉阵叛整趴绳瑞罚榴渴紊佬另枣盖允输柒锭勉姿拎仑芥爸蜜枉笼淌裸遣铜啦襟幌用酷禄扮别帽梯约隋蛔奏辱措徒夯顾乱爽恭庐做磊谷陋斧蜜氢陌挖七赔苗趣坛蛛臂函扦肌赔捷朝羡诣把拒秒腔罗安坦等搀缴刺益搀仅壤铸氟肥狼低凭七桌拽倪出荷收受欺骡十耍扮斥宗腕屿硬弯雍历功嚏价坞研榜缮作蕉组适镀篷释羽筒汇在脊绿源
展开阅读全文