C语言财务管理系统(源代码)

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

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

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

资源描述

#includestdio.h#includestdlib.h#defineMAX_NAME11#defineMAX_DETAIL21#defineMENU_COUNT9#defineDATA_FILEfa.dattypedefwnum_fi_type{income=1,payout=-1}fi_type;typedefstruct_fi_info{intyear;intmonth;fi_typetype;charname[MAX_NAME];floatmoney;chardetail[MAX_DETAIL];}fi_info;typedefstruct_fi_data{fi_infoinfo;struct_fi_data*next;}fi_data;voidadd_income();voidsearch_income();voiddelete_income();voidupdate_income();voidadd_payout();voidsearch_payout();voiddelete_payout();voidupdate_payout();voidcount_total();voidquit();voidsearch_data(fi_typetype);voiddelete_data(fi_typetype);voidupdate_data(fi_typetype);voidinitialize();voidsave_to_file();voidclear_data();fi_data*get_last();fi_data*get_previous(fi_data*p);voidinput_info(fi_info*info);voidshow_info(fi_data*p[],intcount);fi_data*head;charmenu[]================================================\n|家庭财务管理系统|\n+---------------------------------------------+\n|收入管理|\n|1添加收入|\n|2查询收入明细|\n|3删除收入|\n|4修改收入|\n|支出管理|\n|5添加支出|\n|6查询支出明细|\n|7删除支出|\n|8修改支出|\n|统计|\n|9统计总收入总支出|\n----------------------------------------------+\n|0退出系统|\n==============================================+\n;void(*menu_fun[])()={quit,add_income,search_income,delete_income,update_income,add_payout,search_payout,delete_payout,update_payout,count_total};intmain(){intselected=0;initialize();while(selected=0&&selected=MENU_COUNT){system(cls);printf(menu);printf(请选择要进行的操作(%d-%d):,0,MENU_COUNT);if(scanf(%d,&selected)!=1||selected0||selectedMENU_COUNT){printf(输入错误!请选择[%d-%d]之间的数字!按任意键重试...,0,MENU_COUNT);fflush(stdin);getchar();}else{menu_fun[selected]();}selected=0;}}voidadd_income(){fi_data*p=(fi_data*)malloc(sizeof(fi_data));memset(p,0,sizeof(fi_data));p-next=NULL;input_info(&(p-info));p-info.type=income;if(head==NULL){head=p;}else{get_last(head)-next=p;}}voidsearch_income(){search_data(income);}voiddelete_income(){delete_data(income);}voidupdate_income(){update_data(income);}voidadd_payout(){fi_data*p=(fi_data*)malloc(sizeof(fi_data));memset(p,0,sizeof(fi_data));input_info(&(p-info));p-info.type=payout;if(head==NULL){head=p;}else{get_last(head)-next=p;}}voidsearch_payout(){search_data(payout);}voiddelete_payout(){delete_data(payout);}voidupdate_payout(){update_data(payout);}voidcount_total(){floattotal_income=0.0;floattotal_payout=0.0;fi_data*p=head;while(p!=NULL){if(p-info.type==income){total_income+=p-info.money;}else{total_payout+=p-info.money;}p=p-next;}printf(+---------+---------+---------+\n);printf(|合计收入|合计支出|结余|\n);printf(+---------+---------+---------+\n);printf(|%12.2f|%12.2f|%12.2f|\n,total_income,total_payout,total_income-total_payout);printf(+---------+---------+---------+\n);printf(按任意键继续返回主菜单...);fflush(stdin);getchar();}voidsearch_data(fi_typetype){intyear=0;intmonth=0;fi_data*p=NULL;fi_data*result[9]={NULL};intcount=0;charinput='';while(1){printf(请输入要查询的年月(例如:2009/1));if(scanf(%d/%d,&year,&month)!=2){printf(输入错误。\n);}else{p=head;count=0;memset(result,0,sizeof(fi_data*));while(p!=NULL){if(p-info.year==year&&p-info.month==month&&p-info.type==type){if(count9){result[count]=p;count++;}else{show_info(result,count);printf(输入空格并回车翻页。其他键退出。);fflush(stdin);input=getchar();if(input==''){memset(result,0,sizeof(fi_data*));count=0;result[count]=p;count++;}else{break;}}}p=p-next;}if(count!=0){show_info(result,count);}else{printf(没有找到数据。\n);}printf(继续查找其他数据?(yorn));fflush(stdin);input=getchar();if(input=='y'||input=='Y'){continue;}else{break;}}}}voiddelete_data(fi_typetype){intyear=0;intmonth=0;fi_data*p=NULL;fi_data*pre=NULL;fi_data*result[9]={NULL};intcount=0;charinput='';inti=0;while(1){printf(请输入要查询的年月(例如:2009/1));if(scanf(%d/%d,&year,&month)!=2){printf(输入错误。\n);}else{p=head;count=0;memset(result,0,sizeof(fi_data*));while(p!=NULL){if(p-info.year==year&&p-info.month&&p-info.type){if(count=9){result[count]=p;count++;}else{show_info(result,count);printf(请输入空格并回车翻页。输入对应的序号删除。其他键退出:);fflush(stdin)input=getchar();if(input==''){memset(result,0,sizeof(fi_data*));count=0;result[count]=p;count++;}elseif(input=='1'&&input=48+count){i=input-49;pre=get_previous(result[i]);if(pre==NULL){head=head-next;}else{pre-next=result[i]-next;}free(result[i]);for(;icount-1;i++){result[i]=result[i+1];}result[i]=p;printf(删除成功。\n);}else{break;}}}p=p-next;}if(count!=0){show_info(result,count);printf(输入对应的序号删除。其他键退出。);fflush(stdin);input=getchar();if(input='1'&&input=48+count){i=input-49;pre=get_previous(result[i]);if(pre==NULL){head=head-next;}else{pre-next=result[i]-next;}free(result[i]);for(;icount-1;i++){result[i]=result[i+1];}result[i]=NULL;count--;printf(删除成功.\n);}}else{printf(没有找到数据。\n);}printf(继续查找数据?(yorn));fflush(stdin);input=getchar();if(input=='y'||input=='Y'){continue;}else{break;}}}}voidupdate_data(fi_typetype){intyear=0;intmonth=0;fi_data*p=NULL;fi_data*pre=NULL;fi_data*result[9]={NULL};intcount=0;charinput='';inti=0;while(1){printf(请输入要查询的年月(例如:2009/1));if(scanf(%d/%d,&year,&month)!=2){printf(输入错误。\n);}else{p=head;count=0;memset(result,0,sizeof(fi_data*));while(p!=NULL){if

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

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

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

×
保存成功