标题:求助,这段程序为什么始终没有办法运行啊啊?
只看楼主
月夜忆辰
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-12-5
结帖率:0
已结贴  问题点数:20 回复次数:4 
求助,这段程序为什么始终没有办法运行啊啊?
void paihangbang()    /*家庭成员收支排行榜浏览*/
 {  
    money Tm;   /*定义进行操作时的临时结构体变量*/
    money s[SIZE],yueshuju[SIZE];
    char Da[40]="",next; /*Da存储财务收支信息的文件名*/
    int recNumber=0,i,k,j,sign=0,n=0,xmonth;
    int month4[10],yue,yue2,sign2,sign3;
    float in;
    char month[10],month2[10],month3[10];
    FILE *fp;
    printf("\n请输入存储数据的文件名,按回车键结束。\n");
    gets(Da);
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,按回车键结束。\n");
        gets(Da);
    }
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
   /*将文件中的信息存入结构体数组*/
    while((fread(&Tm,sizeof(money),1,fp))!=(int)NULL)
    {
        s[recNumber].Number=Tm.Number;
        strcpy(s[recNumber].Name,Tm.Name);
        s[recNumber].in=Tm.in;
        strcpy(s[recNumber].intime,Tm.intime);
        s[recNumber].out=Tm.out;
        strcpy(s[recNumber].outtime,Tm.outtime);
        s[recNumber].sum=Tm.sum;
        recNumber++;
    }
    fclose(fp);
begin:
    yue=0;yue2=0;n=0;sign=0;sign2=0;sign3=0;
    system("cls");
        printf("##############################################################################\n");
        printf("\t\t家庭成员收支排行榜浏览\n");
        printf("\t\t1.所有家庭成员每月的收入排行\n");
        printf("\t\t2.所有家庭成员每月的支出排行\n");
        printf("##############################################################################\n");
       printf("请输入您的选择(选择1或2):\n");
       scanf("%d",&xmonth);
     printf("\n请输入您要浏览的家庭成员收支排行榜的月份\n(格式为:如二零一零年五月,输入为201005):");
     scanf("%s",month);strcat(month,"00");
        for(i=0;i<8;i++)
          {
             month2[i]=month[i]-'0';
          }
        for(i=0;i<8;i++)
         {
           yue=yue+month2[7-i]*pow(10,i);
         }
        
