c语言个人财务管理系统

这个是我的一个网上朋友写的,仅供大家参考:

在这里留个记录

#include<stdio.h>
#include<string.h>
#define null 0
#define max 20

 

#define ok 1
 struct record{
  char date[20];
  char operate[20];
  int num;
};
 
 
 

 
 struct list_record{
    char account[20];
    char code[20];
    char name[20];
    int rec_len;
   struct record rec[max];
}r[max];

 //系统原有数据,用户不可知

 
 
 
 
 int old_record( struct list_record r[])
{
 int i;
  for(i=0;i<5;i++)
  r[i].rec_len=5;
 strcpy(r[0].account,"ydf");
 strcpy(r[1].account,"lzc");
 strcpy(r[2].account,"lwd");
 strcpy(r[3].account,"to");
 strcpy(r[4].account,"cy");
 strcpy(r[0].code,"111111");
 strcpy(r[1].code,"111111");
 strcpy(r[2].code,"111111");
 strcpy(r[3].code,"111111");
 strcpy(r[4].code,"111111");
 strcpy(r[0].name ,"袁大富");
 strcpy(r[1].name ,"林祯诚");
 strcpy(r[2].name ,"李魏东");
 strcpy(r[3].name ,"唐欧");
 strcpy(r[4].name ,"陈阳");
 strcpy(r[0].rec[0].date,"13-01-01");
 strcpy(r[0].rec[1].date,"13-02-01");
 strcpy(r[0].rec[2].date,"13-03-01");
 strcpy(r[0].rec[3].date,"13-04-01");
 strcpy(r[1].rec[0].date,"13-01-02");
 strcpy(r[1].rec[1].date,"13-02-02");
 strcpy(r[1].rec[2].date,"13-03-02");
 strcpy(r[1].rec[3].date,"13-04-02");
 strcpy(r[2].rec[0].date,"13-01-03");
 strcpy(r[2].rec[1].date,"13-02-03");
 strcpy(r[2].rec[2].date,"13-03-03");
 strcpy(r[2].rec[3].date,"13-04-03");
 strcpy(r[3].rec[0].date,"13-01-04");
 strcpy(r[3].rec[1].date,"13-02-04");
 strcpy(r[3].rec[2].date,"13-03-04");
 strcpy(r[3].rec[3].date,"13-04-04");
 strcpy(r[4].rec[0].date,"13-01-05");
 strcpy(r[4].rec[1].date,"13-02-05");
 strcpy(r[4].rec[2].date,"13-03-05");
 strcpy(r[4].rec[3].date,"13-04-05");
 strcpy(r[0].rec[0].operate,"in");
 strcpy(r[0].rec[1].operate,"out");
 strcpy(r[0].rec[2].operate,"in");
 strcpy(r[0].rec[3].operate,"out");
 strcpy(r[1].rec[0].operate,"out");
 strcpy(r[1].rec[1].operate,"in");
 strcpy(r[1].rec[2].operate,"out");
 strcpy(r[1].rec[3].operate,"in");
 strcpy(r[2].rec[0].operate,"in");
 strcpy(r[2].rec[1].operate,"out");
 strcpy(r[2].rec[2].operate,"in");
 strcpy(r[2].rec[3].operate,"out");
 strcpy(r[3].rec[0].operate,"in");
 strcpy(r[3].rec[1].operate,"out");
 strcpy(r[3].rec[2].operate,"in");
 strcpy(r[3].rec[3].operate,"out");
 strcpy(r[4].rec[0].operate,"in");
 strcpy(r[4].rec[1].operate,"out");
 strcpy(r[4].rec[2].operate,"in");
 strcpy(r[4].rec[3].operate,"out");
  r[0].rec[0].num=3000;
  r[0].rec[1].num=-1500;
  r[0].rec[2].num=2500;
  r[0].rec[3].num=-1000;
  r[1].rec[0].num=-3000;
  r[1].rec[1].num=5000;
  r[1].rec[2].num=-1000;
  r[1].rec[2].num=2000;
  r[2].rec[0].num=1000;
  r[2].rec[1].num=-1500;
  r[2].rec[2].num=3000;
  r[2].rec[2].num=-500;
  r[3].rec[0].num=1000;
  r[3].rec[1].num=-1500;
  r[3].rec[2].num=4000;
  r[3].rec[2].num=-500;
  r[4].rec[0].num=1000;
  r[4].rec[1].num=-1500;
  r[4].rec[2].num=2000;
  r[4].rec[3].num=-500;
 return ok;
}


 
 
 
 //将数据写入文件

 
 
 void save( )
{FILE *fp;
 int i;
 if((fp=fopen("wenjian","wb"))==null)
 {printf("can not open the file.\n");
  return;
 }
 for(i=0;i<max;i++)
 if(fwrite(&r[i],sizeof(struct list_record),1,fp)!=1)
 printf("file write error.\n");
 fclose(fp);
}


 
 
 
 
 //文件读出
