家庭财务管理系统

文件

函数名或其他成分

参数和返回值

功能

main.c

main

参数为无,

返回值为0

实现系统处理主流程,对其他函数进行调用

data.h

struct  fina

struct _data

参数为无,

返回值为无

结构体定义;全局变量定义;

add_income.c

add_income

参数为Node *h,

返回值为h

录入收入的各类信息

add_payout.c

add_payout

参数为Node *h,

返回值为h

录入支出的各类信息

delete_income.c

delete_income

参数为Node *h, int i

返回值为h

删除收入或支出的各类信息

update_income.c

update_income

参数为Node *h, int i

返回值为h

修改收入或支出的各类信息

search_income.c

search_income

参数为Node *h, int i

返回值为无

查询收入或支出明细

count_total.c

count_total

参数为Node *h

返回值为无

统计总收入或总支出

save.c

save

参数为Node *h

返回值为无

保存数据

cover.c

cover

参数为无,

返回值为无

主界面的提示功能界面

Init.c

IniSort

参数为Node *h

返回值为无

初始化

excel.c

excel

参数为Node *h

返回值为无

将收入和收入导入excel表格

Sort.c

Sort

参数为Node *h

返回值为无

排序

Clear.c

clear

参数为Node *h

返回值为h

清空数据

Showtime.c

showtime

参数为无

返回值为无

显示时间

Quit.c

quit

参数为无

返回值为无

退出界面

accountcover.c

coveraccount

参数为无

返回值为无

账户主界面的提示功能界面

Accountinit.c

accountinit

参数为account a[MAX]

返回值为count

读取账户数据

Accountmain.c

accountmain

参数为account a[MAX],

account *b

返回值为无

账户主界面

Accountsave.c

accountsave

参数为account a[MAX],

int i

返回值为无

保存账户数据

Accountupdata.c

accountdate

参数为account a[MAX],

int i

返回值为无

修改账户数据

Registe.c

registe

参数为account a[MAX],

int i

返回值为无

创建账户

Enter.c

enter

参数为account a[MAX],

int i , account *b

返回值为flag

登入账户

# include <stdio.h>
# include "data.h"
# include <stdlib.h>
#include <string.h>
#define MAX 100
typedef struct fina
 {
 	int num; 
 	char  name[20];
    int   year;
    int   month;
    int  type;
    float money;
    char  detail[11];
	struct fina *next;
 }Node; 
 
typedef struct  _data
{
   	struct fina infro;
	struct _data *next;
} data;

typedef struct acc 
{
	char accout[20];//账户 
	char password[15];//密码 
 }account;
