..程序设计报告(2015 / 2016 学年第二学期)题目:家庭支出管理系统专业微电子科学与工程组长学号姓名组员学号姓名指导教师棣华指导单位日期2016年 6 月3日家庭支出管理系统一、课题容和要求1、该系统要求对一个家庭某月的支出情况进行统计和分析。
通过此课题,熟练掌握数组、指针的各种操作,以及一些算法思想的应用。
2、功能要求:(1)支出信息包括:支出类型(主要可以分为饮食,服饰装扮,礼金,教育培训,电器,健身,通讯,子女培养,旅游,文化娱乐,医疗,交通,聚会,居住等小项),金额,消费地点,消费时间等。
(2)需要实现的功能:1)用户根据口令进入系统2)输入某一月份,完成该月份的支出管理3)输入并统计该月的支出情况4)显示该月支出信息表,容应包括日期,金额等5)按支出类型进行分类统计和排序6)进行本月消费分析,即分析每项支出所占总支出的百分比,并显示分析结果7)显示按支出类型排序后的支出信息8)将排序后的容存为文件。
(3)界面友好,输入信息符合逻辑如存款金额不为负数、不可能有非数字的字符等。
二、需求分析家庭支出管理系统的功能框架图如图1所示。
图1 功能框架图(1)功能选择函数:此函数是为了让用户根据主界面选择功能并根据提示来进行操作。
(2)输入函数:为了实现将各个支出项目的类别,支出的金额以及消费的时间,地点等存入需要的文件里,所以必须先要存在存储器里。
(3)输出函数:即通过行列表来直观对应存储文件中的项目的类别,金额,消费时间及地点。
(4)分析函数:读取本月的存储文档中的信息,对本月的消费进行分析,求出本月的消费总和,分析出每项支出所占总支出的百分比,通过他们各自的项目金额所占的百分比来直观显示那个指出比较重要。
随后与本月收入进行比较,求出收支比。
(5)类别排序函数:就是将输入的信息进行按类别排序。
(6)保存函数:将本次添加的信息进行保存到相应月份的支出信息文档中。
(7)登录界面:因为家庭支出管理系统涉及到私人财务,所以需要利用密码函数对程序进行保密。
因此只有在输入正确的口令后才能进入该系统。
同时添加了一个随机验证码的验证过程。
(全文中的(1)、(2)、(3)等格式必须统一为中文括号或者英文括号。
)(中文字体:宋体,英文字体:Times New Roman,小四号,不加粗,两端对齐,1.5倍行距,首行缩进2字符,段前段后距为0)三、概要设计1 主要结构体(二级标题格式:宋体,小四号,不加粗,两端对齐,不缩进,下同)typedef struct// 定义结构体{char type[20];// 消费类型float Getsum;// 消费金额char place[20];// 消费地点int time;// 消费时间}family;family fam[80];2 主要函数流程图(1) 登录界面:包括密码函数,采用数组赋值并与预设值逐字比较的法进行密码验证。
以及验证码函数,验证码采用srand(time(NULL))与p[0]=rand()%1000产生一个0-1000的随机数作为验证码。
如图1所示是否正确密码验证菜单界面N=0;N=N+1N>5?是是图1(2)主函数:包括菜单显示函数以及功能选择函数,菜单显示函数在屏幕上输出选择界面,功能选择函数利用选择结构进入不同的功能函数模块,模块如下列所示。
在十二个月份存储文件齐全的情况下,各功能可随意使用,无使用上的顺序要求。
如图二所示;开始菜单选择区功能选择功能执行结束是否返回是否开始定义一个字符数组输入信息对“种类”赋值对“支出”赋值对“地点”赋值对“时间”赋值是否返回结束否是图2 图3(3)功能模块一信息添加函数:利用输入函数将支出信息赋值给fam,然后利用类别整理函数进行类别整理,最后利用选择结构选择某一月份,打开该月份的信息存储文档,进行信息的写入,最后关闭文件。
如图3,图4所示。
开始选择月份进入该月份相应的语句块打开该月相应存储文件打开成功逐条写入数组元素信息关闭文件结束输出“打开失败”是否开始选择月份进入该月份所在文件打开文件成功读取第一条信息指针是否指向文件末尾退出循环结束输出打印读取信息读取下一条信息是是否否图4 图5(4)功能模块二信息显示函数:利用选择结构打开某一月份的信息存储文档,然后读取其中的信息并逐行显示在屏幕上然后关闭文件。
如图5,图6所示。
开始定义一个整型数组,i=0,J=0i<n-1J=i+1,i=i+1J<nJ=J+1前元素type=后元素type将元素GetSum 大的值置前前元素type>后元素type交换前后元素type 的值i<n-1在屏幕上输出完成排序后的数组结束前元素type<后元素type否是是是是否否否图6(5)功能模块三信息分析函数:利用选择结构打开某一月份的存储文件,读取该月信息,求消费总和并求出各项支出占总支出比,随后可以输入本月的收入以求出本月的收支比。
如图7所示。
开始选择月份进入该月份相应语句打开该月份信息存储数据打开成功读取存储信息逐项对消费金额求和到达文件尾关闭文件打开文件打开文件成功读取信息并赋值给数组统计信息总数到达文件尾逐项输出项目金额占总额比例打印消费金额关闭文件输入总收入求出收支比例并输出在屏幕上结束输出“file error ”输出“file error ”是否是是否否否图7(6)功能模块四退出函数:关闭程序。
四、源程序代码#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include <malloc.h>#include <windows.h>#include <time.h>typedef struct//定义结构体{char type[20];//消费类型float Getsum;//消费金额char place[20];//消费地点int time;//消费时间}family;family fam[80];int menu_select() //显示该系统所具备的功能{int c;do{system("cls");//清屏printf("\t\t欢迎来到家庭支出管理系统(勤俭节约,避免破产,肃脸.jpg)\n");printf("\t\t** ** ** ** ** **极端简朴的菜单系统*** ** ** **\n");printf("\t\t|1.输入消费信息|\n");printf("\t\t|2.显示消费情况|\n");printf("\t\t|3.消费情况分析|\n");printf("\t\t|4.退出系统|\n");printf("\t\t** ** ** ** ** ** ** ** ** ** ** ***\n");printf("\t\t** ** ** ** ** ** ** ** ** ** ** ***\n");printf("\t\t\t请对应选择所需选项(1-4):");scanf("%d",&c);}while(c<1||c>8);return c;}void password() //密码登录部分{char d[6];char m[6];m[0]='1',m[1]='2',m[2]='3',m[3]='4',m[4]='5',m[5]='6'; //数组比较printf("请输入六位数密码:"); //输入密码for (int n=0;;){printf("请输入密码:\n");for(int i=0;i<6;i++){d[i]=getch();if(d[i]>='0'||d[i]<='9'||d[i]>='a'||d[i]<='z'||d[i]>='A'||d[i]<='Z')}if(d[0]==m[0]&&d[1]==m[1]&&d[2]==m[2]&&d[3]==m[3]&&d[4]==m[4]&&d[5]==m[5]) {printf("\n\t\t\t密码正确!请进行验证!\n");break;}if(d[0]!=m[0]||d[1]!=m[1]||d[2]!=m[2]||d[3]!=m[3]||d[4]!=m[4]||d[5]!=m[5]) //当密码错误时如下printf("\n密码错误!请重新输入:");if (n>3){printf("系统即将关闭,88!\n");system("pause");exit (0);}n++;}}void verification_code() //验证码部分{int p[1]={0};int q[1]={0};for(int k=0;;){srand(time(NULL));printf("验证码为:\n");p[0]=rand()%1000; //产生0-1000的随机数printf("%d",p[0]);printf("请输入验证码:");scanf("%d",&q[0]);“if(q[0]!=p[0])printf("验证码错误,请重新输入。
");else{printf("\n欢迎使用!\n");system("pause");break;}if(k>3){printf("系统即将关闭,88!\n");system("pause");exit (0);k++;}}int Inputitems(family sum[],int n)//输入消费信息{int i=0;char sign='y',x[10];while(sign!='n'&&sign!='N'){printf("\t\t\t种类:");scanf("\t\t\t%s",sum[n+i].type);printf("\t\t\t支出(大于0):");scanf("\t\t\t%f",&sum[n+i].Getsum);printf("\t\t\t地点:");scanf("\t\t\t%s",sum[n+i].place);printf("\t\t\t时间(0-31):");scanf("\t\t\t%d",&sum[n+i].time);if(sum[n+i].time<1||sum[n+i].time>31)return false;gets(x);printf("\t\t\t需要再次输入吗?(y/n)");scanf("\t\t\t%c",&sign);i++;}return(n+i);}void Showitems(family sum[],int n)//输出某月份的消费信息{int i=0,month;FILE *fp;printf("请选择月份;");scanf("%d",&month);printf("\t\t\t--------------------------------------\n");printf("\t\t\t种类支出地点时间\n");printf("\t\t\t--------------------------------------\n");switch(month){case 1:fp=fopen("D:\\一月支出信息.txt","r");if(fp==0){printf("file error\n");fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 2:fp=fopen("D:\\二月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 3:fp=fopen("D:\\三月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 4:fp=fopen("D:\\四月支出信息.txt","r");if(fp==0){printf("file error\n");fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 5:fp=fopen("D:\\五月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 6:fp=fopen("D:\\六月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 7:fp=fopen("D:\\七月支出信息.txt","r");if(fp==0){printf("file error\n");fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 8:fp=fopen("D:\\八月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 9:fp=fopen("D:\\九月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 10:fp=fopen("D:\\十月支出信息.txt","r");if(fp==0){printf("file error\n");fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 11:fp=fopen("D:\\十一月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;case 12:fp=fopen("D:\\十二月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);break;}printf("\t\t\t");system("pause");}{int i,j;family temp;for(i=0;i<n-1;i++){for(j=i+1;j<n;j++){if(strcmp(sum[i].type,sum[j].type)==1){temp=sum[j];sum[j]=sum[i];sum[i]=temp;}elseif(strcmp(sum[j].type,sum[i].type)==0){if(sum[i].Getsum>sum[j].Getsum){temp=sum[j];sum[j]=sum[i];sum[i]=temp;}}}for(i=1;i<n+1;i++){if(sum[i-1].Getsum!=0){printf("\t\t\t%-8s %-12f %-8s %-10d\n",sum[i-1].type,sum[i-1].Getsum,sum[i-1].place,sum[i-1]. time);}if(i>1&&i%10==0){printf("\t\t\t----------------\n");printf("\t\t\t");system("pause");printf("\t\t\t----------------\n");}}printf("\t\t\t");system("pause");}}void Analyseitems(family sum[],int n) //求各种消费类型的金额占总金额的百分比并求收支比例{float total=0,a=0,income;int i=0,j=0,month;FILE *fp;printf("请选择月份;");scanf("%d",&month);switch(month){case 1:fp=fopen("D:\\一月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\一月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i=i+1;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t项目%-8s占总比%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 2:fp=fopen("D:\\二月支出信息.txt","r");if(fp==0)printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\二月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 3:fp=fopen("D:\\三月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\三月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 4:fp=fopen("D:\\四月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\四月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 5:fp=fopen("D:\\五月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\五月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 6:fp=fopen("D:\\六月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\六月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 7:fp=fopen("D:\\七月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\七月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 8:fp=fopen("D:\\八月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\八月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 9:fp=fopen("D:\\九月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\九月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 10:fp=fopen("D:\\十月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\十月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;case 11:fp=fopen("D:\\十一月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\十一月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);case 12:fp=fopen("D:\\十二月支出信息.txt","r");if(fp==0){printf("file error\n");exit(1);}fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);while(!feof(fp)){printf("%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);total+=sum[i].Getsum;fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);}fclose(fp);fp=fopen("D:\\十二月支出信息.txt","r");while(!feof(fp)){fscanf(fp,"%s%f%s%d",sum[i].type,&sum[i].Getsum,sum[i].place,&sum[i].time);i++;n=i;};for(i=0;i<n-1;i++){printf("\t\t\t%-8s%-10f%\n",sum[i].type,sum[i].Getsum/total);}printf("消费总额为%f",total);fclose(fp);printf("请输入本月收入:");scanf("\t\t\t%f",&income);printf("\t\t\t本月收支比为%-10f\n",total/income);break;}}void save(family sum[],int n) //保存消费信息{int i,month;FILE *fp;printf("请输入当前信息所属月份:");scanf("%d",&month);switch(month){fp=fopen("D:\\一月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 2:fp=fopen("D:\\二月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 3:fp=fopen("D:\\三月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 4:fp=fopen("D:\\四月支出信息.txt","a+");if(fp==NULL)printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 5:fp=fopen("D:\\五月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 6:fp=fopen("D:\\六月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 7:fp=fopen("D:\\七月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 8:fp=fopen("D:\\八月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 9:fp=fopen("D:\\九月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)fprintf(fp,"%-8s %-12f %-8s %-10d\n",sum[i].type,sum[i].Getsum,sum[i].place,sum[i].time);fclose(fp);printf("\t\t\t保存成功!\n");break;case 10:fp=fopen("D:\\十月支出信息.txt","a+");if(fp==NULL){printf("\t\t\tthe file cannot be opened!\n");exit(1);}fseek(fp,-1,SEEK_END);for(i=0;i<n;i++)。