void load( )
{FILE *fp;
 int i;
 if((fp=fopen("wenjian","rb"))==null)
 {printf("can not open infile.\n");
  return;
 }
 for(i=0;i<max;i++)
  if(fread(&r[i],sizeof(struct list_record),1,fp)!=1)
    {if(feof(fp))
       (fclose(fp));
        return;
       }
 fclose(fp);
}

 


//将用户输入的帐号与系统中原有帐号比较,查找用户帐号
int lookup_accounts( struct list_record r[],char acc[])
{
 int i;
 for(i=0;i<5;i++)
  if(strcmp(r[i].account,acc)==0)
  {  
      return ok;
  }
  
   printf("帐号不存在,请重新输入!\n");
   return null;
 }

 

 


//检查密码函数
struct list_record check_code(struct list_record r[],char acc[],char c[])
{
 int i;
 struct list_record a;
 strcpy(a.account,"0");
 strcpy(a.code,"0");
 a.rec_len=0;
 for(i=0;i<a.rec_len;i++)
 {
  strcpy(a.rec[i].date,"0");
  strcpy(a.rec[i].operate,"0");
  a.rec[i].num=0;
 }
 for(i=0;i<5;i++)
   if(strcmp(r[i].account,acc)==0)
      if(strcmp(r[i].code,c)==0)
      return r[i];
 printf("the code is wrong,please input again!\n");
  return a;
 }

 

 

//显示用户基本信息
void print_message( struct list_record *p)
{printf("姓名:%s\n",p->name);
 printf("帐号:%s\n",(*p).account);
 }

 


//根据用户输入的日期,查找记录
int find_record( struct list_record *p,char d[])
{
 int i;
 for(i=0;i<(*p).rec_len;i++)
 {
 if(strcmp((*p).rec[i].date,d)==0)
 {
  printf("date       operate    money\n");
        printf("%s        ",(*p).rec[i].date);
        printf("%s        ",(*p).rec[i].operate);
        printf("%d \n",(*p).rec[i].num);
        return ok;
 }
 }
  if(i==(*p).rec_len)
  printf("the date is not exit!\n");
  return null;
 }

 

//插入函数,根据用户输入的信息,增加记录
int insert_record( struct list_record *p,struct  record *p1,int lop)
{
 int i;
 if((lop<1)||(lop>((*p).rec_len+1)))
 {
   printf("the position is wrong.\n");
   return 0;
 }
  else
  {
 for(i=(*p).rec_len;i>lop-1;i--)
    {
  strcpy((*p).rec[i].date,(*p).rec[i-1].date);
        strcpy((*p).rec[i].operate,(*p).rec[i-1].operate);
        (*p).rec[i].num=(*p).rec[i-1].num;
    }
   strcpy(p->rec[i].date,p1->date);
   strcpy((*p).rec[i].operate,(*p1).operate);
  (*p).rec[i].num=(*p1).num;
  (*p).rec_len++;
   return ok;
}
}

// 删除记录函数
int del_record(struct list_record *p,int lop2)
{
 int i;
 if((lop2<1)||(lop2>(*p).rec_len))
 {
  printf("the position is wrong.\n");
     return null;
 }
  else
 {
      for(i=lop2-1;i<(*p).rec_len-1;i++)
      {
    strcpy((*p).rec[i].date,(*p).rec[i+1].date);
       strcpy((*p).rec[i].operate,(*p).rec[i+1].operate);
       (*p).rec[i].num=(*p).rec[i+1].num;
      }
      (*p).rec_len--;
      return ok;
  }
}

//输出全部记录函数
 void all_print( struct list_record *p)
{ int i;
  printf("date     operate      num\n");
   for(i=0;i<(*p).rec_len;i++)
    { printf("%s      ",(*p).rec[i].date);
       printf("%s      ",(*p).rec[i].operate);
      printf("%d      ",(*p).rec[i].num);
   printf("\n");
   }
 
}

 //计算总的钱数
int sum_num( struct list_record *p)
{
 int i;
 int sum=0;
 int sum_in=0;
 int sum_out=0;
 for(i=0;i<(*p).rec_len;i++)
  {
    sum+=(*p).rec[i].num;
    if((*p).rec[i].num>0)
      sum_in+=(*p).rec[i].num;
    if((*p).rec[i].num<0)
       sum_out+=(*p).rec[i].num;
  }
  printf("总余额为: %d\n",sum);
  printf("总收入为: %d\n",sum_in);
  printf("总支出为: %d\n",sum_out);
  return ok;
}