void accountupdate(account a[MAX], int i)
{
	account z;
	int flag = 0;
	char x[100];
	int j;
	int m; 
	printf ("请输入你要修改账户:\n");
	scanf ("%s", x);
	for (j = 0; j < i; j ++)
	{
		if (strcmp(x, a[j].accout) == 0)
		break;
	}
	if(j == i) 
		printf("请重新确定你要修改的账户\n");
	printf("请输入你要修改的密码:\n");
	scanf("%s",a[j].password); 
	printf("请再次输入你要修改的密码:\n");
	scanf("%s",z.password); 
	if(strcmp(z.password, a[j].password) != 0)
	{
		printf("密码输入不一致\n");
		flag = 1;
	} 
	if(flag == 1)
		scanf("%s",a[j].password);
}
int enter(account a[MAX], int i, account *b)
{
	int flag = 0, j;
	do{
	printf("请输入账户:\n");
	scanf("%s", b -> accout);
	printf("请输入密码:\n");
	scanf("%s", b -> password);
	for(j = 0; j < i; j ++)
	{
		if(strcmp(b -> accout, a[j].accout) == 0 && strcmp(b -> password, a[j].password) == 0)
		{
			flag = 1;
			break; 
		}		
	}
	}while (flag == 0);

	return flag;
}
int registe(account a[MAX], int i)
{
	account z;
	int j;
	int flag = 0;
	char yn;
	printf("请输入你要创建的账户名:\n");
	fflush (stdin);
	scanf("%s", a[i].accout);
	for(j = 0; j < i; j ++)
	{
		if(strcmp(a[i].accout, a[j].accout) == 0)
		{
			flag = 1;
			break; 
		}
	 } 
	if(flag == 1)
	{
	 	printf("账户重复,请重新输入。\n");
	 	scanf("%s", a[i].accout);
	}
	printf("请输入密码:\n");
	fflush(stdin);
	gets(a[i].password);
	printf("请再次输入密码:\n");
	fflush(stdin);
	gets(z.password);
	if(strcmp(z.password, a[i].password) != 0)
	{
		printf("密码输入不一致\n");
	}
	return i + 1;
}
void accountsave (account a[MAX], int i)  //保存到文件 
{
	FILE *fp;
	int k;
	fp = fopen ("account.txt", "w");
	for(k = 0; k < i; k ++)
	{
		fwrite (&a[k], sizeof (account), 1, fp);
	} 
	 fclose (fp);
}
void coveraccount()
{
	printf("\n");
	printf("\t\t\t\t**************************************\n");
	printf("\t\t\t\t**********家庭财务管理系统************\n");
	printf("\t\t\t\t======================================\n");
	printf("\t\t\t\t*          1.登录                    *\n");
	printf("\t\t\t\t*          2.注册                    *\n");
	printf("\t\t\t\t*          3.修改密码                *\n");
	printf("\t\t\t\t*          4.退出                    *\n");
	printf("\t\t\t\t======================================\n");
	printf("\t\t\t\t**************************************\n");
	printf("\t\t\t\t          请选择(1-4):");
}
int accountinit(account a[MAX])  //初始化|导入 
{
	FILE *fp; 
    int i, count = 0;
    fp = fopen ("account.txt", "r");
    if (fp == NULL)
	{
        printf ("\t\t\t\t    目前还没有该文件,正在创建\n");
        printf ("\t\t\t\t             请继续\n"); 
    }
    for (i = 0; ; i ++)
    {
    	if (fread ( &a[count], sizeof (account), 1, fp) == 1)
    	count ++;
    	else if (fread( &a[count], sizeof (account), 1, fp) != 1) 
		break;
	}
	fclose(fp);
	return count; 
}
void accountmain(account a[MAX], account *b)
{
	int choice;
	int extent = 0;
	char ch;
	int flag = 0;
	extent = accountinit (a);
	do{
		coveraccount();
		scanf ("%d", &choice);
		switch (choice)
		{	
			case 1 : 
				flag = enter(a, extent, b); 
				break;
			case 2 : 
				extent = registe(a, extent);
				strcpy(b -> accout, a[extent - 1].accout); 
				accountsave (a, extent);	
				break;				
			case 3 : 
				accountupdate (a, extent); 
				accountsave (a, extent);
				break;
			case 4 : 
				quit (); 
				break;
	 	} 
	 	fflush(stdin);
	 	system("cls"); 
	}while (ch == 'y'|| ch == 'Y');
 }
Node *add_payout (Node *p)
{
	system("cls"); 
	Node *h = NULL;
	int x;
	printf("如果想停止输入时,请在再次出现“请输入编号:”后输入0!\n"); 
	printf ("请输入编号: ");
	scanf ("%d", &x);
	while (x != 0)
	{
		h = (Node *) malloc (sizeof (Node));
		h -> type = -1;
		printf ("请输入家庭成员姓名: ");
		scanf ("%s", h -> name);
		printf ("请输入年: ");
		scanf ("%d", &h -> year);
		printf ("请输入月: ");
		scanf ("%d", &h -> month); 
		printf ("请输入金额: ");
		scanf ("%f", &h -> money); 
		printf ("请输入备注: ");
		scanf ("%s", h -> detail);
		h -> num = x;
		h -> next = p -> next;
		p -> next = h;	
		printf ("请输入编号: ");
		scanf ("%d", &x);
	}
	
	return p;
 }
