C语言银行账户日常管理作业附源码Word文档下载推荐.docx

上传人:聆听****声音 文档编号:808773 上传时间:2023-04-29 格式:DOCX 页数:11 大小:12.45KB
下载 相关 举报
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第1页
第1页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第2页
第2页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第3页
第3页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第4页
第4页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第5页
第5页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第6页
第6页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第7页
第7页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第8页
第8页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第9页
第9页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第10页
第10页 / 共11页
C语言银行账户日常管理作业附源码Word文档下载推荐.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C语言银行账户日常管理作业附源码Word文档下载推荐.docx

《C语言银行账户日常管理作业附源码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C语言银行账户日常管理作业附源码Word文档下载推荐.docx(11页珍藏版)》请在冰点文库上搜索。

C语言银行账户日常管理作业附源码Word文档下载推荐.docx

structaccount*order(structaccount

*head);

根据账号对链表进行排序

8、保存数据和读取文件功能:

voidsave(structaccount

save函数实现保存功能,退出程序时自动保存数据,

再次执行程序时自动从根目录中读取文件数据。

三、调试过程中遇到的问题及解决方案

一个比较大的问题就是文件的存储和读取问题,在存储和读取过程中会出现好多意想不到的错误,并且很难查找出来。

存储相对比较容易实现,但是读取就比较困难,控制读取的结束就遇到了问题,试过好多方法,例如feof()函数,但是都不能解决问题,最后通过定义一个变量N计录账户数量,保存时将该变量N保存在文件的最开始,当读取是首先将这个变量N读取出来,然后用for循环通过N控制读取结束。

调试过程中还有好多小问题,基本都是由于马虎或者程序不够严谨造成的,这里就不一一列举了。

#include<

stdio.h>

#defineNULL0

#defineLENsizeof(structaccount)structaccount

{

longaccount_num;

longkey;

charname[20];

floatbalance;

structaccount*next;

};

intn;

int*k;

voidprint(structaccount*head)

structaccount*p;

p=head;

if(head==NULL){printf("

NODATA!

\n"

);

gotoloop1;

}printf("

\nNow,These%daccountsare:

n);

printf("

account_num name balance \n"

===================================\n"

if(head!

=NULL)do

printf("

%-15ld%-10s%-10.2f\n"

p->

account_num,p->

name,p->

balance);

p=p->

next;

}while(p!

=NULL);

loop1:

pressanykeyentermenu. \n"

getch();

clrscr();

}

structaccount*del(structaccount*head,longaccount_num)

structaccount*p1,*p2;

if(head==NULL)

{printf("

\ndatanull!

gotoend;

p1=head;

while(account_num!

=p1->

account_num&

&

p1->

next!

=NULL)

p2=p1;

p1=p1->

if(account_num==p1->

account_num)

if(p1==head)head=p1->

elsep2->

next=p1->

delete:

%ld\n"

account_num);

n--;

else

%ldnotbeenfound!

end:

return(head);

structaccount*find(structaccount*head,longaccount_num)

account_num:

p1->

account_num);

key:

key);

name:

%s\n"

name);

balance:

%f\n"

structaccount*withdrawal(structaccount*head,longaccount_num)

longkey1;

floatmoney;

pleaseinputkey:

"

scanf("

%ld"

&

key1);

if(key1==p1->

key){

howmuchdoyouwant:

%f"

money);

if(p1->

balance-money>

=0){ p1->

balance=p1->

balance-money

;

success!

elseprintf("

Youcannotdothis!

}/*if*/

keyerror!

clrscr();

structaccount*saving(structaccount*head,longaccount_num)

floatmoney;

if(head==NULL)

howmuchdoyouwanttosave:

p1->

balance+money;

\success!

structaccount*insert(structaccount*head,structaccount*new)

structaccount*p0,*p1,*p2;

p1=head;

p0=new;

if(head==NULL)

head=p0;

p0->

next=NULL;

while((p0->

account_num>

account_num)&

(p1->

=NULL))

}/*while*/

if(p0->

account_num<

if(head==p1)head=p0;

else

p2->

next=p0;

p0->

next=p1;

}/*else*/n=n+1;

structaccount*order(structaccount*head)

structaccount*p1,*p2,*p0,*p3,*headnew;

intm=0;

headnew=NULL;

while(head!

p0=p2=head;

p1=p0->

while(p1!

account_num)p0=p1;

if(p0==head)head=p0->

}m++;

while(p2->

=p0)p2=p2->

p2->

next=p0->

if(m==1)

headnew=p3=p0;

headnew->

{p3->

p3=p3->

p3->

return(headnew);

voidsave(structaccount*head)

{FILE*fp;

structaccount*p;

if((fp=fopen("

data"

"

wb"

))==NULL)

{printf("

cannotopenfile\n"

return;

fwrite(&

n,sizeof(int),1,fp);

while(p!

=NULL){

if(fwrite(p,sizeof(structaccount),1,fp)!

=1)printf("

filewriteerror\n"

p=p->

fclose(fp);

main()

structaccount*head,*new,*p,*p1;

FILE*fp;

longdel_num,account_num;

intj;

longpassword;

chari;

charuser[10];

charusername[10]="

admin"

head=NULL;

p1=p=(structaccount*)malloc(LEN);

fp=fopen("

rb+"

fread(&

if(n==0)gotoloop;

fread(p,sizeof(structaccount),1,fp);

head=p;

for(j=1;

j<

n;

j++)

{p1=(structaccount*)malloc(LEN);

fread(p1,sizeof(structaccount),1,fp);

p->

p=p1;

loop:

fclose(fp);

LogonNow:

username:

%s"

user);

\npassword:

password);

if(password!

=123456||strcmp(user,username)!

=0){printf("

passworderror!

pressanykeyclose. \n"

exit

(1);

}clrscr();

do

printf("

\n \n"

|1-InsertanewAccount |\n"

printf("

|2-ListallAccounts |\n"

|3-FindaAccount |\n"

|4-DeleteaAccount |\n"

|5-Withdrawal |\n"

|6-Saving |\n"

|Q-quit |\n"

\n"

PleaseinputKey\n"

i=getchar();

while(i=='

\n'

)i=getchar();

switch(i)

case'

1'

:

{clrscr();

\ninputtheinsertedrecord:

new=(structaccount*)malloc(LEN);

\n>

>

new->

scanf("

head=insert(head,new);

break;

2'

head=order(head);

print(head);

break;

3'

Pleaseinputaccount_num:

head=find(head,account_num);

4'

\ninputthedeletednumber:

del_num);

head=del(head,del_num);

5'

\ninputtheaccount_num:

head=withdrawal(head,account_num);

6'

head=saving(head,account_num);

q'

{

save(head);

exit

(1);

}while(i)/*while*/;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2