1、C语言财务管理系统源代码#includestdio.h#includestdlib.h#define MAX_NAME 11#define MAX_DETAIL 21#define MENU_COUNT 9#define DATA_FILE fa.dattypedef wnum_fi_typeincome=1,payout=-1fi_type;typedef struct_fi_infoint year;int month;fi_type type;char nameMAX_NAME;float money;char detailMAX_DETAIL;fi_info;typedef struc
2、t_fi_datafi_info info;struct_fi_data *next;fi_data;void add_income();void search_income();void delete_income();void update_income();void add_payout();void search_payout();void delete_payout();void update_payout();void count_total();void quit();void search_data(fi_type type);void delete_data(fi_type
3、type);void update_data(fi_type type);void initialize();void save_to_file();void clear_data();fi_data *get_last();fi_data *get_previous(fi_data *p);void input_info(fi_info *info);void show_info(fi_data *p,int count);fi_data *head;char menu=n| 家庭财务管理系统 |n+-+n| 收入管理 |n| 1 添加收入 |n| 2 查询收入明细 |n| 3 删除收入 |
4、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;int main()int selected=0;initialize();while(selected
5、=0 & selected请选择要进行的操作(%d - %d):,0,MENU_COUNT);if(scanf(%d,&selected)!=1|selectedMENU_COUNT)printf(输入错误!请选择 %d - %d之间的数字!按任意键重试.,0,MENU_COUNT);fflush(stdin);getchar();elsemenu_funselected();selected=0; void add_income()fi_data *p=(fi_data *)malloc(sizeof(fi_data);memset(p,0,sizeof(fi_data);p-next=NU
6、LL;input_info(&(p-info);p-info.type=income;if(head=NULL)head=p;elseget_last(head)-next=p;void search_income()search_data(income);void delete_income()delete_data(income);void update_income()update_data(income);void add_payout()fi_data *p=(fi_data*)malloc(sizeof(fi_data);memset(p,0,sizeof(fi_data);inp
7、ut_info(&(p-info);p-info.type=payout;if(head=NULL)head=p;elseget_last(head)-next=p;void search_payout()search_data(payout);void delete_payout()delete_data(payout);void update_payout()update_data(payout);void count_total()float total_income=0.0;float total_payout=0.0;fi_data *p=head;while(p!=NULL)if(
8、p-info.type=income)total_income+=p-info.money;elsetotal_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();
9、void search_data(fi_type type)int year=0;int month=0;fi_data *p=NULL;fi_data *result9=NULL;int count=0;char input= ;while(1)printf(请输入要查询的年月(例如:2009/1));if(scanf(%d/%d,&year,&month)!=2) printf(输入错误。n);elsep=head;count=0;memset(result,0,sizeof(fi_data*);while(p!=NULL)if(p-info.year=year & p-info.mont
10、h=month & p-info.type=type)if(count输入空格并回车翻页。其他键退出。);fflush(stdin);input=getchar();if(input= )memset(result,0,sizeof(fi_data*);count=0;resultcount=p;count+;elsebreak;p=p-next;if(count!=0)show_info(result,count);elseprintf(没有找到数据。n);printf(继续查找其他数据?(y or n);fflush(stdin);input=getchar();if(input=y|in
11、put=Y)continue;elsebreak;void delete_data(fi_type type)int year=0;int month=0;fi_data *p=NULL;fi_data *pre=NULL;fi_data *result9=NULL;int count=0;char input= ;int i=0;while(1)printf(请输入要查询的年月(例如:2009/1));if(scanf(%d/%d,&year,&month)!=2)printf(输入错误。n);elsep=head;count=0;memset(result,0,sizeof(fi_data
12、*);while(p!=NULL)if(p-info.year=year & p-info.month & p-info.type)if(count=9)resultcount=p;count+;elseshow_info(result,count);printf(请输入空格并回车翻页。输入对应的序号删除。其他键退出:);fflush(stdin)input=getchar();if(input= )memset(result,0,sizeof(fi_data*);count=0;resultcount=p;count+;else if(input=1 & inputnext;elsepre-
13、next=resulti-next;free(resulti);for(;i删除成功。n);elsebreak;p=p-next;if(count!=0)show_info(result,count);printf(输入对应的序号删除。其他键退出。);fflush(stdin);input=getchar();if(input=1 & inputnext;else pre-next=resulti-next;free(resulti);for(;i删除成功.n);elseprintf(没有找到数据。n);printf(继续查找数据?(y or n);fflush(stdin);input=ge
14、tchar();if(input=y | input=Y)continue;elsebreak;void update_data(fi_type type)int year=0;int month=0;fi_data *p=NULL;fi_data *pre=NULL;fi_data *result9=NULL;int count=0;char input= ;int i=0;while(1)printf(请输入要查询的年月(例如:2009/1));if(scanf(%d/%d,&year,&month)!=2)printf(输入错误。n);elsep=head;count=0;memset(
15、result,0,sizeof(fi_data*);while(p!=NULL)if(p-info.year=year & p-info.month=month & p-info.type=type)if(count输入空格并回车翻页。输入对应的序号修改。其他键退出。);fflush(stdin);input=getchar();if(input= )memset(result,0,sizeof(fi-data*);count=0;resultcount=p;count+;else if(input=1 & inputinfo);printf(修改成功。n);p=get_previous(p)
16、;elsebreak;p=p-next;if(count!=0)show_info(result,count);printf(输入对应的序号修改。其他键退出。);fflush(stdin);input=getchar();if(input=1 & inputinfo);show_info(result,count);printf(修改成功。n);elseprintf(没有找到数据。n);printf(继续查找数据?(y or n);fflush(stdin);input=getchar();if(input=y | input=Y)continue;elsebreak;void initial
17、ize()FILE *fp=NULL;fi_data *p=NULL;fi_data *last=NULL;int count=0;fp=fopen(DATA_FILE,rb);if(fp=NULL)fp=fopen(DATA_FILE,w);fclose(fp);return;p=(fi_data*)malloc(sizeof(fi_data);memset(p,0,sizeof(fi_data);p-next=NULL;while(fread(&(p-info),sizeof(fi_info),1,fp)=1)if(head=NULL)head=p;elselast=get_last();
18、last-next=p;count+;fseek(fp,count *sizeof(fi_info),SEEK_SET);p=(fi_data*)malloc(sizeof(fi_data);memset(p,0,sizeof(fi_data);p-next=NULL;free(p);p=NULL;fclose(fp);void save_to_file()FILE *fp=fopen(DATA_FILE,wb);fi_data *p=head;while(p!=NULL)fwrite(&(p-info),sizeof(fi_info),1,fp);fseek(fp,0,SEEK_END);p
19、=p-next;fclose(fp);void clear_data()fi_data *p=NULL;while(head!=NULL)if(head-next!=NULL)p=head;head=head-next;free(p);p=NULL;elsefree(head);head=NULL;fi_data *get_last()fi_data *p=head;if(p=NULL)return p;while(p!=NULL) & (p-nezt!=NULL)p=p-next;return p;fi_data *get_previous(fi_data *p)fi_data *previ
20、ous=head;while(previous!=NULL)if(previous-next=p)break; previous=previous-next;return previous;void input_info(fi_info *info)printf(请输入年月(YYYY/M):);scanf(%d/%d,*(info-year),&(info-month);printf(请输入家庭成员姓名(最大长度为 %d):,MAX_NAME - 1);scanf(%s,info-name);printf(请输入金额:);scanf(%f,&(info-money);printf(请输入备注(
21、最大长度为 %d):,MAX_DETAIL - 1);scanf(%s,info-detail);void show_info(fi_data *p,int count)int i=0;printf(+-+-+-+-+-+-+n);printf(|No.| 年-月 | 类型 | 姓名 | 金额 | 备注 |n);printf(+-+-+-+-+-+-+n);for(i=0;iinfo.year,pi-info.month, pi-info.type=income?收入:支出, pi-info.name, pi-info.money, pi-info.detail);printf(+-+-+-+-+-+-+n);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1