if(xmonth==1)
{
      for(j=0;j<recNumber;j++)
      {        
                 strcpy(month3,s[j].intime);
                   yue2=0;
                 for(i=0;i<8;i++)
                 {
                    month4[i]=month3[i]-'0';
                 }
                 for(i=0;i<8;i++)
                 {
                     yue2=yue2+month4[7-i]*pow(10,i);
                 }
                if((abs(yue-yue2)<50))
                 {   
                    for(k=0;k<=n;k++)
                    {
                           if(sign3!=1)
                           {
                                yueshuju[k].Number=s[j].Number;
                                strcpy(yueshuju[k].Name,s[j].Name);
                                yueshuju[k].in=s[j].in;
                                yueshuju[k].out=s[j].out;
                                yueshuju[k].sum=s[j].sum;
                                sign3=1;break;
                           }
                            if(strcmp(yueshuju[k].Name,s[j].Name)==0)
                            {
                                yueshuju[k].in=yueshuju[k].in+s[j].in;
                                yueshuju[k].out=yueshuju[k].out+s[j].out;
                                yueshuju[k].sum=yueshuju[k].sum+s[j].sum;
                                sign=1;break;
                            }
                            else
                            {
                                  if(k==n&&sign!=1)
                                  {
                                      yueshuju[k+1].Number=s[j].Number;
                                      strcpy(yueshuju[k+1].Name,s[j].Name);
                                      yueshuju[k+1].in=s[j].in;
                                      yueshuju[k+1].out=s[j].out;
                                      yueshuju[k+1].sum=s[j].sum;
                                      n=k+1;break;
                                  }
                            }               
                    }   
                    sign2=1;
                 }
                else
                {
                    if(j==recNumber-1&&sign2!=1)
                    {printf("\n输入错误!财务信息没有该月份的记录。\n");sign2=0;}
                }
        sign=0;
      }
     
      /*用选择排序法进行按收入的排序*/
      if(sign2==1)
      {
          for(i=0;i<n;i++)
          {
            k=i;
            for(j=i+1;j<=n;j++)
            {
                if(yueshuju[k].in<yueshuju[j].in) k=j;
            }
            Tm.Number=yueshuju[k].Number;
            strcpy(Tm.Name,yueshuju[k].Name);
            Tm.in=yueshuju[k].in;
            Tm.out=yueshuju[k].out;
            Tm.sum=yueshuju[k].sum;
            yueshuju[k].Number=yueshuju[i].Number;
            strcpy(yueshuju[k].Name,yueshuju[i].Name);
            yueshuju[k].in=yueshuju[i].in;
            yueshuju[k].out=yueshuju[i].out;
            yueshuju[k].sum=yueshuju[i].sum;
            yueshuju[i].Number=Tm.Number;
            strcpy(yueshuju[i].Name,Tm.Name);
            yueshuju[i].in=Tm.in;
            yueshuju[i].out=Tm.out;
            yueshuju[i].sum=Tm.sum;
        }
          system("cls");
      printf("\n###########################################");
      printf("\n#####%d年%d月份所有家庭成员收入排行榜#####\n",yue/10000,(yue/100)%100);
      printf("###########################################\n");
      for(i=0;i<=n;i++)
      {
          printf("\n收入第%d名\n",i+1);
          printf("成员编号:%ld\n",yueshuju[i].Number);
          printf("成员姓名:%s\n",yueshuju[i].Name);
          printf("月总收入:%.2f元\n",yueshuju[i].in);
          printf("月总支出:%.2f元\n",yueshuju[i].out);
          printf("月总计:%.2f元\n",yueshuju[i].sum);
          printf("###########################################");
          yueshuju[i].in=0;yueshuju[i].out=0;yueshuju[i].sum=0;
      }
  }
    printf("\n继续?(是: y/Y,否:n/N)\n");
     next=getche();
     putchar('\n');system("cls");
     if(next=='y'||next=='Y') goto begin;
}
 if(xmonth==2)
 {
    for(j=0;j<recNumber;j++)
      {        
                 strcpy(month3,s[j].intime);
                   yue2=0;
                 for(i=0;i<8;i++)
                 {
                    month4[i]=month3[i]-'0';
                 }
                 for(i=0;i<8;i++)
                 {
                     yue2=yue2+month4[7-i]*pow(10,i);
                 }
                if((abs(yue-yue2)<50))
                 {   
                    for(k=0;k<=n;k++)
                    {
                           if(sign3!=1)
                           {
                                yueshuju[k].Number=s[j].Number;
                                strcpy(yueshuju[k].Name,s[j].Name);
                                yueshuju[k].in=s[j].in;
                                yueshuju[k].out=s[j].out;
                                yueshuju[k].sum=s[j].sum;
                                sign3=1;break;
                           }
                            if(strcmp(yueshuju[k].Name,s[j].Name)==0)
                            {
                                yueshuju[k].in=yueshuju[k].in+s[j].in;
                                yueshuju[k].out=yueshuju[k].out+s[j].out;
                                yueshuju[k].sum=yueshuju[k].sum+s[j].sum;
                                sign=1;break;
                            }
                            else
                            {
                                  if(k==n&&sign!=1)
                                  {
                                      yueshuju[k+1].Number=s[j].Number;
                                      strcpy(yueshuju[k+1].Name,s[j].Name);
                                      yueshuju[k+1].in=s[j].in;
                                      yueshuju[k+1].out=s[j].out;
                                      yueshuju[k+1].sum=s[j].sum;
                                      n=k+1;break;
                                  }
                            }               
                    }   
                    sign2=1;
                 }
                else
                {
                    if(j==recNumber-1&&sign2!=1)
                    {printf("\n输入错误!财务信息没有该月份的记录。\n");sign2=0;}
                }
        sign=0;
      }
     
      /*用选择排序法进行按支出的排序*/
      if(sign2==1)
      {
          for(i=0;i<n;i++)
          {
            k=i;
            for(j=i+1;j<=n;j++)
            {
                if(yueshuju[k].out<yueshuju[j].out) k=j;
            }
            Tm.Number=yueshuju[k].Number;
            strcpy(Tm.Name,yueshuju[k].Name);
            Tm.in=yueshuju[k].in;
            Tm.out=yueshuju[k].out;
            Tm.sum=yueshuju[k].sum;


            yueshuju[k].Number=yueshuju[i].Number;
            strcpy(yueshuju[k].Name,yueshuju[i].Name);
            yueshuju[k].in=yueshuju[i].in;
            yueshuju[k].out=yueshuju[i].out;
            yueshuju[k].sum=yueshuju[i].sum;

            yueshuju[i].Number=Tm.Number;
            strcpy(yueshuju[i].Name,Tm.Name);
            yueshuju[i].in=Tm.in;
            yueshuju[i].out=Tm.out;
            yueshuju[i].sum=Tm.sum;
          }
          system("cls");
      printf("\n###########################################");
      printf("\n#####%d年%d月份所有家庭成员支出排行榜#####\n",yue/10000,(yue/100)%100);
      printf("###########################################\n");
      for(i=0;i<=n;i++)
      {
          printf("\n支出第%d名\n",i+1);
          printf("成员编号:%ld\n",yueshuju[i].Number);
          printf("成员姓名:%s\n",yueshuju[i].Name);
          printf("月总收入:%.2f元\n",yueshuju[i].in);
          printf("月总支出:%.2f元\n",yueshuju[i].out);
          printf("月总计:%.2f元\n",yueshuju[i].sum);
          printf("###########################################");
          yueshuju[i].in=0;yueshuju[i].out=0;yueshuju[i].sum=0;
      }
  }
    printf("\n继续?(是: y/Y,否:n/N)\n");
     next=getche();
     putchar('\n');system("cls");
     if(next=='y'||next=='Y') goto begin;
 }
}
搜索更多相关主题的帖子: 排行榜 money 结构体 
2012-07-06 16:16
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
得分:20 
为什么,报错信息和完整程序呢?
2012-07-06 16:40
月夜忆辰
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-12-5
得分:0 
#include"stdio.h"
#include "stdlib.h"
#include"windows.h"
#include "string.h"
#include"conio.h"
#include"math.h"
#define SIZE 1000
typedef struct
{
    long no;            /*每一组输入的编号*/
    long Number;        /*家庭成员编号*/
    char Name[20];      /*家庭成员姓名*/
    float in;           /*家庭成员收入*/
    char intime[10];    /*收入时间*/
    float out;          /*家庭成员支出*/
    char outtime[10];   /*支出时间*/
    float sum;          /*总计*/
}money;
typedef struct
{
    long Number;     /*家庭成员编号*/
    char Name[20];   /*家庭成员姓名*/
    char ps[10];      /*家庭成员密码*/
    int power;       /*家庭成员权限*/
}user;
void tianjiashouzhi()/*添加财务收支信息记录*/
{
    FILE *fp = NULL;         /*定义指向文件的指针*/
    money Tm,ch;           /*定义进行操作时的临时结构体变量*/
    char Da[40] = "",next;  /*存储财务收支信息的文件名*/
    int count;           /*计算可输入数据的最大范围*/
    /*====输入要添加财务收支信息的文件名====*/
    printf("\n 请输入要添加财务收支信息的文件名:");
    printf("\n 注意:文件名不能超过八位字符,后缀不能超过三位字符。\n");
    gets(Da);
    /*如家长没有输入,则循环提示家长输入*/
    while(*Da==('\0'))
    {
        printf("\n 请输入用来存储数据的文件名,以回车键结束。");
        printf("\n 注意:文件名不能超过八位字符,后缀不能超过三位字符。\n");
        gets(Da);
    }
begin: count=1;
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n 打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
  while(fread(&ch,sizeof(money),1,fp)!=(int)NULL)
  {
      count++;
  }
  fclose(fp);
    /*如果成功打开或创建文件,则提示输入家庭成员序号、姓名、收入、支出等相关信息*/
   fp=fopen(Da,"ab+");/*a+:当文件存在时,追加,当文件不存在时,创建*/
       /*如果当前文件不存在,提示打开文件失败*/
       if (fp==NULL)
        {
           printf("\n 打开文件 %s 失败!按任意键结束!\n",Da);
           exit(0);
        }
    printf("输入编号,姓名,收入,收入时间,支出,支出时间,输入编号为0时结束!\n");
    printf("编号不超过九位,姓名不超过二十个字符。\n");
    printf("如果只需输入收入或支出其中一项,则另外一项收入或支出为零,时间与输入项相同。\n");
    printf("输入时间与输出时间应为同一个月。\n");
   
    while(count<=SIZE)
   {
        Tm.no=count;
        printf("\n 输入 编号为零时结束输入!\n");
        printf("成员编号:");
        scanf("%ld",&Tm.Number);
        if (Tm.Number==0 )
            break;
        printf("成员姓名:");
        scanf("%s",Tm.Name);
        printf("成员收入:");
        scanf("%f",&Tm.in);
        printf("收入时间:");
        scanf("%s",Tm.intime);
        printf("成员支出:");
        scanf("%f",&Tm.out);
        printf("支出时间:");
        scanf("%s",Tm.outtime);
        Tm.sum=Tm.in-Tm.out;
        printf("\n");   
        if(fwrite(&Tm,sizeof(money),1,fp)!=1)
        {
            printf("\n写入文件 %s 失败!以任意键结束!\n",Da);
            exit(0);
        }
       count=count+1;
    }
    /*如果输入的数据量超过最大允许的范围,则提示数据不能录入*/
    if (count>SIZE)
        printf("\n对不起,输入的数据量超过最大允许的范围%d\n",SIZE);
    fclose(fp);
    system("cls");
    printf("您输入的数据已成功存储在 %s 文件中。\n",Da);
    printf("文件全部内容如下:\n");
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件%s失败!按任意键结束!\n",Da);
        exit(0);
    }
    while(fread(&Tm,sizeof(money),1,fp)!=(int)NULL)
    {
        printf("\n成员编号:%ld\n",Tm.Number);
        printf("成员姓名:%s\n",Tm.Name);
        printf("成员收入:%.2f元\n",Tm.in);
        printf("收入时间:%s\n",Tm.intime);
        printf("成员支出:%.2f元\n",Tm.out);
        printf("支出时间:%s\n",Tm.outtime);
        printf("############################\n");
    }
    fclose(fp);
    /*询问是否继续删除*/
    printf("\n是否继续?(是:y/Y;否:n/N)");
    next=getche();system("cls");
    putchar('\n');
    if ( next=='y'||next=='Y') goto begin;
}
void shanchucaiwu()    /*删除家庭成员财务信息记录*/
 {
    int i;
    long delnum;      /*存放家长输入的要删除家庭成员序号*/
    money Tm;    /*定义进行操作时的临时结构体变量*/
    money s[SIZE];
    int recNumber;    /*原文件中的记录数*/
    char Da[40]= "",next;
    FILE *fp;/*fp指针指向存储数据的文件名*/
    printf("\n请输入存储数据的文件名,按任意键结束!\n");
    gets(Da);
    /*提示家长输入要进行删除的文件名*/
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,以回车键结束!\n");
        gets(Da);
    }