Node *update_income (Node *h, int i)
{
	system("cls"); 
	int a;
	char year[15];
	int month;
	Node *p, *q;
	int x; 
	if(i == 1)
	{
		printf ("请输入你想修改内容的时间:(姓名和年)\n");
		printf ("请输入姓名:");
		scanf ("%s", year);
		printf ("请输入年:");
		scanf ("%d", &month);
		for (q = h, p = h -> next; p != NULL; q = p, p = p -> next)
		{
			if (strcmp(year, p -> name) == 0 && month == p -> year && p -> type == 1)
			break;
		}
		if (p != NULL)
		{
			printf ("请输入你想修改的内容:\n");
			printf ("修改序号 按 0\n");
			printf ("修改姓名 按 1\n"); 
			printf ("修改年份 按 2\n");
			printf ("修改月份 按 3\n");
			printf ("修改金额 按 4\n");
			printf ("修改备注 按 5\n");
			scanf ("%d", &x);
			switch (x)
			{
				case 0 : printf ("请输入你想修改的序号:"); scanf ("%d", &p -> num); break;
				case 1 : printf ("请输入你想修改的姓名:"); scanf ("%s", p -> name); break;
				case 2 : printf ("请输入你想修改的年份:"); scanf ("%d", &p -> year); break;
				case 3 : printf ("请输入你想修改的月份:"); scanf ("%d", &p -> month); break;
				case 4 : printf ("请输入你想修改的金额:"); scanf ("%f", &p -> money); break;
				case 5 : printf ("请输入你想修改的备注:"); scanf ("%s", p -> detail); break;
			}
		}
	}
	else if(i == -1)
	{
		printf ("请输入你想修改内容的时间:(姓名和年)\n");
		printf ("请输入姓名:");
		scanf ("%s", year);
		printf ("请输入年:");
		scanf ("%d", &month);
		for (q = h, p = h -> next; p != NULL; q = p, p = p -> next)
		{
			if (strcmp(year, p -> name) == 0 && month == p -> year && p -> type == -1)
			break;
		}
		if (p != NULL)
		{
			printf ("请输入你想修改的内容:\n");
			printf ("修改序号 按 0\n");
			printf ("修改姓名 按 1\n"); 
			printf ("修改年份 按 2\n");
			printf ("修改月份 按 3\n");
			printf ("修改金额 按 4\n");
			printf ("修改备注 按 5\n");
			scanf ("%d", &x);
			switch (x)
			{
				case 0 : printf ("请输入你想修改的序号:"); scanf ("%d", &p -> num); break;
				case 1 : printf ("请输入你想修改的姓名:"); scanf ("%s", p -> name); break;
				case 2 : printf ("请输入你想修改的年份:"); scanf ("%d", &p -> year); break;
				case 3 : printf ("请输入你想修改的月份:"); scanf ("%d", &p -> month); break;
				case 4 : printf ("请输入你想修改的金额:"); scanf ("%f", &p -> money); break;
				case 5 : printf ("请输入你想修改的备注:"); scanf ("%s", p -> detail); break;
			}
		}	
	}
	return h;
}
void cover()
   {
      printf("\n");
      printf("\n"); 
      printf("\t\t            ~~~~~~~~~~~~~~~~~~~~~~\n");
      printf("\t\t            ~~~~~~~~~~~~~~~~~~~~~~\n");
      printf("\t\t\t       家庭财务管理系统\n");
      printf("\t\t            ~~~~~~~~~~~~~~~~~~~~~~\n");
      printf("\t\t            ~~~~~~~~~~~~~~~~~~~~~~\n");
      printf("\t\t*******************************************\n");
      printf("\t\t收入管理:");
      printf("1.添加收入");
      printf("  2.查询收入明细\n");
      printf("\t\t\t 3.删除收入");
      printf("  4.修改收入\n");
      printf("\t\t*******************************************\n");
      printf("\t\t支出管理:");
      printf("5.添加支出");
      printf("  6.查询支出明细\n");
      printf("\t\t\t 7.删除支出");
      printf("  8.修改支出\n");
      printf("\t\t*******************************************\n");
      printf("\t\t统    计:");
      printf("9.统计总收入/总支出\n");
      printf("\t\t*******************************************\n");
      printf("\t\t导    出:");
      printf("10.导入excel表格\n");
      printf("\t\t*******************************************\n");
      printf("\t\t排    序:");
      printf("11.排序\n");
      printf("\t\t*******************************************\n");
      printf("\t\t清    空:");
      printf("12.清空数据\n");
      printf("\t\t*******************************************\n");
	  printf("\t\t退    出:0.退出系统\n");
      printf("\t\t*******************************************\n\n\n");
      
   }
