⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gexfglxt1.cpp

📁 暑假做的个人消费管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct scorenode)
#define DEBUG
#include <string.h>
struct scorenode
{int number;
char name[10];
float living;
float study;
float other;
struct scorenode *next;
};
typedef struct scorenode score;
int n,k;

score *creat2311(void)

{
 score*head;
 score *p1,*p2,*p3,*max;
 int i,j;
 float fen;
    char t[10];
  n=0;
     p1=p2=p3=(score *)malloc(LEN);head=p3; 
       printf("please input the school number!\n");
repeat1: printf("    please input the school number(should up to zero):");
       scanf("%d",&p1->number);
     while(p1->number<0)
   {getchar();
    printf("    wrong input please input again:");
       scanf("%d",&p1->number);}       

  if(p1->number==0)
   goto end;
  else 
  { 
  p3=head;
  if(n>0)
   {for(i=0;i<n;i++)
           {if(p1->number!=p3->number)
     p3=p3->next;
     else 
     {printf("    school number has existed!\n");
     goto repeat1;
     
        }
    }     
   }          
  }
       printf("    please input your name:");
       scanf("%s",&p1->name);
       printf("    input your living fee(should up to zero):");
       scanf("%f",&p1->living);
    while(p1->living<0)
 {getchar();
  printf("    wrong input please input again");
            scanf("%f",&p1->living);}
       printf("    please input the studying fee(should up to zero):");
       scanf("%f",&p1->study);
    while(p1->study<0)
 {getchar();
  printf("    wrong input please input the studing consuming");
           scanf("%f",&p1->study);}
       printf("    input the other fee up to zero:");
       scanf("%f",&p1->other);
    while(p1->other<0)
 {getchar();
  printf("    wrong input input again");
            scanf("%f",&p1->other);}
     head=NULL;
 while(p1->number!=0)
  {
    n=n+1;
 if(n==1)  
  head=p1;
 else
 
    p2->next=p1;
    p2=p1;
    p1=(score *)malloc(LEN);
    printf("    input your data!\n");
repeat2:printf("    input your credit number(should up to zero):");
      scanf("%d",&p1->number);
   
   while(p1->number<0)
   {getchar();
    printf("    wrong number please input again:");
       scanf("%d",&p1->number);}      
  
  if(p1->number==0)
   goto end;
  else
  {
  p3=head;
  if(n>0)
   {for(i=0;i<n;i++)
      {if(p1->number!=p3->number)
    p3=p3->next;
    else 
    {printf("    number has exist repeat again!\n");
     goto repeat2;
    
    }
    }     
   }          
 
  }
  printf("    input your name here:");
       scanf("%s",&p1->name);
     printf("    please input your life consumption(大于0):");
       scanf("%f",&p1->living);
     while(p1->living<0)
  {getchar();
   printf("    wrong input please input again");
         scanf("%f",&p1->living);}
     printf("    please input the studing fee(up to zero):");
      scanf("%f",&p1->study);
     while(p1->study<0)
  {getchar();
   printf("    wrong input please input again");
         scanf("%f",&p1->study);}
      printf("    please input other fee(up to zero):");
       scanf("%f",&p1->other);
     while(p1->other<0)
  {getchar();
   printf("    wrong input please input again");
         scanf("%f",&p1->other);}
     
 }

end: p1=head;
     p3=p1;
  for(i=1;i<n;i++)
               {
             for(j=i+1;j<=n;j++)
                 {
       max=p1;
       p1=p1->next;
      
       if(max->number>p1->number)
        {
        k=max->number;
        max->number=p1->number;
        p1->number=k;
         
        
        strcpy(t,max->name);
        strcpy(max->name,p1->name);
        strcpy(p1->name,t);
     
        fen=max->living;
        max->living=p1->living;
        p1->living=fen;
                 
      
        fen=max->study;
        max->study=p1->study;
        p1->study=fen;
    
       
        fen=max->other;
        max->other=p1->other;
        p1->other=fen;
                
        }

                 }
    max=head;p1=head;
  } 
p2->next=NULL;
       printf("    the number of the person is:%d个!\n",n);
       return(head);

}
  


score *load2311(score *head)