begin:
    /*以二进制读的方式打开文件*/
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    /*输入要删除的家庭成员序号*/
    printf("请输入要删除的家庭成员编号:");
    scanf("%ld",&delnum);
    printf("您要删除的编号是:%ld\n",delnum);
   /*将文件中信息存入结构体数组*/
   /*与要删除的家庭成员序号相匹配的项不写入数组,
   循环后数组中即为去掉了要删除记录后的剩余记录*/
   recNumber=0;
    while((fread(&Tm,sizeof(money),1,fp))!=(int)NULL)
    {
        if(Tm.Number!=delnum)
            {
            s[recNumber].no=Tm.no;
            s[recNumber].Number=Tm.Number;
            strcpy(s[recNumber].Name, Tm.Name);
            s[recNumber].in=Tm.in;
            strcpy(s[recNumber].intime,Tm.intime);
            s[recNumber].out=Tm.out;
            strcpy(s[recNumber].outtime,Tm.outtime);
            s[recNumber].sum=Tm.sum;
            recNumber++;
            }
    }
    fclose(fp);
        /*将删除后的剩余结构体记录写入文件*/
        fp=fopen(Da,"wb+");
        if (fp==NULL)
        {
            printf("\n记录文件 %s失败!按任意键结束!\n",Da);
            exit(0);
        }
        for(i=0;i<recNumber;i++)
        {
            if(fwrite(&s[i],sizeof(money),1,fp)!=1)
            {
                printf("\n记录文件 %s 失败!按任意键结束!\n",Da);
                    exit(0);
            }
        }
        fclose(fp);
/*显示删除财务信息记录后的文件*/
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件%s失败!按任意键结束! \n",Da);
        exit(0);
    }
    printf("删除后的文件全部内容是:\n");
     while(fread(&Tm,sizeof(money),1,fp)!=(int)NULL)
    {
        printf("\n成员编号:%ld\n",Tm.Number);
        printf("成员姓名:%s\n",Tm.Name);
        printf("成员收入:%.2f元\n",Tm.in);
        printf("收入时间:%s\n",Tm.intime);
        printf("成员支出:%.2f元\n",Tm.out);
        printf("支出时间:%s\n",Tm.outtime);
        printf("############################\n");
    }
    fclose(fp);
    /*询问是否继续删除*/
    printf("\n是否继续?(是:y/Y;否:n/N)");
    next=getche();system("cls");
    putchar('\n');
    if ( next=='y'||next=='Y') goto begin;
}


void chuangjianchengyuan()   /*创建家庭成员信息文件*/
{
    FILE *fp=NULL;
    user Sh;
    user Tm;
    char Da[40]="yonghu",next;/*存储家庭成员信息的文件名*/
    int count=1;         /*计算可输入数据的最大范围*/
begin:
    fp=fopen(Da,"ab+");
    /*如果当前文件不存在,提示打开文件失败*/
    if (fp==NULL)
    {
        printf("\n 打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    /*如果成功打开文件,
    则提示输入序号、用户名、密码、权限等相关信息*/
    printf("请输入编号,姓名,密码。输入编号为0时结束。\n");
    printf("编号不超过九位,姓名不超过二十个字符,密码不超过8位。\n");
    /*循环从键盘上读取家长输入的家庭成员相关信息*/
    while(count<=SIZE)
   {
        printf("\n 输入编号为零时结束输入\n");
        printf("成员编号:");
        scanf("%ld",&Tm.Number);
        if (Tm.Number==0 )
            break;
        printf("成员姓名:");
        scanf("%s",Tm.Name);
        printf("成员密码:");
        scanf("%s",Tm.ps);
        printf("成员权限:");
        scanf("%d",&Tm.power);
        printf("\n");
        /*如遇无法写入文件的异常,则加以提示*/
        if(fwrite(&Tm,sizeof(user),1,fp)!=1)
        {
            printf("\n写入文件 %s 失败!按任意键结束!\n",Da);
            exit(0);
        }
        count++;
    }
    /*如果输入的数据量超过最大允许的范围,则提示数据不能录入*/
    if (count>SIZE)
        printf("\n对不起,数据量不能超过%d\n",SIZE);
    fclose(fp);
    system("cls");
    printf("您输入的数据已成功存储在 %s 文件中!\n",Da);
    /*询问是否继续删除*/
    printf("\n继续?(是:y/Y,否:n/N)");
    next=getche();system("cls");
    putchar('\n');
    if ( next=='y'||next=='Y') goto begin;
}
void shanchuyonghu()        /*删除用户信息*/
 {
    int i;
    long delnum;
    user Tm;
    user s[SIZE];
    int recNumber;
    char Da[40]="yonghu",next;
    FILE *fp;
begin:

    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    printf("请输入您要删除的用户的编号:");
    scanf("%ld",&delnum);
    printf("您要删除的用户的编号是:%ld\n",delnum);
   recNumber=0;
    while((fread(&Tm,sizeof(user),1,fp))!=(int)NULL)
    {
        if(Tm.Number!=delnum)
            {
            s[recNumber].Number=Tm.Number;
            strcpy(s[recNumber].Name, Tm.Name);
            strcpy(s[recNumber].ps,Tm.ps);
            s[recNumber].power=Tm.power;
            recNumber++;
            }
    }
    fclose(fp);
    /*将删除后的结构体数组记录写入文件=*/
        fp=fopen(Da,"wb+");
        if (fp==NULL)
        {
            printf("\n打开文件 %s失败!按任意键结束!\n",Da);
            exit(0);
        }
       for(i=0;i<recNumber;i++)
        {
            if(fwrite(&s[i],sizeof(user),1,fp)!=1)
            {
                printf("\n写入文件 %s 失败!按任意键结束!\n",Da);
                    exit(0);
            }
        }
        fclose(fp);
    printf("删除用户成功!\n");
    /*询问是否继续删除*/
    printf("\n继续?(是:y/Y,否:n/N)");
    next=getche();system("cls");
    putchar('\n');
    if ( next=='y'||next=='Y') goto begin;
 }
void xiugaishouzhi()     /*修改家庭成员收支信息记录*/
 {
    int i;
    long modnum;/*存储家长输入的要修改的家庭成员序号*/
    /*输入各项修改后信息*/
    long no,Number;
    char Name[20];
    float in;
    char intime[10];
    float out;
    char outtime[10];
    float sum;
    money Tm;      /*定义进行操作时的临时结构体变量*/
    money s[SIZE];   /*SIZE,在shead.h头文件中定义的常量,值为100  */
    int recNumber;
    char Da[40]="",next;
    /*Da存储家庭成员收支信息信息的文件名,next为是否进行下一次删除操作的选项*/
    FILE *fp;   /*fp指针指向存储数据的文件名*/
    /*提示家长输入要进行修改记录的文件名*/
    printf("\n请输入存储数据的文件名,按回车键结束!\n");
    gets(Da);
    /*提示家长输入要进行修改记录的文件名*/
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,按回车键结束!\n");
        gets(Da);
    }
begin:
    fp=fopen(Da,"rb");
    if(fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    printf("请输入您要修改的家庭成员的编号:");
    scanf("%ld",&modnum);
    printf("您要修改的编号是:%ld\n",modnum);
    while(fread(&Tm,sizeof(money),1,fp)!=(int)NULL)
    {
        if(Tm.Number==modnum)
        {
            printf("\n该项内容编号:%ld\n",Tm.no);
            printf("\n成员编号:%ld\n",Tm.Number);
            printf("\n成员姓名:%s\n",Tm.Name);
            printf("\n成员收入:%.2f元\n",Tm.in);
            printf("\n收入时间:%s\n",Tm.intime);
            printf("\n成员支出:%.2f元\n",Tm.out);
            printf("\n支出时间:%s\n",Tm.outtime);
            printf("############################\n");
        }
    }
    rewind(fp);
    printf("请选择您要修改的该项内容编号:\n");scanf("%ld",&no);
    /*输入要修改记录的各项内容值*/
    Number=modnum;
    printf("输入姓名,收入,收入时间,支出,支出时间,输入编号为0时结束!\n");
    printf("姓名不超过二十个字符。\n");
    printf("如果只需输入收入或支出其中一项,则另外一项收入或支出为零,时间与输入项相同。\n");
    printf("输入时间与输出时间应为同一个月。\n");
    printf("成员姓名:");
    scanf("%s",Name);
    printf("成员收入:");
    scanf("%f",&in);
    printf("收入时间:");
    scanf("%s",intime);   
    printf("成员支出:");
    scanf("%f",&out);   
    printf("支出时间:");
    scanf("%s",outtime);
    /*用公式自动计算家庭成员财务合计*/
    sum=in-out;
   /*将文件中要修改的信息存入结构体数组*/
   recNumber=0;
   /*循环将文件数据读入结构体数组,
   如文件中的数据家庭成员号和要修改的家庭成员号不符,则原样写入数组,
   如文件中数据的家庭成员号和要修改家庭成员号匹配,
   则根据家长输入的各项修改内容重新赋值,即修改,并写入数组*/
    while((fread(&Tm,sizeof(money),1,fp))!=(int)NULL)
    {
        if(Tm.no!=no)
            {
            s[recNumber].no=Tm.no;
            s[recNumber].Number=Tm.Number;
            strcpy(s[recNumber].Name, Tm.Name);
            s[recNumber].in=Tm.in;
            strcpy(s[recNumber].intime, Tm.intime);
            s[recNumber].out=Tm.out;
            strcpy(s[recNumber].outtime, Tm.outtime);
            s[recNumber].sum=Tm.sum;
            recNumber++;
            }
        else
            {
            s[recNumber].no=no;
            s[recNumber].Number=Number;
            strcpy(s[recNumber].Name,Name);
            s[recNumber].in=in;
            strcpy(s[recNumber].intime,intime);
            s[recNumber].out=out;
            strcpy(s[recNumber].outtime,outtime);
            s[recNumber].sum=sum;
            recNumber++;
            }
    }
    fclose(fp);
   /*将修改后的结构体数组记录写入文件*/
        fp=fopen(Da,"wb+");
        if (fp==NULL)
        {
            printf("\n打开文件%s失败!按任意键结束!\n",Da);
            exit(0);
        }
        for(i=0;i<recNumber;i++)
        {
            if(fwrite(&s[i],sizeof(money),1,fp)!=1)
            {
                printf("\n写入文件 %s 失败!按任意键结束!\n",Da);
                    exit(0);
            }
        }
        fclose(fp);
     /*显示修改后的文件*/
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件%s失败!按任意键结束!\n",Da);
        exit(0);
    }
    system("cls");
    printf("\n修改后的文件全部内容是:\n");
    while(fread(&Tm,sizeof(money),1,fp)!=(int)NULL)
    {
        printf("\n成员编号:%ld\n",Tm.Number);
        printf("成员姓名:%s\n",Tm.Name);
        printf("成员收入:%.2f元\n",Tm.in);
        printf("收入时间:%s\n",Tm.intime);
        printf("成员支出:%.2f元\n",Tm.out);
        printf("支出时间:%s\n",Tm.outtime);
        printf("############################\n");
    }
    fclose(fp);
/*提示是否进行下一次修改*/
    printf("\n继续?(是:y/Y,否:n/N)");
    next=getche();system("cls");
    putchar('\n');
    if (next=='y'||next=='Y') goto begin;
 }
void xiugaiyonghu()   /*按用户编号修改用户信息*/
 {
    int i;
    long modnum;
    /*输入各项修改后信息*/
    long Number;
    char Name[20];
    char ps[8];
    int power;
    user Tm;
    user s[SIZE];  
    int recNumber;
    char Da[40]="yonghu",next;
    FILE *fp;
begin:
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    printf("请输入您要修改成员信息的编号:");
    scanf("%ld",&modnum);
    printf("您要修改成员信息的编号是%ld\n",modnum);
    Number=modnum;
    printf("成员姓名:");
    scanf("%s",Name);
    printf("成员密码:");
    scanf("%s",ps);
    printf("成员权限:");
    scanf("%d",&power);
   /*将文件中要修改的信息存入结构体数组*/
   recNumber=0;
    while((fread(&Tm,sizeof(user),1,fp)) != (int)NULL)
    {
        if(Tm.Number!=modnum)
            {
            s[recNumber].Number=Tm.Number;
            strcpy(s[recNumber].Name, Tm.Name);
            strcpy(s[recNumber].ps,Tm.ps);
            s[recNumber].power=Tm.power;
            recNumber++;
            }
        else
            {
            s[recNumber].Number=Number;
            strcpy(s[recNumber].Name, Name);
            strcpy(s[recNumber].ps,ps);
            s[recNumber].power=power;
            recNumber++;
            }
    }
    fclose(fp);
    /*将删除后的结构体记录写入文件*/
        fp=fopen(Da,"wb+");
        if (fp==NULL)
        {
            printf("\n打开文件 %s失败!按任意键结束!\n",Da);
            exit(0);
        }
        for(i=0;i<recNumber;i++)
        {
            if(fwrite(&s[i],sizeof(user),1,fp)!=1)
            {
                printf("\n写入文件 %s 失败!按任意键结束!\n",Da);
                    exit(0);
            }
        }
        fclose(fp);
    printf("修改用户信息成功!\n");
    /*是否继续修改*/
    printf("\n继续?(是:y/Y,否:n/N)");
    next=getche();
    putchar('\n');system("cls");
    if(next=='y'||next=='Y') goto begin;
 }
void xingmingchaxun()    /*按姓名查询家庭成员财务收支信息记录*/
{
    int result;/* "result=1"说明查询成功,反之查找失败  */
    money Tm;   /*定义进行操作时的临时结构体变量*/
    char Xingming[20],before[20]; /*数组Xingming用于用户输入要查询的家庭成员姓名*/
    char   Da[40]="",next;
    /*Da存储家庭成员财务信息的文件名,next为是否进行下一次操作的选项*/
    FILE *fp=NULL;
    printf("\n 请输入存储数据的文件名,按回车键结束。\n");
    gets(Da);
    /*提示用户输入要查询的文件名*/
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,按回车键结束。\n");
        gets(Da);
    }
    /*提示用户输入要查询的家庭成员姓名*/
begin:
    result=0;system("cls");
    printf("请输入要查询的家庭成员姓名(姓名不超过二十位字符),按回车键结束。\n");
    scanf("%s",&Xingming);
    getchar();
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    /*循环查找和输入姓名相匹配的家庭成员财务收支信息记录,如果查找到,则输出结果*/
    while(feof(fp)==0)
    {
        if(fread(&Tm,sizeof(money),1,fp)!=(int)NULL)
        {
            if (strcmp(Tm.Name,Xingming)==0)
            {   
                if(strcmp(before,Tm.Name)!=0)
                {
                    system("cls");printf("\n查找成功!\n\n您要查找的家庭成员的信息如下:\n");
                }
                printf("\n成员编号:%ld\n",Tm.Number);
                printf("成员姓名:%s\n",Tm.Name);
                printf("成员收入:%.2f 元\n",Tm.in);
                printf("收入时间:%s\n",Tm.intime);
                printf("成员支出:%.2f 元\n",Tm.out);
                printf("支出时间:%s\n",Tm.outtime);
                printf("######################################\n");
                result=1;/*"result=1"说明找到了该家庭成员的对应信息.*/
                strcpy(before,Tm.Name);            
            }
        }
    }
    fclose(fp);
    if (result==0)
    {
        system("cls");
        printf("对不起!\n文件中没有该家庭成员所对应的信息。\n");
    }
    printf("\n继续?(是: y/Y,否:n/N)\n");
    next=getche();
    putchar('\n');system("cls");
    if(next=='y'||next=='Y') goto begin;
}
void bianhaochaxun()    /*按编号查询家庭成员财务收支信息记录*/
{
    int result;/* "result=1"说明查询成功,反之查找失败  */
    money Tm;   /*定义进行操作时的临时结构体变量*/
    long bianhao,before=0;
    char   Da[40]="",next;
    /*Da存储家庭成员财务信息的文件名,next为是否进行下一次操作的选项*/
    FILE *fp=NULL;
    /*提示用户输入要查询的文件名*/
    printf("\n 请输入存储数据的文件名,按回车键结束。\n");
    gets(Da);
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,按回车键结束。\n");
        gets(Da);
    }
    /*提示用户输入要查询的家庭成员姓名*/
begin:
    result=0;system("cls");
    printf("请输入要查询的家庭成员编号(姓名不超过二十位字符),按回车键结束。\n");
    scanf("%ld",&bianhao);
    getchar();
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
    /*循环查找和输入姓名相匹配的家庭成员财务收支信息记录,如果查找到,则输出结果*/
    while(feof(fp)==0)
    {
        if(fread(&Tm,sizeof(money),1,fp)!=(int)NULL)
        {
            if (Tm.Number==bianhao)
            {   
                if(before!=Tm.Number)
                {
                    system("cls");printf("\n查找成功!\n\n您要查找的家庭成员的信息如下:\n");
                }
                printf("\n成员编号:%ld\n",Tm.Number);
                printf("成员姓名:%s\n",Tm.Name);
                printf("成员收入:%.2f 元\n",Tm.in);
                printf("收入时间:%s\n",Tm.intime);
                printf("成员支出:%.2f 元\n",Tm.out);
                printf("支出时间:%s\n",Tm.outtime);
                printf("######################################\n");
                result=1;/*"result=1"说明找到了该家庭成员的对应信息.*/
                before=Tm.Number;            
            }
        }
    }
    fclose(fp);
    if (result==0)
    {
        system("cls");
        printf("对不起!\n文件中没有该家庭成员所对应的信息。\n");
    }
    printf("\n继续?(是: y/Y,否:n/N)\n");
    next=getche();
    putchar('\n');system("cls");
    if(next=='y'||next=='Y') goto begin;
}

void tongjicaiwu()    /*家庭成员财务统计情况*/
 {
    int i,j,c1=0,c2=0,c3=0,c4=0,tongxuan;
    int nian,yue,nian2,yue2,sign,y,t;
    money Tm;   /*定义进行操作时的临时结构体变量*/
    money s[SIZE];
    int recNumber=0,b1[10],b2[10],b3[10],b4[10];
    float insum=0,outsum=0;
    float ainsum=0,aoutsum=0,yinsum=0,youtsum=0;
    char Da[40]="",month[10],month2[10],x[10],x2[10],next;
    char xingming[20],year[10];
    FILE *fp;
    printf("\n请输入存储数据的文件名,按回车键结束。\n");
    gets(Da);
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,按回车键结束。\n");
        gets(Da);
    }
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
   /*将文件中的信息存入结构体数组*/
    while((fread(&Tm,sizeof(money),1,fp))!=(int)NULL)
    {
        s[recNumber].Number=Tm.Number;
        strcpy(s[recNumber].Name,Tm.Name);
        s[recNumber].in=Tm.in;
        strcpy(s[recNumber].intime,Tm.intime);
        s[recNumber].out=Tm.out;
        strcpy(s[recNumber].outtime,Tm.outtime);
        s[recNumber].sum=Tm.sum;
        recNumber++;
    }
    fclose(fp);
begin:
    system("cls");
    printf("##############################################################################\n");
    printf("\t\t\t\t统计家庭成员财务情况\n");
    printf("\t\t1.所有家庭成员每月的收支统计情况\n");
    printf("\t\t2.每个家庭成员每月收支统计情况和全年总收支统计情况\n");
    printf("##############################################################################\n");
    printf("请输入您的选择(选择1或2):\n");
    scanf("%d",&tongxuan);
