作者在 2010-07-01 23:57:20 发布以下内容
#include<stdio.h>
#include<string.h>
struct
{
int num;//数据编号
int shouru;//收入
int zhichu;//支出
int yue;//余额
}date[366];
int sum=0;
void win();//菜单显示
void Login()
{
int i;
FILE *user;
char name[10],pass[20],na[10],pa[20];
printf("******** 请输入你的选择: ********\n");
printf("******** 1.登陆 2.注册 3.关闭 ********\n");
scanf("%d",&i);
switch (i)
{
case 1:
{
printf("请输入你的用户名:");
scanf("%s",na);
printf("请输入你的密码:");
scanf("%s",pa);
user=fopen("user.txt","r");
Goto1:fscanf(user,"%s %s\n",name,pass);
if ((!strcmp(name,na)) && (!strcmp(pass,pa)))//判断用户名和密码
{ printf("******** 欢迎你 %s ********\n",name);
fclose(user);
win();
break;
}
else if (fopen("user.txt","r")!=NULL)
goto Goto1;//继续查找user.txt里的用户名和密码
else
{
printf("******** 密码错误 ********\n");
fclose(user);
Login();
break;
}
}
case 2:
{
user=fopen("user.txt","a");
printf("请输入你的新用户名:");
scanf("%s",name);
printf("请输入你的新密码:");
scanf("%s",pass);
fprintf(user,"%s %s",name,pass);
fprintf(user,"\n");
fclose(user);
Login();
break;
}
case 3: break;
}
}
void Input()
{
FILE *dat;
int m,n;
dat=fopen("date.txt","a");
printf("你要输入几个数据?");
scanf("%d",&m);
sum=sum+m;
printf("收入 | 支出\n");
for (n=1;n<=m;n++)
{
scanf("%d%d",&date[n].shouru,&date[n].zhichu);
fprintf(dat,"%d %d\n",date[n].shouru,date[n].zhichu);
}
fclose(dat);
printf("******** 你输入了 %d 个数据 ********\n",m);
win();
}
void all()
{
FILE *dat;
int i,x=0,y=0,z=0;
dat=fopen("date.txt","r");
for (i=1;i<=sum;i++)
{
fscanf(dat,"%d %d",&date[i].shouru,&date[i].zhichu);
date[i].num=i;
x=x+date[i].shouru;
y=y+date[i].zhichu;
z=x-y;
date[i].yue=z;
}
}
void Pr()
{
int i;
all();
printf("| 编号 | 收入 | 支出 | 余额 |\n");
for (i=1;i<=sum;i++)
printf("%-7d %-8d %-8d %-8d\n",i,date[i].shouru,date[i].zhichu,date[i].yue);
win();
}
void Over()
{
int i;
all();
printf("| 编号 | 收入 | 支出 | 余额 |\n");
for (i=1;i<=sum;i++)
if (date[i].yue<0)
printf("%-7d %-8d %-8d %-8d\n",i,date[i].shouru,date[i].zhichu,date[i].yue);
win();
}
void Lookup()
{
int a,b,i;
all();
printf("请输入A,B将查找编号A——B的数据:");
scanf("%d%d",&a,&b);
printf("| 编号 | 收入 | 支出 | 余额 |\n");
for (i=a;i<=b;i++)
printf("%-7d %-8d %-8d %-8d\n",i,date[i].shouru,date[i].zhichu,date[i].yue);
win();
}
void win()
{
int o;
printf("+-------------------------------------------------+\n");
printf("| |\n");
printf("| 欢迎来到财务管理系统 |\n");
printf("| |\n");
printf("+-------------------------------------------------+\n");
printf("| 1.改变用户 2.输入数据 |\n");
printf("| 3.查找数据 4.透支警告 |\n");
printf("| 5.显示全部 0.关闭程序 |\n");
printf("+-------------------------------------------------+\n");
printf("请输入你的选择:");
scanf("%d",&o);
switch(o)
{
case 0: break;
case 1: Login(); break;
case 2: Input(); break;
case 3: Lookup(); break;
case 4: Over(); break;
case 5: Pr(); break;
}
}
void main()
{
Login();
}
#include<string.h>
struct
{
int num;//数据编号
int shouru;//收入
int zhichu;//支出
int yue;//余额
}date[366];
int sum=0;
void win();//菜单显示
void Login()
{
int i;
FILE *user;
char name[10],pass[20],na[10],pa[20];
printf("******** 请输入你的选择: ********\n");
printf("******** 1.登陆 2.注册 3.关闭 ********\n");
scanf("%d",&i);
switch (i)
{
case 1:
{
printf("请输入你的用户名:");
scanf("%s",na);
printf("请输入你的密码:");
scanf("%s",pa);
user=fopen("user.txt","r");
Goto1:fscanf(user,"%s %s\n",name,pass);
if ((!strcmp(name,na)) && (!strcmp(pass,pa)))//判断用户名和密码
{ printf("******** 欢迎你 %s ********\n",name);
fclose(user);
win();
break;
}
else if (fopen("user.txt","r")!=NULL)
goto Goto1;//继续查找user.txt里的用户名和密码
else
{
printf("******** 密码错误 ********\n");
fclose(user);
Login();
break;
}
}
case 2:
{
user=fopen("user.txt","a");
printf("请输入你的新用户名:");
scanf("%s",name);
printf("请输入你的新密码:");
scanf("%s",pass);
fprintf(user,"%s %s",name,pass);
fprintf(user,"\n");
fclose(user);
Login();
break;
}
case 3: break;
}
}
void Input()
{
FILE *dat;
int m,n;
dat=fopen("date.txt","a");
printf("你要输入几个数据?");
scanf("%d",&m);
sum=sum+m;
printf("收入 | 支出\n");
for (n=1;n<=m;n++)
{
scanf("%d%d",&date[n].shouru,&date[n].zhichu);
fprintf(dat,"%d %d\n",date[n].shouru,date[n].zhichu);
}
fclose(dat);
printf("******** 你输入了 %d 个数据 ********\n",m);
win();
}
void all()
{
FILE *dat;
int i,x=0,y=0,z=0;
dat=fopen("date.txt","r");
for (i=1;i<=sum;i++)
{
fscanf(dat,"%d %d",&date[i].shouru,&date[i].zhichu);
date[i].num=i;
x=x+date[i].shouru;
y=y+date[i].zhichu;
z=x-y;
date[i].yue=z;
}
}
void Pr()
{
int i;
all();
printf("| 编号 | 收入 | 支出 | 余额 |\n");
for (i=1;i<=sum;i++)
printf("%-7d %-8d %-8d %-8d\n",i,date[i].shouru,date[i].zhichu,date[i].yue);
win();
}
void Over()
{
int i;
all();
printf("| 编号 | 收入 | 支出 | 余额 |\n");
for (i=1;i<=sum;i++)
if (date[i].yue<0)
printf("%-7d %-8d %-8d %-8d\n",i,date[i].shouru,date[i].zhichu,date[i].yue);
win();
}
void Lookup()
{
int a,b,i;
all();
printf("请输入A,B将查找编号A——B的数据:");
scanf("%d%d",&a,&b);
printf("| 编号 | 收入 | 支出 | 余额 |\n");
for (i=a;i<=b;i++)
printf("%-7d %-8d %-8d %-8d\n",i,date[i].shouru,date[i].zhichu,date[i].yue);
win();
}
void win()
{
int o;
printf("+-------------------------------------------------+\n");
printf("| |\n");
printf("| 欢迎来到财务管理系统 |\n");
printf("| |\n");
printf("+-------------------------------------------------+\n");
printf("| 1.改变用户 2.输入数据 |\n");
printf("| 3.查找数据 4.透支警告 |\n");
printf("| 5.显示全部 0.关闭程序 |\n");
printf("+-------------------------------------------------+\n");
printf("请输入你的选择:");
scanf("%d",&o);
switch(o)
{
case 0: break;
case 1: Login(); break;
case 2: Input(); break;
case 3: Lookup(); break;
case 4: Over(); break;
case 5: Pr(); break;
}
}
void main()
{
Login();
}