Node *clear(Node *h)
{
	system("cls"); 
	FILE *fp;
	int i,flag = 1;
	system("cls");
	Node *q = h,*p = h -> next;
	
	fp = fopen("sj.txt","w");	
	printf("\n\n\n");
	printf("\t\t已清空全部收支数据");	
	printf("\n\n\n");
	h -> next = NULL;
	printf("\t\t确认返回请输入0:");
	scanf("%d", &flag); 
	
	return h;
}
void search_income (Node *h, int i)
{
	system("cls"); 
	if (i == 1)
	{
		printf ("收入明细\n");
		Node *x = h -> next;
		while (x != NULL)
		{
			if (x -> type == 1)
			{
				printf ("序号 \t\t姓名 \t\t年 \t\t月 \t\t金额 \t\t备注\n");
				printf ("%d \t\t%s \t\t%d \t\t%d \t\t%f \t\t%s ", x -> num, x -> name, x -> year, x -> month, x -> money, x -> detail);
				printf ("\n");
			}
			x = x -> next;
		}
	}
	else if (i == -1)
	{
		printf ("支出明细\n");
		Node *z = h -> next; 
		while (z != NULL)
		{
			if (z -> type == -1)
			{
				printf ("序号 \t\t姓名 \t\t年 \t\t月 \t\t金额 \t\t备注\n");
				printf ("%d \t\t%s \t\t%d \t\t%d \t\t%f \t\t%s ", z -> num, z -> name, z -> year, z -> month, z -> money, z -> detail);
				printf ("\n");
			}
			z = z -> next;
		}
	}
}
void Sort(Node *L)
{
	int choice;
	int cho;
	int i ,count = 0, num;
	Node *p, *q, *tail;
	p = L;
	printf("请选择你要排序的是收入还是支出\n"); 
	printf ("收入请按1, 支出请按2\n");
	scanf("%d", &cho);
	if(cho == 1)
	{
		while(p -> next != NULL && p -> type == 1)
		{
			count++;
			p = p -> next;
		}
		printf("请选择你要排序的方式:\n");
		printf("1、金额排序\t\t2、日期排序\t\t3、姓名排序\n");
		scanf("%d", &choice);
		if(choice == 1)
		{
			for(i = 0; i < count - 1; i ++)
			{
				num = count - i - 1;
				q = L -> next;
				p = q -> next;
				tail = L;
				while(num --)
				{
					if(q -> money > p -> money)
					{
						q -> next = p -> next;
						p -> next = q;
						tail -> next = p;
					}
					tail = tail -> next;
					q = tail -> next;
					p = q -> next;
				 } 
			} 
		}
		else if(choice == 2)
		{
			for(i = 0; i < count - 1; i ++)
			{
				num = count - i - 1;
				q = L -> next;
				p = q -> next;
				tail = L;
				while(num --)
				{
					if(q -> year >= p -> year && q -> month > p -> month)
					{
						q -> next = p -> next;
						p -> next = q;
						tail -> next = p;
					}
					tail = tail -> next;
					q = tail -> next;
					p = q -> next;
				 } 
			} 
		} 
		else if(choice == 3)
		{
			for(i = 0; i < count - 1; i ++)
			{
				num = count - i - 1;
				q = L -> next;
				p = q -> next;
				tail = L;
				while(num --)
				{
					if(strcmp (q -> name, p -> name))
					{
						q -> next = p -> next;
						p -> next = q;
						tail -> next = p;
					}
					tail = tail -> next;
					q = tail -> next;
					p = q -> next;
				 } 
			} 
		} 
	}
	else if(cho == 2)
	{
		while(p -> next != NULL && p -> type == -1)
		{
			count++;
			p = p -> next;
		}
		printf("请选择你要排序的方式:\n");
		printf("1、金额排序\t\t2、日期排序\t\t3、姓名排序");
		scanf("%d", &choice);
		if(choice == 1)
		{
			for(i = 0; i < count - 1; i ++)
			{
				num = count - i - 1;
				q = L -> next;
				p = q -> next;
				tail = L;
				while(num --)
				{
					if(q -> money > p -> money)
					{
						q -> next = p -> next;
						p -> next = q;
						tail -> next = p;
					}
					tail = tail -> next;
					q = tail -> next;
					p = q -> next;
				 } 
			} 
		}
		else if(choice == 2)
		{
			for(i = 0; i < count - 1; i ++)
			{
				num = count - i - 1;
				q = L -> next;
				p = q -> next;
				tail = L;
				while(num --)
				{
					if(q -> year >= p -> year && q -> month > p -> month)
					{
						q -> next = p -> next;
						p -> next = q;
						tail -> next = p;
					}
					tail = tail -> next;
					q = tail -> next;
					p = q -> next;
				 } 
			} 
		} 
		else if(choice == 3)
		{
			for(i = 0; i < count - 1; i ++)
			{
				num = count - i - 1;
				q = L -> next;
				p = q -> next;
				tail = L;
				while(num --)
				{
					if(strcmp (q -> name, p -> name))
					{
						q -> next = p -> next;
						p -> next = q;
						tail -> next = p;
					}
					tail = tail -> next;
					q = tail -> next;
					p = q -> next;
				 } 
			} 
		} 
	}
	printf("已排序成功,请返回主页面进行查询\n");
}
void quit()
{
	printf ("\n");
	printf ("\t                           ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★\n\n");
	puts ("\n");
	puts ("\t                             ┃                                               ┃");
	puts ("\t                             ┃                                               ┃");
	puts ("\t                             ┃     感谢访问家庭财富管理系统!欢迎下次再来!    ┃");
	puts ("\t                             ┃                                               ┃");
	puts ("\t                             ┃                                               ┃");
	puts ("\t                             ┃                  	制作人:落                 ┃");
	puts ("\t                             ┃                             2021.3.9          ┃ ");
	puts ("\n ");

}
void showtime()
{
	time_t timep;
    struct tm *p;
    time (&timep);
    p=gmtime(&timep);
    
    
    printf("现在是 %d年%d月%d日 的 %d:%02d:%02d\n",1900+p->tm_year,1+p->tm_mon,p->tm_mday, p->tm_hour + 8,p->tm_min,p->tm_sec);
    
}
void save (Node *h, account *b)  //保存到文件 
{
	FILE *fp;
	Node *p;
	fp = fopen (b -> accout, "w");
	for(p = h -> next; p != NULL; p = p -> next)
	    fwrite(p, sizeof(struct fina), 1, fp);
	fclose (fp);
}
void excel(Node *h)
{
	system("cls");
	int flag=1;
	Node *p;
	FILE*fp;
	fp=fopen("data.csv","wb+");
	fprintf(fp,"%s,%s,%s,%s,%s,%s\n","日期","姓名","收入或支出","用途","金额","备注");
	for(p=h->next;p!=NULL;p=p->next)
	{
		if(p->type==1)fprintf(fp,"%d, %d,%s, %s, %.2f,%s\n",p -> year,p -> month, p -> name,"收入",p->money, p->detail);
		if(p->type==-1)fprintf(fp,"%d, %d,%s, %s, %.2f,%s\n",p -> year,p -> month, p -> name,"支出",p->money, p->detail);
	}
	fclose(fp);
	printf("\n\n\n");
	printf("\t\t>>导出成功\n\t\t>>请在Excel文件中中查看数据\n");
	printf("\n\n");
	printf("\t\t>>确认返回请输入0:");
	scanf("%d",&flag); 
}
void Init(Node *h, account *b)  //初始化|导入 
{
	FILE *fp; 
    int i;
    fp = fopen(b -> accout, "r");//以读写方式打开文件
    if (fp == NULL)
	{
		printf("\n"); 
		printf("\n"); 
        printf ("\t\t\t\t\t    目前还没有该文件,正在创建\n");
        printf ("\t\t\t\t\t             请继续\n"); 
    }
    Node *p;
    while (p = (struct fina *) malloc (sizeof (struct fina)), fread (p, sizeof (Node), 1, fp) == 1)
    {
    	p -> next = h -> next;
    	h -> next = p;
	}
	fclose (fp);
}
Node *delete_income (Node *h, int i)
{
	system("cls"); 
	Node *p,*q;
	char name[20]; 
	int a;
	if(i == 1)
	{
		printf ("请输入姓名: ");
		scanf ("%s", name);
		for (q = h, p = h -> next; p != NULL; q = p, p = p -> next)
		{
			if(p -> type == 1)
				if (strcmp (p -> name, name) == 0)
				{
					printf ("序号 \t\t姓名 \t\t年 \t\t月 \t\t金额 \t\t备注\n");
					printf ("%d \t\t%s \t\t%d \t\t%d \t\t%f \t\t%s ", p -> num, p -> name, p -> year, p -> month, p -> money, p -> detail);
					printf ("\n");
				}
		}
		printf("请输入序号:\n");
		scanf("%d", &a);
		for (q = h, p = h -> next; p != NULL; q = p, p = p -> next)
		{
			if(p -> type == 1)
				if (p -> num == a)
				{
					break;
				}
		}
		 if (p != NULL)
		 {
		 	q -> next = p -> next;
		 	free (p);
		 }
	}
	else if(i == -1)
	{
		printf ("请输入姓名: ");
		scanf ("%s", name);
		for (q = h, p = h -> next; p != NULL; q = p, p = p -> next)
		{
			if(p -> type == 1)
				if (strcmp (p -> name, name) == 0)
				{
					printf ("序号 \t\t姓名 \t\t年 \t\t月 \t\t金额 \t\t备注\n");
					printf ("%d \t\t%s \t\t%d \t\t%d \t\t%f \t\t%s ", p -> num, p -> name, p -> year, p -> month, p -> money, p -> detail);
					printf ("\n");
				}
		}
		printf("请输入序号:\n");
		scanf("%d", &a);
		for (q = h, p = h -> next; p != NULL; q = p, p = p -> next)
		{
			if(p -> type == 1)
				if (p -> num == a)
				{
					break;
				}
		}
		 if (p != NULL)
		 {
		 	q -> next = p -> next;
		 	free (p);
		 }
	}	
	 return h;
}
void count_total (Node *h)
{
	system("cls"); 
	int a, n, k;
	float sum;
	int year, month;
	char name[20];
	Node *p = h;
	printf ("你想要查询的是总收入还是总支出。");
	printf ("总收入请按1, 总支出请按2");
	scanf ("%d", &a); 
	if (a == 1)
	{
		printf ("请选择你要统计的依据(1.姓名;2.年份;3.月份;4.总金额):");
		scanf ("%d", &n);
		sum = 0;
		k = 0;
		switch (n)
		{
			case 1 : 
				printf ("请输入姓名 :");
				scanf ("%s", name);
				while(p!=NULL)
				{
     				if(!strcmp(name, p -> name) && p -> type == 1)
					{
      					sum=sum+p->money;
      					k ++;
    				}
    				p=p->next;
   				}
   				if (k == 0) 
				   printf ("没有该数据");
				else 
					printf ("%s的收入总和为%f\n", name, sum);
					break; 
			case 2 : 
				printf ("请输入年份 :");
				scanf ("%d", &year);
				while (p != NULL)
				{
					if (year == p -> year && p -> type == 1)
					{
						sum += p -> money;
						k ++;
					}
					p = p -> next; 
				}
				if (k == 0) 
				   	printf ("没有该数据");
				else 
					printf ("%d年的收入总和为%f\n", year, sum);
				break;
			case 3 : 
				printf ("请输入月份 :");
				scanf ("%d", &month);
				while (p != NULL)
				{
					if (month == p -> month && p -> type == 1)
					{
						sum += p -> month;
						k ++;
					}
					p = p -> next;
				}
				if (k == 0) 
				   	printf ("没有该数据");
				else 
					printf ("%d月的收入总和为%f\n", month, sum);
				break;
			case 4 :
				while (p != NULL)
				{
					if (p -> type == 1)
					{
						sum += p -> money;
						p = p -> next;
					}
				}
				printf ("总收入为:%f\n", sum);
		}
	}
	else if (a == 2)
	{
		printf ("请选择你要统计的依据(1.姓名;2.年份;3.月份;4.总金额):");
		scanf ("%d", &n);
		sum = 0;
		k = 0;
		switch (n)
		{
			case 1 : 
				printf ("请输入姓名 :");
				scanf ("%s", name);
				while(p!=NULL)
				{
     				if(!strcmp(name ,p -> name) && p -> type == -1)
					{
      					sum=sum+p->money;
      					k ++;
    				}
    				p=p->next;
   				}
   				if (k == 0) 
				   printf ("没有该数据");
				else 
					printf ("%s的支出总和为%f\n", name, sum);
					break; 
			case 2 : 
				printf ("请输入年份 :");
				scanf ("%d", &year);
				while (p != NULL)
				{
					if (year == p -> year && p -> type == -1)
					{
						sum += p -> money;
						k ++;
					}
					p = p -> next; 
				}
				if (k == 0) 
				   	printf ("没有该数据");
				else 
					printf ("%d年的支出总和为%f\n", year, sum);
				break;
			case 3 : 
				printf ("请输入月份 :");
				scanf ("%d", &month);
				while (p != NULL)
				{
					if (month == p -> month && p -> type == -1)
					{
						sum += p -> month;
						k ++;
					}
					p = p -> next;
				}
				if (k == 0) 
				   	printf ("没有该数据");
				else 
					printf ("%d月的支出总和为%f\n", month, sum);
				break;
			case 4 :
				while (p != NULL)
				{
					if (p -> type == -1)
					{
						sum += p -> money;
						p = p -> next;
					}
				}
				printf ("总支出为:%f\n", sum);
		}
	}
}
Node *add_income (Node *h)
{
	system("cls"); 
	Node *p = NULL;
	int x;
	printf("如果想停止输入时,请在再次出现“请输入编号:”后输入0!\n"); 
	printf ("请输入编号: ");
	scanf ("%d", &x);
	while (x != 0)
	{
		p = (Node *) malloc (sizeof (Node));
		p -> type = 1;
		printf ("请输入家庭成员姓名: ");
		scanf ("%s", p -> name);
		printf ("请输入年: ");
		scanf ("%d", &p -> year);
		printf ("请输入月: ");
		scanf ("%d", &p -> month); 
		printf ("请输入金额: ");
		scanf ("%f", &p -> money); 
		printf ("请输入备注: ");
		scanf ("%s", p -> detail);
		p -> num = x;
		p -> next = h -> next;
		h -> next = p;	
		printf ("请输入编号: ");
		scanf ("%d", &x);
	}
	return h;
}
int main (int argc, char *argv[])
{
	system("color 0A\n");
	char c[10] = ".txt";
	account acc[200],b;
	account *mz = &b;
	Node *head = (Node *) malloc (sizeof (Node)); 
 	char is;
 	int choi; 
 	head -> next = NULL;
 	accountmain(acc, mz);
 	strcat(mz -> accout, c);
 	Init(head, mz);
	do{
		showtime();
		cover ();
		printf ("请输入菜单:");
		scanf ("%d",&choi);
		switch (choi)	
		{
  			case 1 : 
			  	head = add_income (head);
			  	save (head, mz);
  				break;
  			case 2 : 
			  	search_income (head, 1); 
  				break;
  			case 3 : 
			  	head = delete_income (head, -1);
				save (head, mz);	
		    	break;
        	case 4 :
				head = update_income (head, 1);
				save (head, mz);
				break;
			case 5 :
				head = add_payout (head);
				save (head, mz);
				break;
			case 6 :
				search_income (head, -1);
				break;
			case 7 :
				head = delete_income (head, -1);
				save (head, mz);
				break;
			case 8 :
				head = update_income (head, -1);
				save (head, mz);
				break;
			case 9 :
				count_total (head);
				break;
			case 10 :
				excel(head);
				break;
			case 11 :
				Sort(head);
				save (head, mz);
				break; 
			case 12 :
				head = clear(head);
				save (head, mz);
				break; 
			case 0 :
				quit (0);
				exit (0); 
				break;		 
  			default :
  				break;
  		}

	printf ("是否继续");
	fflush (stdin);
	scanf ("%c", &is); 
	system("cls"); 
	}while (is == 'y' || is == 'Y');
	if (is != 'y' || is != 'Y') quit (0); 	
  
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值