{       score *p1,*p2;
        int m=0;
        char filepn[10];
  FILE *fp;
  
  printf("    please input the name and the course of the file:");
     scanf("%s",filepn);
     if((fp=fopen(filepn,"r+"))==NULL)
 {
  printf("    can not open the file!\n");
  return 0;
 }
     fscanf(fp,"\t\t\t\tpersonal consuming system\n");
     fscanf(fp,"        作者: 潘浩亮 学号:0716000227  班级 :2  专业:计算机科学与技术  \n");
        fscanf(fp,"-----------------------------------------\n");
       
  fscanf(fp,"|number\t|name\t|life fee\t|studing fee\t|other fee\t|\n");
        fscanf(fp,"-----------------------------------------\n");
printf("\t\t\t\tpersonal consuming system\n");
 printf("      作者: 潘浩亮 学号:0716000227  班级 :2  专业:计算机科学与技术  \n");
        printf("    -----------------------------------------\n");
  printf("    |number\t|name\t|life fee\t|studing fee\t|other fee\t|\n");
        printf("    -----------------------------------------\n");
  m=m+1;  
  if(m==1)
  {
  
  p1=(score *)malloc(LEN); 
  fscanf(fp,"%d%s%f%f%f",&p1->number,p1->name,&p1->living,&p1->study,&p1->other);
         printf("    |%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p1->number,p1->name,p1->living,p1->study,p1->other);
    
  head=NULL;
     do
  {
   n=n+1;
   if(n==1) head=p1;
   else p2->next=p1;
   p2=p1;
   p1=(score *)malloc(LEN);      
      fscanf(fp,"%d%s%f%f%f\n",&p1->number,p1->name,&p1->living,&p1->study,&p1->other);
            printf("    |%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p1->number,p1->name,p1->living,p1->study,p1->other);
           
  }while(!feof(fp));
  p2->next=p1;
  p1->next=NULL;
  n=n+1; 
 }printf("    -----------------------------------------\n");
  fclose(fp);
      
 return (head);
}

   


score *add2311(score *head,score *stu)

{
 score *p0,*p1,*p2,*p3,*max;
    int i,j;
 float fen;
    char t[10];

   p3=stu=(score *)malloc(LEN);\
   printf("    \n    please inpt the data of the person!");
  repeat4: printf("    please input his number(should up to zero):");
  scanf("%d",&stu->number); 
 
      while(stu->number<0)
   {getchar();
    printf("    wrong input please input again:");
       scanf("%d",&stu->number);}
     /******************************************************/
    if(stu->number==0)
   goto end2;
  else 
  { 
   p3=head;
  if(n>0)
   {for(i=0;i<n;i++)
           {if(stu->number!=p3->number)
     p3=p3->next;
     else 
     {printf("    number has existed please input again!\n");
     goto repeat4;
     
        }
    }     
   }          

  }
   
  /******************************************************/  
  printf("    please input the name:");
       scanf("%s",&stu->name);
     printf("    please input the life fee(should up to zero):");
       scanf("%f",&stu->living);
     while(stu->living<0)
  {getchar();
   printf("   wrong input please input again");
         scanf("%f",&stu->living);}
     printf("    please input the studying again(should up to zero):");
      scanf("%f",&stu->study);
     while(stu->study<0)
  {getchar();
   printf("    wrong input please input again");
         scanf("%f",&stu->study);}
      printf("    please input other fee(should up to zero):");
       scanf("%f",&stu->other);
     while(stu->other<0)
  {getchar();
   printf("    wrong input please input again");
         scanf("%f",&stu->other);}
p1=head;
p0=stu;
if(head==NULL)
 {head=p0;p0->next=NULL;}
 else
 {
  if(p1->next==NULL)
  {
   p1->next=p0;
      p0->next=NULL;
  }
     else
  {
    while(p1->next!=NULL)
    {
     p2=p1;p1=p1->next;
    }
        p1->next=p0;
        p0->next=NULL;
  }

 }
 n=n+1;


p1=head;
p0=stu;
  for(i=1;i<n;i++)
               {
             for(j=i+1;j<=n;j++)
                 {
       max=p1;
       p1=p1->next;
      
       if(max->number>p1->number)
        {
        k=max->number;
        max->number=p1->number;
        p1->number=k;
        
        
        strcpy(t,max->name);
        strcpy(max->name,p1->name);
        strcpy(p1->name,t);
     
        fen=max->living;
        max->living=p1->living;
        p1->living=fen;
             
      
        fen=max->study;
        max->study=p1->study;
        p1->study=fen;
  
       
        fen=max->other;
        max->other=p1->other;
        p1->other=fen;
              
        }

                 }
    max=head;p1=head;
  } end2:
 printf("    now the number of person is:%d个!\n",n);
  return(head);

}
 


score *search2311(score *head)

{int number;
 score *p1,*p2;
 printf("    please input the number of the person you want,");
 scanf("%d",&number);

while(number!=0)
{
   if(head==NULL)
  {printf(" \n    no any data!\n");return(head);}

   printf("    -----------------------------------------\n");
   printf("    |number\t|name\t|life fee\t|studing fee\t|other fee\t|\n");
   printf("    -----------------------------------------\n");
   p1=head;
     while(number!=p1->number&&p1->next!=NULL)

  {p2=p1;p1=p1->next;} 
         if(number==p1->number)  
    {printf("    |%d\t|%s\t|%.1f\t|%.1f\t|%.1f\t|\n",p1->number,p1->name,p1->living,p1->study,p1->other);
          printf("    -----------------------------------------\n");}
         else 
           printf("    %d no this person!\n",number);
  
         printf("    input number of the person you want,");
         scanf("%d",&number);
}
printf("    has quited!\n");
return(head);}




score *del2311(score *head)
{
 score *p1,*p2;
int number;
 printf("    input the number of the person you want to delete(zero is quitted):");
 scanf("%d",&number);
 getchar();
 while(number!=0)
 {
 
  if(head==NULL)
  {
   printf("    \n    no data!\n");
   return(head);
  }

  
  p1=head;
  
  while(number!=p1->number&&p1->next!=NULL)
   
  {
   p2=p1;p1=p1->next;
  } 
     
  if(number==p1->number)  
  
  {
   if(p1==head)
    head=p1->next;
  
   else 
      p2->next=p1->next;
  
   printf("    delete:%d\n",number);n=n-1;
  }
  else
   printf("    %dno such person!\n",number);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -