#include <stdio.h>#include <stdlib.h>#include <string.h>struct Data{char name[20];char riqi[8];float money;char beizhu[50];};struct list{struct Data info;struct list *next;};struct list *Inhead=NULL;struct list *Intail=NULL;struct list *zhichuhead=NULL;struct list *zhichutail=NULL;struct list *temp=NULL;void chaxun_income();void chaxun_zhichu();void xiugai_income();void xiugai_zhichu();void Save_income(){FILE *fp;fp=fopen("D:\家庭财务管理.txt","w");struct list *p = Inhead;while(p != NULL){fwrite(&p->info, sizeof(struct Data), 1, fp);p = p->next;}fclose(fp);}void Save_zhichu(){FILE *fp;fp=fopen("D:\家庭财务管理支出.txt","w");struct list *p = zhichuhead;while(p != NULL){fwrite(&p->info, sizeof(struct Data), 1, fp);p = p->next;}fclose(fp);}void Open(){FILE *fp;fp=fopen("D:\家庭财务管理.txt","r");if(fp!=NULL){struct Data linshi;while(fread(&linshi, sizeof(struct Data), 1, fp) == 1){temp=(struct list*)malloc(sizeof(struct list));temp->info=linshi;temp->next=NULL;if(Inhead == NULL){Inhead = temp;Intail = temp;}else{Intail->next = temp;Intail = temp;}}fclose(fp);}}void Menu(){ system("cls");printf("\n");printf("\n");printf("\n");printf("\n");printf("******************\n");printf("欢迎使用家庭财务管理系统\n");printf("******************\n");printf(" \n");printf(" 1:收入操作\n");printf(" 2:支出操作\n");printf(" 3:统计操作\n");printf(" 0:退出\n");}void Openzhichu(){FILE *fp;fp=fopen("D:\家庭财务管理支出.txt","r");if(fp!=NULL){struct Data linshi;while(fread(&linshi, sizeof(struct Data), 1, fp) == 1){temp=(struct list*)malloc(sizeof(struct list));temp->info=linshi;temp->next=NULL;if(zhichuhead == NULL){zhichuhead = temp;zhichutail = temp;}else{zhichutail->next = temp;zhichutail = temp;}}fclose(fp);}}void mingzi (){char chazhao[20];printf("请输入查询的名字");gets(chazhao);struct list *p = Inhead;while(p != NULL){if(strcmp(p->,chazhao)==0){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(Inhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_income();}}}void mingzi_zhichu (){char chazhao[20];printf("请输入查询的名字");gets(chazhao);struct list *p = zhichuhead;while(p != NULL){if(strcmp(p->,chazhao)==0){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(zhichuhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_zhichu();}}}void mingzi_xiugai_income(){char xiugai[20];printf("请输入修改的名字");fflush(stdin);gets(xiugai);struct list *p = Inhead;while(p != NULL){if(strcmp(p->,xiugai)==0){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_income();if(Inhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_income();}}}void mingzi_xiugai_zhichu(){char xiugai[20];printf("请输入修改的名字");fflush(stdin);gets(xiugai);struct list *p = zhichuhead;while(p != NULL){if(strcmp(p->,xiugai)==0){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_zhichu();if(zhichuhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_zhichu();}}}void riqi(){char chazhao[20];printf("请输入查询的日期");gets(chazhao);struct list *p = Inhead;while(p != NULL){if(strcmp(p->info.riqi,chazhao)==0){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(Inhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_income();}}}void riqi_zhichu(){char chazhao[20];printf("请输入查询的日期");gets(chazhao);struct list *p = zhichuhead;while(p != NULL){if(strcmp(p->info.riqi,chazhao)==0){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(zhichuhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_zhichu();}}}void riqi_xiugai_income(){char xiugai[20];printf("请输入修改的日期");fflush(stdin);gets(xiugai);struct list *p = Inhead;while(p != NULL){if(strcmp(p->info.riqi,xiugai)==0){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_income();if(Inhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_income();}}}void riqi_xiugai_zhichu(){char xiugai[20];printf("请输入修改的日期");fflush(stdin);gets(xiugai);struct list *p = zhichuhead;while(p != NULL){if(strcmp(p->info.riqi,xiugai)==0){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_zhichu();if(zhichuhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_zhichu();}}}void money (){float chazhao;printf("请输入查询的money");scanf("%f",&chazhao);fflush(stdin);struct list *p = Inhead;while(p != NULL){if(p->info.money==chazhao){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(Inhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_income();}}}void money_zhichu (){float chazhao;printf("请输入查询的money");scanf("%f",&chazhao);fflush(stdin);struct list *p = zhichuhead;while(p != NULL){if(p->info.money==chazhao){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(zhichuhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_zhichu();}}}void money_xiugai_income(){float xiugai;printf("请输入修改的money");scanf("%f",&xiugai);fflush(stdin);struct list *p = Inhead;while(p != NULL){if(p->info.money==xiugai){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_income();if(Inhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_income();}}}void money_xiugai_zhichu(){float xiugai;printf("请输入修改的money");scanf("%f",&xiugai);fflush(stdin);struct list *p = zhichuhead;while(p != NULL){if(p->info.money==xiugai){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_zhichu();if(zhichuhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_zhichu();}}}void beizhu(){char chazhao[20];printf("请输入查询的备注");gets(chazhao);struct list *p = Inhead;while(p != NULL){if(strcmp(p->info.beizhu,chazhao)==0){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(Inhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_income();}}}void beizhu_zhichu(){char chazhao[20];printf("请输入查询的备注");gets(chazhao);struct list *p = zhichuhead;while(p != NULL){if(strcmp(p->info.beizhu,chazhao)==0){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);system("PAUSE");}p = p->next;}if(zhichuhead!=NULL){char panduan;printf("是否继续查询(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){chaxun_zhichu();}}}void beizhu_xiugai_income(){char xiugai[20];printf("请输入修改的备注");fflush(stdin);gets(xiugai);struct list *p = Inhead;while(p != NULL){if(strcmp(p->info.beizhu,xiugai)==0){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_income();if(Inhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_income();}}}void beizhu_xiugai_zhichu(){char xiugai[20];printf("请输入修改的备注");fflush(stdin);gets(xiugai);fflush(stdin);struct list *p = zhichuhead;while(p != NULL){if(strcmp(p->info.beizhu,xiugai)==0){fflush(stdin);printf("姓名:");gets(p->);fflush(stdin);printf("日期:");gets(p->info.riqi);fflush(stdin);printf("支出: ");scanf("%f",&p->info.money);fflush(stdin);printf("备注:");gets(p->info.beizhu);fflush(stdin);//------}p = p->next;}Save_zhichu();if(zhichuhead!=NULL){char panduan;printf("是否继续修改(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){xiugai_zhichu();}}}void Income_menu(){system("cls");printf("\n");printf("\n");printf("\n");printf("\n");printf("******************\n");printf("欢迎使用家庭财务管理系统\n");printf("******************\n");printf(" \n");printf(" 1.添加收入\n");printf(" 2.删除收入\n");printf(" 3.查询收入\n");printf(" 4.显示收入\n");printf(" 5.修改收入\n");printf(" 0.返回上一级\n");}void zhichu_menu(){system("cls");printf("\n");printf("\n");printf("\n");printf("\n");printf("******************\n");printf("欢迎使用家庭财务管理系统\n");printf("******************\n");printf(" \n");printf(" 1.添加支出\n");printf(" 2.删除支出\n");printf(" 3.查询支出\n");printf(" 4.显示支出\n");printf(" 5.修改支出\n");printf(" 0.返回上一级\n");}void chaxun_menu(){system("cls");printf("\n");printf("\n");printf("\n");printf("\n");printf("******************\n");printf("欢迎使用家庭财务管理系统\n");printf("******************\n");printf(" \n");printf(" 1.按名字查询\n");printf(" 2.按日期查询\n");printf(" 3.按money询\n");printf(" 4.按备注查询\n");printf(" 0.返回上一级\n"); }void xiugai_menu(){system("cls");printf("\n");printf("\n");printf("\n");printf("\n");printf("******************\n");printf("欢迎使用家庭财务管理系统\n");printf("******************\n");printf(" \n");printf(" 1.按名字修改\n");printf(" 2.按日期修改\n");printf(" 3.按money修改\n");printf(" 4.按备注修改\n");printf(" 0.返回上一级\n");}void Add_income(){char panduan;do{temp=(struct list*)malloc(sizeof(struct list));printf("姓名");gets(temp->);fflush(stdin);printf("日期(XX年XX月XX日)");gets(temp->info.riqi);fflush(stdin);printf("收入");scanf("%f",&temp->info.money);fflush(stdin);printf("备注");gets(temp->info.beizhu);fflush(stdin);printf("\n");//------自己添加temp->next=NULL;if(Inhead == NULL){Inhead = temp;Intail = temp;}else{Intail->next = temp;Intail = temp;}Save_income();//后面可以添加“继续添加功能”printf("是否(Y/N)继续添加信息\n");panduan=getchar();fflush(stdin);}while(panduan=='Y'||panduan=='y');system("PAUSE");}void Add_zhichu(){char panduan;do{temp=(struct list*)malloc(sizeof(struct list));printf("姓名");gets(temp->);fflush(stdin);printf("日期(XX年XX月XX日)");gets(temp->info.riqi);fflush(stdin);printf("支出");scanf("%f",&temp->info.money);fflush(stdin);printf("备注");gets(temp->info.beizhu);fflush(stdin);printf("\n");//------自己添加temp->next=NULL;if(zhichuhead == NULL){zhichuhead = temp;zhichutail = temp;}else{zhichutail->next = temp;zhichutail = temp;}Save_zhichu();//后面可以添加“继续添加功能”printf("是否(Y/N)继续添加信息\n");panduan=getchar();fflush(stdin);}while(panduan=='Y'||panduan=='y');system("PAUSE");}void Del_income(){char shanchu[20];struct list *p=NULL;struct list *m =NULL;struct list *n =NULL;p=Inhead;printf("请输入删除姓名");gets(shanchu);if(strcmp(Inhead->,shanchu)==0){while(Inhead!=NULL && strcmp(Inhead->,shanchu)==0) {char ch;printf("找到一个数据名字为%s,确认删除Y/N?",shanchu);ch=getchar();fflush(stdin);if(ch=='y'||ch=='Y') Inhead=Inhead->next;else break;}}else{if(strcmp(Intail->,shanchu)==0){do{ m=p;p=p->next;}while(p!=Intail);m->next=NULL;}//删除尾巴else{do{m=p;p=p->next;n=p->next;}while(strcmp(p->,shanchu)!=0&&n->next!=NULL);if(strcmp(p->,shanchu)==0)m->next=n;}}//删除除头节点之外的节点,自己课后完成Save_income();if(Inhead!=NULL){char panduan;printf("是否继续删除(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){Del_income();}}}void Del_zhichu(){char shanchu[20];struct list *p=NULL;struct list *m =NULL;struct list *n =NULL;p=zhichuhead;printf("请输入删除姓名");gets(shanchu);if(strcmp(zhichuhead->,shanchu)==0){while(zhichuhead!=NULL && strcmp(zhichuhead->,shanchu)==0) {char ch;printf("找到一个数据名字为%s,确认删除Y/N?",shanchu);ch=getchar();fflush(stdin);if(ch=='y'||ch=='Y') zhichuhead=zhichuhead->next;else break;}}else{if(strcmp(zhichutail->,shanchu)==0){do{ m=p;p=p->next;}while(p!=zhichutail);m->next=NULL;}//删除尾巴else{do{m=p;p=p->next;n=p->next;}while(strcmp(p->,shanchu)!=0&&n->next!=NULL);if(strcmp(p->,shanchu)==0)m->next=n;}}Save_zhichu();//删除除头节点之外的节点,自己课后完成if(zhichuhead!=NULL){char panduan;printf("是否继续删除(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){Del_zhichu();}}}void xiugai_income(){xiugai_menu();int choice;printf(" 请输入你的选择:");scanf("%d",&choice);fflush(stdin);switch(choice){case 1: mingzi_xiugai_income();break;case 2: riqi_xiugai_income();break;case 3: money_xiugai_income();break;case 4: beizhu_xiugai_income();break;default: printf("输入错误");break;}}void xiugai_zhichu(){xiugai_menu();int choice;printf(" 请输入你的选择:");scanf("%d",&choice);fflush(stdin);switch(choice){case 1: mingzi_xiugai_zhichu();break;case 2: riqi_xiugai_zhichu();break;case 3: money_xiugai_zhichu();break;case 4: beizhu_xiugai_zhichu();break;default: printf("输入错误");break;}}void chaxun_income(){chaxun_menu();int choice;printf(" 请输入你的选择:");scanf("%d",&choice);fflush(stdin);switch(choice){case 1: mingzi();break;case 2: riqi();break;case 3: money();break;case 4: beizhu();break;default: printf("输入错误");break;}}void chaxun_zhichu(){chaxun_menu();int choice;printf(" 请输入你的选择:");scanf("%d",&choice);fflush(stdin);switch(choice){case 1: mingzi_zhichu();break;case 2: riqi_zhichu();break;case 3: money_zhichu();break;case 4: beizhu_zhichu();break;default: printf("输入错误");break;}}void Sho_income(){struct list *p = Inhead;while(p != NULL){printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("收入:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);p = p->next;}system("PAUSE");}void Sho_zhichu(){struct list *p = zhichuhead;while(p != NULL){fflush(stdin);printf("姓名:");puts(p->);printf("日期:");puts(p->info.riqi);printf("支出:");printf("%.4f\n",p->info.money);printf("备注:");puts(p->info.beizhu);p = p->next;}system("PAUSE");}void Income(){int choice;while(1){Income_menu();printf("请输入选择");scanf("%d",&choice);fflush(stdin);if(choice==0){break;}elseswitch(choice){case 1: Add_income(); Save_income();break;case 2: Del_income(); Save_income();break;case 3: chaxun_income(); Save_income();break;case 4: Sho_income(); Save_income();break;case 5: xiugai_income(); Save_income();break;}}}void zhichu(){int choice;while(1){zhichu_menu();printf("请输入选择");scanf("%d",&choice);fflush(stdin);if(choice==0){break;}elseswitch(choice){case 1: Add_zhichu(); Save_zhichu();break;case 2: Del_zhichu(); Save_zhichu();break;case 3: chaxun_zhichu(); Save_zhichu();break;case 4: Sho_zhichu(); Save_zhichu();break;case 5: xiugai_zhichu(); Save_zhichu();break;}}}void tongji_menu(){system("cls");printf("\n");printf("\n");printf("\n");printf("\n");printf("******************\n");printf("欢迎使用家庭财务管理系统\n");printf("******************\n");printf(" \n");printf(" 1.总收入\n");printf(" 2.总支出\n");printf(" 3.总资金\n");printf(" 0.返回上一级\n");}void zongshouru(){float shouru=0;struct list *linshi;linshi=Inhead;if(linshi!=NULL){do{shouru=linshi->info.money+shouru;linshi=linshi->next;}while(linshi!=NULL);printf("%.4f",shouru);system("PAUSE");}}void zongzhichu(){float zhichu=0;struct list *linshi;linshi=zhichuhead;if(linshi!=NULL){do{zhichu=linshi->info.money+zhichu;linshi=linshi->next;}while(linshi!=NULL);printf("%.4f",zhichu);system("PAUSE");}}void zongzijin(){float zhichu=0;float zongzijin;struct list *linshi;linshi=zhichuhead;if(linshi!=NULL){do{zhichu=linshi->info.money+zhichu;linshi=linshi->next;}while(linshi!=NULL);}float shouru=0;linshi=Inhead;if(linshi!=NULL){do{shouru=linshi->info.money+shouru;linshi=linshi->next;}while(linshi!=NULL);printf("%.4f",shouru-zhichu);system("PAUSE");}}void Tongji(){while(1){tongji_menu();int choice;printf(" 请输入你的选择:");scanf("%d",&choice);if(choice==0){break;}switch(choice){case 1: zongshouru();break;case 2: zongzhichu();break;case 3: zongzijin();break;default: printf("输入错误");break;}}}void Quit(){char panduan;printf("确认退出(Y/N)");panduan=getchar();fflush(stdin);if(panduan=='Y'||panduan=='y'){exit(0);}}int main(){Open();Openzhichu();system("color 72");while(1){Menu();int choice;printf(" 请输入你的选择:");scanf("%d",&choice);fflush(stdin);switch(choice){case 1: Income();break;case 2: zhichu();break;case 3: Tongji();break;case 0: Quit();break;default: printf("输入错误");break;}}return 0;}。