//输出收入记录
int acc_print( struct list_record *p)
{
 int i;
 int sum_acc=0;
 printf("date     operate      num\n");
 for(i=0;i<(*p).rec_len;i++)
  if((*p).rec[i].num>0)
   {
    sum_acc+=(*p).rec[i].num;
    printf("%s      ",(*p).rec[i].date);
    printf("%s      ",(*p).rec[i].operate);
 printf("%d      ",(*p).rec[i].num);
    printf("\n");
   }
  printf("总收入金额为: %d\n",sum_acc);
   return ok;
  if(sum_acc==0)
  printf("there is no account.\n");
  return null;
}

//输出支出记录
 int pay_print( struct list_record *p)
{int i;
 int sum_pay=0;
  printf("date     operate      num\n");
 for(i=0;i<p->rec_len;i++)
  if((*p).rec[i].num<0)
   {
    sum_pay+=(*p).rec[i].num;
    printf("%s      ",(*p).rec[i].date);
  printf("%s      ",(*p).rec[i].operate);
 printf("%d      ",(*p).rec[i].num);
    printf("\n");
   }
   printf("总的支出为: %d\n",sum_pay);
   return ok;
   if(sum_pay==0)
   printf("there is no payout.\n");
   return null;
 }

 
 
 
 void main( )
{
 int j=0,n=0;
 int x,k,lop1,lop2;
 char data1[20];
 char accou[20],cod[20];
 struct record *p0;
 struct  record a;
 struct list_record b;
 struct list_record *p;
 b.rec_len=0;
  p0=&a;
 old_record(r);
 save();
 load();
while(k)
{
 printf("                   欢迎使用个人财政支出管理系统!\n");
 printf("                                           -----首字母修改版\n");
 printf("------------------------------------------------------------\n");
 printf("|                                                          |\n");                                                          
 printf("|                       1、登陆系统                        |\n");
 printf("|                       0、退出系统                        |\n");
 printf("|                                                          |\n");
 printf("------------------------------------------------------------\n");
 scanf("%d",&x);
 if(x==0)
 {
  printf("  感谢您使用本系统,再见!\n");
     break;
 }
  else
   {
    do
    {
     printf("请输入帐号:");  
     scanf("%s",accou);
    
     if(lookup_accounts(r,accou))
     { printf("请输入密码:");   
       scanf("%s",cod);
    b=check_code(r,accou,cod);
       if(b.rec_len==0)
    {do
       {
             b=check_code(r,accou,cod); 
    scanf("%s",cod);
    n++;
    }while(n<3);
   if(n=3)
           printf("您已连续四次输入错误密码,请退出系统,谢谢使用,再见!\n");
     break;
    }
     else
  {
  int mark=0;//设置标志位 用于标记是否退出
        do
     {
          if(mark==1)
    break;

         printf("---------------请选择您要进行的操作-------------------\n");
   printf("|                                                    |\n");  
      printf("|                 2、查找记录                        |\n");
      printf("|                 3、增加记录                        |\n");
      printf("|                 4、删除记录                        |\n");
      printf("|                 5、输出所有记录                    |\n");
      printf("|                 6、输出所有收入记录                |\n");
      printf("|                 7、输出所有支出记录                |\n");
   printf("|                 8、退出个人财务网站                |\n");
   printf("|                                                    |\n");
   printf("-----------------------------------------------------|\n");
   p=&b;
         print_message(p);

     scanf("%d",&k);     
        if(k==10)
        printf("感谢您使用本系统,再见!\n");
        if(k==2)
     {
            printf("请输入您要查询的日期:");
            scanf("%s",data1);
            find_record(p,data1);
     }
            if(k==3)
      {
        printf("请输入你要插入的位置:\n");
     scanf("%d",&lop1);
              printf("请输入您要添加的记录:\n");
     printf("日期:");
              scanf("%s",p0->date);
     printf("操作:");
              scanf("%s",p0->operate);
     printf("金额:");
              scanf("%d",&(p0->num));
              insert_record(p,p0,lop1);
      }
            if(k==4)
      {
               printf("请输入您要删除的记录的位置:\n");
               scanf("%d",&lop2);
               del_record(p,lop2);
      }
            if(k==5)
      {
              all_print(p);
              sum_num(p);
      }
             if(k==6)
               acc_print(p);
             if(k==7)
                pay_print(p);
    if(k==8)
    {
     mark=1;
    }
     }while(k>0);
      break;
  }
  }
    j++;
 }while(j<3);
 
 
  }printf("感谢您使用本系统,再见!\n");
    printf("-----------------------------------------------------\n\n");
  }
}

发布了145 篇原创文章 · 获赞 45 · 访问量 18万+

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览