if(tongxuan==1)
{
    insum=0;outsum=0;sign=0;
      printf("\n请输入您要浏览的所有家庭成员收支统计情况的月份\n(格式为:如二零一零年五月,输入为201005):");
      scanf("%s",month);
       strcat(month,"00");
   for(j=0;j<recNumber;j++)
   {
       if(strcmp(s[j].intime,"0")!=0)
       {
           strcpy(x,s[j].intime);
          for(i=0;i<8;i++)
          {
             b1[i]=x[i]-'0';b2[i]=month[i]-'0';
          }
         for(i=0;i<8;i++)
         {
           c1=c1+b1[7-i]*pow(10,i);c2=c2+b2[7-i]*pow(10,i);
         }
         yue=(c2/100)%100;nian=c2/10000;
        if((abs(c1-c2))<50)
        {
            insum=insum+s[j].in;sign=1;
        }        
       }
       c1=0;c2=0;
      if(strcmp(s[j].outtime,"0")!=0)
      {
            strcpy(x,s[j].outtime);
            for(i=0;i<8;i++)
            {
               b1[i]=x[i]-'0';b2[i]=month[i]-'0';
            }
          for(i=0;i<8;i++)
          {
             c1=c1+b1[7-i]*pow(10,i);c2=c2+b2[7-i]*pow(10,i);
          }
        
        if((abs(c1-c2))<50)
        {
            outsum=outsum+s[j].out;sign=1;
        }
        if(sign!=1&&j==recNumber-1)
            printf("\n输入错误!财务信息中没有该月份的记录。\n");
       c1=0;c2=0;
      }
   }
   if(sign==1)
   {
       system("cls");
       printf("######################################\n");
       printf("所有家庭成员财务统计情况:\n");
       printf("\n%d年%d月\n",nian,yue);
       printf("该月所有成员总收入:%.2f\n该月所有成员总支出:%.2f\n",insum,outsum);
       printf("######################################\n");
   }
}
if(tongxuan==2)
{
    yinsum=0;youtsum=0;ainsum=0;aoutsum=0;sign=0;y=0;t=0;
    printf("\n请输入您要浏览的财务统计情况的成员姓名:");
    scanf("%s",xingming);
    printf("\n请输入月份(格式为:如二零一零年五月,输入为201005):");
               scanf("%s",month2);strcat(month2,"00");strcpy(year,month2);
    for(i=0;i<recNumber;i++)
    {        
        if(strcmp(s[i].Name,xingming)==0)
        {   
            t=1;        
           for(j=0;j<8;j++)
               {
                   year[j]=month2[j]-'0';
               }
               for(j=0;j<8;j++)
               {
                  y=y+year[7-j]*pow(10,j);
               }
               y=y/10000;
           if(strcmp(s[i].intime,"0")!=0)
           {
               strcpy(x2,s[i].intime);
               for(j=0;j<8;j++)
               {
                   b3[j]=x2[j]-'0';b4[j]=month2[j]-'0';
               }
               for(j=0;j<8;j++)
               {
                  c3=c3+b3[7-j]*pow(10,j);c4=c4+b4[7-j]*pow(10,j);
               }
              yue2=(c4/100)%100;nian2=c4/10000;
              if((abs(c3-c4))<50)
              {
                  ainsum=ainsum+s[i].in;sign=1;
              }
           }
           c3=0;c4=0;
           if(strcmp(s[i].intime,"0")!=0)
           {
               strcpy(x2,s[i].intime);
               for(j=0;j<8;j++)
               {
                   b3[j]=x2[j]-'0';b4[j]=month2[j]-'0';
               }
               for(j=0;j<8;j++)
               {
                  c3=c3+b3[7-j]*pow(10,j);c4=c4+b4[7-j]*pow(10,j);
               }
              if((abs(c3-c4))<50)
              {
                  aoutsum=aoutsum+s[i].out;sign=1;
              }
           }
           if(y==nian2)
           {yinsum=yinsum+s[i].in;youtsum=youtsum+s[i].out;}
           
           c3=0;c4=0;
        }
        if(sign!=1&&i==recNumber-1)
            printf("\n输入错误!财务信息中没有该月份的记录。\n");
         if(t!=1&&i==recNumber-1)  printf("\n用户名输入错误!财务信息中没有该用户。\n");
    }
    if(sign==1)
    {
        system("cls");
        printf("#########################################\n");
        printf("家庭成员%s的月财务统计情况:\n",xingming);
        printf("\n%d年%d月\n",nian2,yue2);
        printf("该月总收入:%.2f\n该月总支出:%.2f\n",ainsum,aoutsum);
        printf("#########################################\n");
        printf("\n家庭成员%s在%d年的总统计情况:\n",xingming,nian2);
        printf("年总收入:%.2f\n年总支出:%.2f\n",yinsum,youtsum);
        printf("#########################################\n");
    }
}
    printf("\n继续?(是: y/Y,否:n/N)\n");
     next=getche();
     putchar('\n');system("cls");
     if(next=='y'||next=='Y') goto begin;
}
2012-07-06 16:52
月夜忆辰
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-12-5
得分:0 
void paihangbang()    /*家庭成员收支排行榜浏览*/
 {  
    money Tm;   /*定义进行操作时的临时结构体变量*/
    money s[SIZE],yueshuju[SIZE];
    char Da[40]="",next; /*Da存储财务收支信息的文件名*/
    int recNumber=0,i,k,j,sign=0,n=0,xmonth;
    int month4[10],yue,yue2,sign2,sign3;
    float in;
    char month[10],month2[10],month3[10];
    FILE *fp;
    printf("\n请输入存储数据的文件名,按回车键结束。\n");
    gets(Da);
    while(*Da==('\0'))
    {
        printf("\n请输入存储数据的文件名,按回车键结束。\n");
        gets(Da);
    }
    fp=fopen(Da,"rb");
    if (fp==NULL)
    {
        printf("\n打开文件 %s 失败!按任意键结束!\n",Da);
        exit(0);
    }
   /*将文件中的信息存入结构体数组*/
    while((fread(&Tm,sizeof(money),1,fp))!=(int)NULL)
    {
        s[recNumber].Number=Tm.Number;
        strcpy(s[recNumber].Name,Tm.Name);
        s[recNumber].in=Tm.in;
        strcpy(s[recNumber].intime,Tm.intime);
        s[recNumber].out=Tm.out;
        strcpy(s[recNumber].outtime,Tm.outtime);
        s[recNumber].sum=Tm.sum;
        recNumber++;
    }
    fclose(fp);
begin:
    yue=0;yue2=0;n=0;sign=0;sign2=0;sign3=0;
    system("cls");
        printf("##############################################################################\n");
        printf("\t\t家庭成员收支排行榜浏览\n");
        printf("\t\t1.所有家庭成员每月的收入排行\n");
        printf("\t\t2.所有家庭成员每月的支出排行\n");
        printf("##############################################################################\n");
       printf("请输入您的选择(选择1或2):\n");
       scanf("%d",&xmonth);
     printf("\n请输入您要浏览的家庭成员收支排行榜的月份\n(格式为:如二零一零年五月,输入为201005):");
     scanf("%s",month);strcat(month,"00");
        for(i=0;i<8;i++)
          {
             month2[i]=month[i]-'0';
          }
        for(i=0;i<8;i++)
         {
           yue=yue+month2[7-i]*pow(10,i);
         }
        
if(xmonth==1)
{
      for(j=0;j<recNumber;j++)
      {        
                 strcpy(month3,s[j].intime);
                   yue2=0;
                 for(i=0;i<8;i++)
                 {
                    month4[i]=month3[i]-'0';
                 }
                 for(i=0;i<8;i++)
                 {
                     yue2=yue2+month4[7-i]*pow(10,i);
                 }
                if((abs(yue-yue2)<50))
                 {   
                    for(k=0;k<=n;k++)
                    {
                           if(sign3!=1)
                           {
                                yueshuju[k].Number=s[j].Number;
                                strcpy(yueshuju[k].Name,s[j].Name);
                                yueshuju[k].in=s[j].in;
                                yueshuju[k].out=s[j].out;
                                yueshuju[k].sum=s[j].sum;
                                sign3=1;break;
                           }
                            if(strcmp(yueshuju[k].Name,s[j].Name)==0)
                            {
                                yueshuju[k].in=yueshuju[k].in+s[j].in;
                                yueshuju[k].out=yueshuju[k].out+s[j].out;
                                yueshuju[k].sum=yueshuju[k].sum+s[j].sum;
                                sign=1;break;
                            }
                            else
                            {
                                  if(k==n&&sign!=1)
                                  {
                                      yueshuju[k+1].Number=s[j].Number;
                                      strcpy(yueshuju[k+1].Name,s[j].Name);
                                      yueshuju[k+1].in=s[j].in;
                                      yueshuju[k+1].out=s[j].out;
                                      yueshuju[k+1].sum=s[j].sum;
                                      n=k+1;break;
                                  }
                            }               
                    }   
                    sign2=1;
                 }
                else
                {
                    if(j==recNumber-1&&sign2!=1)
                    {printf("\n输入错误!财务信息没有该月份的记录。\n");sign2=0;}
                }
        sign=0;
      }
     
      /*用选择排序法进行按收入的排序*/
      if(sign2==1)
      {
          for(i=0;i<n;i++)
          {
            k=i;
            for(j=i+1;j<=n;j++)
            {
                if(yueshuju[k].in<yueshuju[j].in) k=j;
            }
            Tm.Number=yueshuju[k].Number;
            strcpy(Tm.Name,yueshuju[k].Name);
            Tm.in=yueshuju[k].in;
            Tm.out=yueshuju[k].out;
            Tm.sum=yueshuju[k].sum;
            yueshuju[k].Number=yueshuju[i].Number;
            strcpy(yueshuju[k].Name,yueshuju[i].Name);
            yueshuju[k].in=yueshuju[i].in;
            yueshuju[k].out=yueshuju[i].out;
            yueshuju[k].sum=yueshuju[i].sum;
            yueshuju[i].Number=Tm.Number;
            strcpy(yueshuju[i].Name,Tm.Name);
            yueshuju[i].in=Tm.in;
            yueshuju[i].out=Tm.out;
            yueshuju[i].sum=Tm.sum;
        }
          system("cls");
      printf("\n###########################################");
      printf("\n#####%d年%d月份所有家庭成员收入排行榜#####\n",yue/10000,(yue/100)%100);
      printf("###########################################\n");
      for(i=0;i<=n;i++)
      {
          printf("\n收入第%d名\n",i+1);
          printf("成员编号:%ld\n",yueshuju[i].Number);
          printf("成员姓名:%s\n",yueshuju[i].Name);
          printf("月总收入:%.2f元\n",yueshuju[i].in);
          printf("月总支出:%.2f元\n",yueshuju[i].out);
          printf("月总计:%.2f元\n",yueshuju[i].sum);
          printf("###########################################");
          yueshuju[i].in=0;yueshuju[i].out=0;yueshuju[i].sum=0;
      }
  }
    printf("\n继续?(是: y/Y,否:n/N)\n");
     next=getche();
     putchar('\n');system("cls");
     if(next=='y'||next=='Y') goto begin;
}
 if(xmonth==2)
 {
    for(j=0;j<recNumber;j++)
      {        
                 strcpy(month3,s[j].intime);
                   yue2=0;
                 for(i=0;i<8;i++)
                 {
                    month4[i]=month3[i]-'0';
                 }
                 for(i=0;i<8;i++)
                 {
                     yue2=yue2+month4[7-i]*pow(10,i);
                 }
                if((abs(yue-yue2)<50))
                 {   
                    for(k=0;k<=n;k++)
                    {
                           if(sign3!=1)
                           {
                                yueshuju[k].Number=s[j].Number;
                                strcpy(yueshuju[k].Name,s[j].Name);
                                yueshuju[k].in=s[j].in;
                                yueshuju[k].out=s[j].out;
                                yueshuju[k].sum=s[j].sum;
                                sign3=1;break;
                           }
                            if(strcmp(yueshuju[k].Name,s[j].Name)==0)
                            {
                                yueshuju[k].in=yueshuju[k].in+s[j].in;
                                yueshuju[k].out=yueshuju[k].out+s[j].out;
                                yueshuju[k].sum=yueshuju[k].sum+s[j].sum;
                                sign=1;break;
                            }
                            else
                            {
                                  if(k==n&&sign!=1)
                                  {
                                      yueshuju[k+1].Number=s[j].Number;
                                      strcpy(yueshuju[k+1].Name,s[j].Name);
                                      yueshuju[k+1].in=s[j].in;
                                      yueshuju[k+1].out=s[j].out;
                                      yueshuju[k+1].sum=s[j].sum;
                                      n=k+1;break;
                                  }
                            }               
                    }   
                    sign2=1;
                 }
                else
                {
                    if(j==recNumber-1&&sign2!=1)
                    {printf("\n输入错误!财务信息没有该月份的记录。\n");sign2=0;}
                }
        sign=0;
      }
     
      /*用选择排序法进行按支出的排序*/
      if(sign2==1)
      {
          for(i=0;i<n;i++)
          {
            k=i;
            for(j=i+1;j<=n;j++)
            {
                if(yueshuju[k].out<yueshuju[j].out) k=j;
            }
            Tm.Number=yueshuju[k].Number;
            strcpy(Tm.Name,yueshuju[k].Name);
            Tm.in=yueshuju[k].in;
            Tm.out=yueshuju[k].out;
            Tm.sum=yueshuju[k].sum;


            yueshuju[k].Number=yueshuju[i].Number;
            strcpy(yueshuju[k].Name,yueshuju[i].Name);
            yueshuju[k].in=yueshuju[i].in;
            yueshuju[k].out=yueshuju[i].out;
            yueshuju[k].sum=yueshuju[i].sum;

            yueshuju[i].Number=Tm.Number;
            strcpy(yueshuju[i].Name,Tm.Name);
            yueshuju[i].in=Tm.in;
            yueshuju[i].out=Tm.out;
            yueshuju[i].sum=Tm.sum;
          }
          system("cls");
      printf("\n###########################################");
      printf("\n#####%d年%d月份所有家庭成员支出排行榜#####\n",yue/10000,(yue/100)%100);
      printf("###########################################\n");
      for(i=0;i<=n;i++)
      {
          printf("\n支出第%d名\n",i+1);
          printf("成员编号:%ld\n",yueshuju[i].Number);
          printf("成员姓名:%s\n",yueshuju[i].Name);
          printf("月总收入:%.2f元\n",yueshuju[i].in);
          printf("月总支出:%.2f元\n",yueshuju[i].out);
          printf("月总计:%.2f元\n",yueshuju[i].sum);
          printf("###########################################");
          yueshuju[i].in=0;yueshuju[i].out=0;yueshuju[i].sum=0;
      }
  }
    printf("\n继续?(是: y/Y,否:n/N)\n");
     next=getche();
     putchar('\n');system("cls");
     if(next=='y'||next=='Y') goto begin;
 }
}
void putongchengyuan()/*普通成员登陆界面*/
{
    int choice=0;/*存放用户输入的功能选项代码*/
    while(1)
    {
        system("cls");
        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("###         0. 返回登录界面                                  ###\n");
        printf("###                                                          ###\n");
        printf("################################################################\n");
        printf("###            请输入您的选择                  (1,2,3,4,0)   ###\n");
        printf("################################################################\n");
        printf("请输入您的选择(以回车键结束):");
        scanf("%d",&choice);
        getchar();
        switch(choice)
        {
            case 1:system("cls");xingmingchaxun();break;/*按家庭成员姓名查询财务信息*/                       
            case 2:system("cls");bianhaochaxun();break;/*按家庭成员编号查询财务信息*/
            case 3:system("cls");tongjicaiwu();break;/*家庭成员财务统计情况*/               
            case 4:system("cls");paihangbang();break;/*家庭成员收支排行榜浏览*/  
            case 0:system("cls");goto end;/*返回登录界面*/
            default:break;
        }
    }
end:;
}
void jiazhangjiemian()/*家长登陆界面*/
{
    int choice=0; /*存放用户选项的变量*/
    while(1)
    {
        system("cls");
        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("###            6. 家庭成员财务统计情况                       ###\n");      
        printf("###            7. 家庭成员收支排行榜浏览                     ###\n");
        printf("###            8. 创建或增加家庭成员信息                     ###\n");
        printf("###            9. 删除家庭成员信息                           ###\n");
        printf("###            10. 修改家庭成员信息                          ###\n");
        printf("################################################################\n");
        printf("###            0. 返回登录界面                               ###\n");
        printf("################################################################\n");
        printf("###      请输入您的选择(1,2,3,4,5,6,7,8,9,10,0)              ###\n");
        printf("################################################################\n");
        printf("请输入您的选择(以回车键结束):");
        scanf("%d",&choice);
        getchar();
       /*根据用户选项调用相应函数*/
        switch(choice)
        {            
            case 1:system("cls");tianjiashouzhi();break;/*增加财务信息记录*/
            case 2:system("cls");xiugaishouzhi();break;/*按家庭成员编号修改财务信息*/              
            case 3:system("cls");shanchucaiwu();break;/*删除家庭成员财务信息*/               
            case 4:system("cls");xingmingchaxun();break;/*按家庭成员姓名查询财务信息*/               
            case 5:system("cls");bianhaochaxun();break;/*按家庭成员编号查询财务信息*/  
            case 6:system("cls");tongjicaiwu();break;/*家庭成员财务统计情况*/            
            case 7:system("cls");paihangbang();break;/*家庭成员收支排行榜浏览*/                              
            case 8:system("cls");chuangjianchengyuan();break;/*创建初始家庭成员信息文件*/                           
            case 9:system("cls");shanchuyonghu();break;/*删除家庭成员*/                                
            case 10:system("cls");xiugaiyonghu();break;/*按家庭成员姓名修改家庭成员*/                                               
            case 0:system("cls");goto end;/*返回登录界面*/              
            default:break;               
        }
    }
end:;
}
int denglu(int a)/*用户登录*/
{

    FILE *fp=NULL;
    user Sh;
    user Tm;                   /*临时存放家庭成员信息的结构体变量*/
    /*char Da[40]="yonghu";存放家庭成员信息的文件名为yonghu*/
  int i,d,success=0;
  int denglu;            
begin:
   printf("#############################################################################\n");
   printf("####                     欢迎来到家庭财务管理系统!                       ####\n");
   printf("#############################################################################\n");
   printf("#############################################################################\n");
   printf("####                          欢迎进入登录界面                           ####\n");
   printf("####                          请选择操作内容:                            ####\n");
   printf("####               0: 退出                        1: 登录                ####\n");        
   printf("####                          请选择( 0 或 1 )                         ####\n");
   printf("#############################################################################\n");
   printf("请输入您的选择(以回车键结束):");
   scanf("%d",&d);
        switch(d)
        {
            case 1:denglu=1;break;                       
            case 0:denglu=0;exit(0);break;/*退出系统*/
            default:break;
        }
    if(denglu==1)
    {
        /*输入用户名*/
      printf("请输入用户名:");
      scanf("%s",Tm.Name);
      printf("用户密码(6个字符):");
       for(i=0;i<6;i++)
        {
          Tm.ps[i]=getch();
          printf("*");      
        }

     Tm.ps[i]='\0';
     /*打开yonghu文件,用来验证用户名和密码*/
     fp=fopen("yonghu","rb");
     if(fp==NULL)
     {
        printf("\n打开文件yonghu失败!按任意键结束 \n");
        exit(0);
     }
       /*循环读取文件校验用户名和密码是否正确*/
        while(fread(&Sh,sizeof(user),1,fp)!=(int)NULL)
        {
           if((strcmp(Tm.Name,Sh.Name)==0)&&(strcmp(Tm.ps,Sh.ps)==0))
           {
               success=1;break;
           }
           else success=0;
        
        }
        if(success==1)
           {
              if(Sh.power==1) return a=11;
              else return a=10;
           }
        else if(success==0)
            return a=0;
        fclose(fp);
    }
    else if(d!=0&&d!=1)
    {
        system("cls");
        printf("\n输入错误,请重新输入!\n");
        goto begin;
    }
}
main()
{
    int d,t=0;
    char relogin,next;
    chuangjianchengyuan();
begin:
    system("cls");
    while(1)
    {   
        d=denglu(t);
        if(d==11)
            jiazhangjiemian();
        else if(d==10)
            putongchengyuan();
        else
        {
            printf("\n用户名或密码错误!是否重新输入?((是:y/Y;否:n/N))");
            next=getche();
           putchar('\n');
           if(next=='y'||next=='Y') goto begin;
            else
                break;
        }
    }
}


[ 本帖最后由 月夜忆辰 于 2012-7-6 16:57 编辑 ]
2012-07-06 16:52
月夜忆辰
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-12-5
得分:0 
这个是总的程序,但是有些功能 无法使用
2012-07-06 16:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-372873-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.556486 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved