编写语言:c++ 

截图展示:

 

代码如下:

main.cpp

 

  1 #include <iostream>
  2 #include <cstdio>
  3 #include<stdlib.h>
  4 #include <cstring>
  5 #include <windows.h>
  6 #include "see3.cpp"
  7 #include "see4.cpp"
  8 #include "jie gou.cpp"
  9 #include "pai.cpp"
 10 #include "see.cpp"
 11 #include "add.cpp"
 12 #include "cret.cpp"
 13 #include "find.cpp"
 14 #include "gai.cpp"
 15 #include "now.cpp"
 16 #include "see2.cpp"
 17 #include "delet.cpp"
 18 #include "copy.cpp"
 19 using namespace std;
 20 int main()
 21 {  system("color 0D");
 22     int n,a;
 23     see();
 24     FILE *fp;
 25     char f[80]="student";
 26     char fc[80];
 27     fp=fopen(f,"r");
 28     if(fp==0)
 29     {fp=fopen(f,"w");
 30     if(fp==0)
 31     {cout<<"创建默认文件夹 student 失败了。。。。"<<endl;
 32     return 0;}}
 33     fclose(fp);
 34     while(1)
 35     {
 36         cin>>n;
 37         getchar();
 38         if(n>=1&&n<=10)
 39         {
 40 
 41             if(n==1)
 42             { system("cls");
 43                add(f);
 44                cout<<endl;
 45                cout<<"存储完毕,都放在";printf(" %s 这里了%cn",f,3);
 46                cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
 47                getchar();
 48                system("cls");
 49                see2();
 50                continue;
 51             }
 52             if(n==2)
 53             {   system("cls");
 54                 gai(f);
 55                 getchar();
 56                 cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
 57                 getchar();
 58                  system("cls");
 59                  see2();
 60                 continue;
 61             }
 62             if(n==3)
 63             { system("cls");
 64               cout<<"正在努力加载~";
 65               cout<<endl;
 66                  int flag=0;
 67                   flag=now(f);
 68                   if(!flag)
 69                   printf("这就是目前全部的学生成绩哦!n");
 70                cout<<endl;
 71                cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
 72                getchar();
 73                 system("cls");
 74                 see2();
 75               continue;
 76             }
 77             if(n==4)
 78             { system("cls");
 79                find(f);
 80                getchar();
 81               cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
 82               getchar();
 83                system("cls");
 84                see2();
 85               continue;
 86             }
 87             if(n==5)
 88             {   system("cls");
 89                 cout<<endl<<endl;
 90                 cout<<"--------亲,是要把里面的信息全部删除吗??---------"<<endl;
 91                 cout<<"是点1,否则戳2"<<endl;
 92                 int a;
 93                 cin>>a;
 94                 while(a!=1&&a!=2)
 95                 {
 96                     cout<<"你的选项与我相隔甚远,重新输入吧"<<endl;
 97                     cin>>a;
 98                 }
 99                 if(a==1)
100                 {fp=fopen(f,"w");
101                 fclose(fp);
102                 cout<<"已经全部删除了";printf("%cn",1);}
103                 else
104                 delet(f);
105                 getchar();
106                 cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
107                 getchar();
108                  system("cls");
109                  see2();
110                continue;
111             }
112             if(n==6)
113             {   system("cls");
114                 pai(f);
115                 cout<<"已经排好序了哦,不信看下边了"<<endl<<endl;
116                 now(f);
117                 getchar();
118                cout<<"按任意键就可以进行下一个操作了";printf("%cn",2);
119                getchar();
120                system("cls");
121                see2();
122                continue;
123 
124             }
125             if(n==7)
126             {  system("cls");
127                 cout<<"将要保存信息文件的地址为 ";printf("%s n",f);
128                 cout<<"就是这个地址按1    我要换一个地址按2"<<endl;
129                 cin>>a;
130                 getchar();
131                 if(a==1)
132                 {
133                 }
134                  else
135                  {
136                      if(a==2)
137                      {
138                          cout<<"那么,输入你要存的地址吧,格式仿照这个哦 d:/student "<<endl;
139                          scanf("%s",f);
140                      }
141                      else
142                      {
143                        cout<<"输入错误,让你回到最初的操作~~"<<endl<<endl;
144                        see2();
145                        cout<<"重新选择您要进行的操作吧";printf("%cn",2);
146                        continue;
147                      }
148                  }
149                  add(f);
150                  cout<<"存储完毕,都放在";printf(" %s 这里了%cn",f,3);
151                  getchar();
152                  cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
153                  getchar();
154                  system("cls");
155                  see2();
156                  continue;
157             }
158             if(n==8)
159             {   system("cls");
160                 cout<<"将要读取信息的文件地址为 ";printf("%s n",f);
161                 cout<<endl;
162                 cout<<"就是这个地址按1    我要换一个地址按2"<<endl;
163                 cout<<endl;
164                 cin>>a;
165                 if(a==1)
166                 {
167 
168                 }
169                 else
170                 {
171                     if(a==2)
172                  {
173                     cout<<"那么,输入你要读取的地址吧,格式仿照这个哦 d:/student "<<endl;
174                      scanf("%s",f);
175                  }
176                  else
177                  {
178                  cout<<"输入错误,让你回到最初的操作~~"<<endl<<endl;
179                  see2();
180                  cout<<endl;
181                  cout<<"重新选择您要进行的操作吧";printf("%cn",2);
182                  continue;
183                     }
184                  }
185                  cout<<"正在努力加载~";
186                  cout<<endl<<endl;
187                  int flag=0;
188                  flag=now(f);
189                  if(!flag)
190                  printf("这就是目前全部的学生成绩哦!n");
191                  getchar();
192                  cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
193                  getchar();
194                   system("cls");
195                   see2();
196                  continue;
197             }
198             if(n==9)
199             {  system("cls");
200                cout<<"将要从目前文件中拷贝学生信息"<<endl;
201                cout<<"请输入要拷贝到的地址 ,格式仿照这个哦 d:/student "<<endl;
202                scanf("%s",fc);
203                 getchar();
204                 copy(f,fc);
205                 cout<<"按回车键就可以进行下一个操作了";printf("%cn",2);
206                  getchar();
207                   system("cls");
208                   see2();
209 
210                  continue;
211 
212 
213             }
214             if(n==10)
215             {   system("cls");
216                 cout<<endl<<endl;
217                 cout<<"----您的数据已保护的妥妥的,请放心88-----"<<endl;
218                                 break;
219             }
220         }
221         else
222         {   system("cls");
223             cout<<"你的选项与我相隔甚远,重新输入吧"<<endl;
224         continue;}
225     }
226     return 1;
227 }

 

 

 

 

 

add.cpp

 1 using namespace std;
 2 void add(char f[])
 3 { int flag;
 4    double c;
 5    char a,s[40];
 6    FILE *fp;
 7    fp=fopen(f,"a");
 8    if(fp==0)
 9    {
10        cout<<endl<<"没找到文件 "<<f<<"... "<<endl;
11        return ;
12    }
13 while(1)
14 {   fputc(' ',fp);
15     cout<<"输入名字吧:"<<endl;
16     gets(s);
17     fputs(s,fp);
18     fputc(' ',fp);
19     cout<<"然后是他/她的学号"<<endl;
20     gets(s);
21     fputs(s,fp);
22     fputc(' ',fp);
23     cout<<"boy请按y,girl请按x"<<endl;
24     a=getchar();
25     while(a!='x'&&a!='y')
26     {cout<<"亲,你输的啥性别。。。"<<endl;
27     cout<<"重新输入吧:"<<endl;
28     a=getchar();}
29     fputc(a,fp);
30     fputc(' ',fp);
31     if(a=='x')
32     cout<<"告诉我她的三门成绩是多少,我帮你记录"<<endl;
33     if(a=='y')
34     cout<<"告诉我他的三门成绩是多少,我帮你记录"<<endl;
35     double sum=0;
36     for(int i=0;i<3;i++)
37     {cin>>c;
38     fprintf(fp,"%.2lf ",c);
39     sum+=c;}
40     fprintf(fp,"%.2lf ",sum/3);
41     fprintf(fp,"%.2lf",sum);
42     cout<<"亲,还要继续添加吗"<<endl;
43     cout<<"继续请戳 1"<<endl;
44     cout<<"否则请按 0"<<endl;
45     cin>>flag;
46     getchar();
47     if(!flag)
48     break;
49     };
50     fclose(fp);
51 }

delet.cpp

  1 using namespace std;
  2 void delet(char f[])
  3 {
  4      FILE *fp;
  5      fp=fopen(f,"r");
  6      int a;
  7      char s[40];
  8      struct stu *p,*head;
  9      head=p=(struct stu*)malloc(sizeof(struct stu));
 10      p->last=NULL;
 11      if(fp==0)
 12      {
 13          cout<<endl;
 14          cout<<"没有找到文件 "<<f<<"...."<<endl;
 15          return ;
 16      }
 17      long long a1,b;
 18      a1=ftell(fp);
 19      fseek(fp,0,2);
 20      b=ftell(fp);
 21      fseek(fp,0,0);
 22      if(a1==b)
 23      {   cout<<endl;
 24          cout<<"目前肚肚里没有任何东西,先添加吧"<<endl;
 25          return ;
 26      }
 27      else
 28      {
 29 
 30      cout<<"输入你要删除的ta~~"<<endl;
 31     cout<<"1、名字戳我        2、学号捶我"<<endl;
 32     cin>>a;
 33     getchar();
 34   if(a==1)
 35   {
 36       cout<<"ta的名字是"<<endl;cout<<": ";
 37       gets(s);
 38   }
 39   if(a==2)
 40   {
 41        cout<<"ta的学号是"<<endl;cout<<": ";
 42        gets(s);
 43   }
 44   while(a>=3||a<=0)
 45   {
 46       cout<<"你的选项与我相隔甚远,重新选择吧"<<endl;
 47       cin>>a;
 48       getchar();
 49       if(a==1)
 50   {
 51       cout<<"ta的名字是"<<endl;cout<<": ";
 52       gets(s);
 53       break;
 54   }
 55   if(a==2)
 56   {
 57        cout<<"ta的学号是"<<endl;cout<<": ";
 58        gets(s);
 59        break;
 60   }
 61   }
 62         while(!feof(fp))
 63        {
 64         p->next=(struct stu*)malloc(sizeof(struct stu));
 65         p->next->last=p;
 66         p=p->next;
 67         fscanf(fp,"%s",p->nam);
 68         fscanf(fp,"%s",p->num);
 69         fgetc(fp);
 70         p->x=fgetc(fp);
 71         fscanf(fp,"%lf%lf%lf%lf%lf",&p->a,&p->b,&p->c,&p->ave,&p->sum);
 72         p->next=NULL;
 73         }
 74         fclose(fp);
 75          p=head;
 76         while(p->next)
 77         {
 78               p=p->next;
 79               if(a==1)
 80             {
 81              if(strcmp(p->nam,s)==0)
 82             {
 83                 p->last->next=p->next;
 84                 if(p->next)
 85                 p->next->last=p->last;
 86                 free(p);
 87                 break;
 88             }
 89             }
 90             if(a==2)
 91             {
 92              if(strcmp(p->num,s)==0)
 93             {
 94                 p->last->next=p->next;
 95                 p->next->last=p->last;
 96                 free(p);
 97                 break;
 98             }
 99             }
100         }
101         fp=fopen(f,"w");
102         p=head;
103         while(p->next)
104         {   p=p->next;
105          fputc(' ',fp);
106            fputs(p->nam,fp);
107            fputc(' ',fp);
108            fputs(p->num,fp);
109            fputc(' ',fp);
110            fputc(p->x,fp);
111            fputc(' ',fp);
112            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
113            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
114         }
115         fclose(fp);
116         cout<<endl;
117         cout<<"妥了,您讨厌的ta已经删除了";printf("%cn",1);
118 
119         }
120 }

now.cpp

 1 using namespace std;
 2  int now(char f[])
 3  {   FILE *fp;
 4      fp=fopen(f,"r");
 5      int flag=0;
 6      if(fp==0)
 7      {
 8          cout<<endl;
 9          cout<<"没有找到文件 "<<f<<"...."<<endl;
10          return flag;
11      }
12      long long a,b;
13      a=ftell(fp);
14      fseek(fp,0,2);
15      b=ftell(fp);
16      fseek(fp,0,0);
17      if(a==b)
18      {   cout<<endl;
19          cout<<"目前肚肚里没有任何东西,先添加吧"<<endl;
20           flag=1;
21          return flag;
22      }
23      else
24      {
25      struct stu *p,*head;
26      head=p=(struct stu*)malloc(sizeof(struct stu));
27      while(!feof(fp))
28        {
29         p->next=(struct stu*)malloc(sizeof(struct stu));
30         p=p->next;
31         fscanf(fp,"%s",p->nam);
32         fscanf(fp,"%s",p->num);
33         fgetc(fp);
34         p->x=fgetc(fp);
35         fscanf(fp,"%lf%lf%lf%lf%lf",&p->a,&p->b,&p->c,&p->ave,&p->sum);
36         p->next=NULL;
37         }
38          fclose(fp);
39          p=head;
40          cout<<endl<<endl;
41          printf(" 姓名     学号       性别    科目1    科目2    科目3    平均分   总分n");
42          while(p->next!=NULL)
43          {
44              p=p->next;
45              printf("%s  %s    %c     ",p->nam,p->num,p->x);
46              printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
47          }
48          cout<<endl;
49          return flag;
50      }}

jiegou.cpp

1 struct stu
2 {
3     char nam[40];
4     char num[40];
5     char x;
6     double a,b,c;
7     double ave,sum;
8     struct stu* next,*last;
9 };

see.cpp

 1 using namespace std;
 2 void see()
 3 {
 4   printf("   %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3);
 5   printf("   %c                                                                    %cn",3,3);
 6   printf("   %c                                                                    %cn",3,3);
 7   printf("   %c       ---------  学 生 成 绩 管 理 系 统  ---------                %cn",3,3);
 8   printf("   %c                                                                    %cn",3,3);
 9   printf("   %c                                          -计科二班 刘家树%c         %cn",3,1,3);
10   printf("   %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3);
11   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
12   printf("%c                                                                          %cn",4,4);
13   printf("%c             1、增加学生信息                 2、修改学生信息              %cn",4,4);
14   printf("%c                                                                          %cn",4,4);
15   printf("%c             3、显示学生信息                 4、查询学生信息              %cn",4,4);
16   printf("%c                                                                          %cn",4,4);
17   printf("%c             5、删除学生信息                 6、学生信息排序              %cn",4,4);
18   printf("%c                                                                          %cn",4,4);
19   printf("%c             7、保存学生信息至文件           8、从文件读取学生信息        %cn",4,4);
20   printf("%c                                                                          %cn",4,4);
21   printf("%c             9、拷贝学生信息至文件           10、运行结束                 %cn",4,4);
22   printf("%c                                                                          %cn",4,4);
23   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
24   cout<<endl;
25   cout<<"-----------恭候您的选择,请直接用键盘输入选项------------"<<endl;
26   cout<<"您的选择是:";
27 }

gai.cpp

 1 using namespace std;
 2 void gai(char f[])
 3 {
 4      FILE *fp;
 5      fp=fopen(f,"r");
 6      char a;
 7      struct stu *p,*head;
 8      head=p=(struct stu*)malloc(sizeof(struct stu));
 9      p->last=NULL;
10      if(fp==0)
11      {
12          cout<<endl;
13          cout<<"没有找到文件 "<<f<<"...."<<endl;
14          return ;
15      }
16      long long a1,b;
17      a1=ftell(fp);
18      fseek(fp,0,2);
19      b=ftell(fp);
20      fseek(fp,0,0);
21      if(a1==b)
22      {   cout<<endl;
23          cout<<"目前肚肚里没有任何东西,先添加吧"<<endl;
24          return ;
25      }
26      else
27      {
28      while(!feof(fp))
29        {
30         p->next=(struct stu*)malloc(sizeof(struct stu));
31         p->next->last=p;
32         p=p->next;
33         fscanf(fp,"%s",p->nam);
34         fscanf(fp,"%s",p->num);
35         fgetc(fp);
36         p->x=fgetc(fp);
37         fscanf(fp,"%lf%lf%lf%lf%lf",&p->a,&p->b,&p->c,&p->ave,&p->sum);
38         p->next=NULL;
39         }
40         fclose(fp);
41          p=head;
42        struct stu *s;
43        s=(struct stu *)malloc(sizeof(struct stu));
44         cout<<"你要修改的名字是~~"<<endl;
45         cout<<": ";
46         gets(s->nam);
47         cout<<"你要修改的学号是~~"<<endl;
48         cout<<": ";
49         gets(s->num);
50         cout<<"boy请按y,girl请按x"<<endl;
51         a=getchar();
52         while(a!='x'&&a!='y')
53        {cout<<"亲,你输的啥性别。。。"<<endl;
54         cout<<"重新输入吧:"<<endl;
55         a=getchar();}
56         s->x=a;
57         cout<<"然后是ta的三门成绩~~"<<endl;
58         cout<<": ";
59         cin>>s->a>>s->b>>s->c;
60         s->sum=s->a+s->b+s->c;
61         s->ave=s->sum/3;
62         while(p->next)
63         {
64             p=p->next;
65             if(strcmp(p->nam,s->nam)==0)
66             {
67                 p->last->next=s;
68                 s->last=p->last;
69                 s->next=p->next;
70                 if(p->next)
71                 p->next->last=s;
72                 free(p);
73                 break;
74             }
75         }
76         fp=fopen(f,"w");
77         p=head;
78         while(p->next)
79         {   p=p->next;
80             fputc(' ',fp);
81            fputs(p->nam,fp);
82            fputc(' ',fp);
83            fputs(p->num,fp);
84            fputc(' ',fp);
85            fputc(p->x,fp);
86            fputc(' ',fp);
87            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
88            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
89         }
90         fclose(fp);
91         cout<<endl;
92         cout<<"妥了,修改好了";printf("%cn",1);
93 
94         }
95 }

see2.cpp

 1 using namespace std;
 2 void see2()
 3 {
 4     printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
 5   printf("%c                                                                          %cn",4,4);
 6   printf("%c             1、增加学生信息                 2、修改学生信息              %cn",4,4);
 7   printf("%c                                                                          %cn",4,4);
 8   printf("%c             3、显示学生信息                 4、查询学生信息              %cn",4,4);
 9   printf("%c                                                                          %cn",4,4);
10   printf("%c             5、删除学生信息                 6、学生信息排序              %cn",4,4);
11   printf("%c                                                                          %cn",4,4);
12   printf("%c             7、保存学生信息至文件           8、从文件读取学生信息        %cn",4,4);
13   printf("%c                                                                          %cn",4,4);
14   printf("%c             9、拷贝学生信息至文件           10、运行结束                 %cn",4,4);
15   printf("%c                                                                          %cn",4,4);
16   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
17   cout<<endl;
18 }

cret.cpp

1 FILE * cret(char f[])
2 {
3     FILE *fp;
4     scanf("%s",f);
5     fp=fopen(f,"w");
6     fclose(fp);
7     return fp;
8 }

find.cpp

  1 using namespace std;
  2 void find(char f[])
  3 {
  4     FILE *fp;
  5      fp=fopen(f,"r");
  6      int a;
  7      double fen;
  8      char s[40];
  9      struct stu *p;
 10      p=(struct stu*)malloc(sizeof(struct stu));
 11      if(fp==0)
 12      {
 13          cout<<endl;
 14          cout<<"没有找到文件 "<<f<<"...."<<endl;
 15          return ;
 16      }
 17      long long a1,b;
 18      a1=ftell(fp);
 19      fseek(fp,0,2);
 20      b=ftell(fp);
 21      fseek(fp,0,0);
 22      if(a1==b)
 23      {   cout<<endl;
 24          cout<<"目前肚肚里没有任何东西,先添加吧"<<endl;
 25          return ;
 26      }
 27      else
 28      {
 29          cout<<"----选择你要查询的条件吧---"<<endl;
 30          see3();
 31          cout<<": ";
 32          cin>>a;
 33          getchar();
 34          while(a>=8||a<=0)
 35          {
 36              cout<<"你的选项与我相隔甚远,重新输入吧"<<endl;
 37              cout<<": ";
 38              cin>>a;
 39              getchar();
 40          }
 41          if(a>=1&&a<=2)
 42          {  if(a==1)
 43          cout<<"ta的名字是~ ";
 44          if(a==2)
 45          cout<<"ta的学号是~ ";
 46          scanf("%s",s);}
 47          if(a>2)
 48          {
 49              cout<<"ta的分数是~ ";
 50              cin>>fen;
 51          }
 52        while(!feof(fp))
 53        {
 54          fscanf(fp,"%s",p->nam);
 55          fscanf(fp,"%s",p->num);
 56          fgetc(fp);
 57          p->x=fgetc(fp);
 58          fscanf(fp,"%lf%lf%lf%lf%lf",&p->a,&p->b,&p->c,&p->ave,&p->sum);
 59              if(a==1)
 60              {   if(strcmp(p->nam,s)==0)
 61                  {
 62                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
 63                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
 64                  }
 65              }
 66              if(a==2)
 67              {
 68                if(strcmp(p->num,s)==0)
 69                  {
 70                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
 71                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
 72                  }
 73              }
 74              if(a==3)
 75              {
 76                  if(fen==p->a)
 77                  {
 78                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
 79                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
 80                  }
 81              }
 82              if(a==4)
 83              {
 84                  if(fen==p->b)
 85                  {
 86                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
 87                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
 88                  }
 89              }
 90              if(a==5)
 91              {
 92                  if(fen==p->c)
 93                  {
 94                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
 95                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
 96                  }
 97              }
 98              if(a==6)
 99              {
100                  if(fen==p->ave)
101                  {
102                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
103                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
104                  }
105              }
106              if(a==7)
107              {
108                  if(fen==p->sum)
109                  {
110                      printf("%s  %s    %c     ",p->nam,p->num,p->x);
111                      printf("%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
112                  }
113              }
114          }
115           free(p);
116          fclose(fp);
117          cout<<endl;
118          cout<<"以上是所能查询到的全部信息了,真的";printf("%cn",2);
119 }
120 }

see3.cpp

 1 using namespace std;
 2 void see3()
 3 {
 4   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
 5   printf("%c                                                                          %cn",4,4);
 6   printf("%c             1、名字                 2、学号                              %cn",4,4);
 7   printf("%c                                                                          %cn",4,4);
 8   printf("%c             3、科目1                 4、科目2                            %cn",4,4);
 9   printf("%c                                                                          %cn",4,4);
10   printf("%c             5、科目3                 6、平均分                           %cn",4,4);
11   printf("%c                                                                          %cn",4,4);
12   printf("%c             7、总分                                                      %cn",4,4);
13   printf("%c                                                                          %cn",4,4);
14   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
15   cout<<endl;
16 }

pai.cpp

  1 using namespace std;
  2 void pai(char f[])
  3 {
  4      FILE *fp;
  5      fp=fopen(f,"r");
  6      if(fp==0)
  7      {   cout<<endl;
  8          cout<<"没有找到你要排序的文件。。"<<endl;
  9          return ;
 10      }
 11      int a;
 12      struct stu *p,*head;
 13      head=p=(struct stu*)malloc(sizeof(struct stu));
 14      p->last=NULL;
 15      int n=0;
 16      long long a1,b;
 17      a1=ftell(fp);
 18      fseek(fp,0,2);
 19      b=ftell(fp);
 20      fseek(fp,0,0);
 21      if(a1==b)
 22      {   cout<<endl;
 23          cout<<"目前肚肚里没有任何东西,先添加吧"<<endl;
 24          return ;
 25      }
 26      else
 27      {
 28      while(!feof(fp))
 29        {
 30         p->next=(struct stu*)malloc(sizeof(struct stu));
 31         n++;
 32         p->next->last=p;
 33         p=p->next;
 34         fscanf(fp,"%s",p->nam);
 35         fscanf(fp,"%s",p->num);
 36         fgetc(fp);
 37         p->x=fgetc(fp);
 38         fscanf(fp,"%lf%lf%lf%lf%lf",&p->a,&p->b,&p->c,&p->ave,&p->sum);
 39         p->next=NULL;
 40         }
 41          fclose(fp);
 42          p=head;
 43          cout<<"----选择你要排序的条件吧---"<<endl;
 44          see4();
 45          cout<<": ";
 46          cin>>a;
 47          while(a>=9||a<=0)
 48          {
 49              cout<<"你的选项与我相隔甚远,重新输入吧"<<endl;
 50              cout<<": ";
 51              cin>>a;
 52          }
 53          if(a==1)
 54          {  struct stu *q,*k,*t;
 55          t=(struct stu *)malloc(sizeof(struct stu));
 56             while(p->next)
 57             {   p=p->next;
 58                 k=q=p;
 59                 while(q->next)
 60                 {    q=q->next;
 61                     if(strcmp(q->nam,k->nam)>0)
 62                     k=q;
 63 
 64                 }
 65                 if(k!=p)
 66                 {
 67                     strcpy(t->nam,k->nam);
 68                     strcpy(k->nam,p->nam);
 69                     strcpy(p->nam,t->nam);
 70                     strcpy(t->num,k->num);
 71                     strcpy(k->num,p->num);
 72                     strcpy(p->num,t->num);
 73                     t->x=k->x;
 74                     k->x=p->x;
 75                     p->x=t->x;
 76                     t->a=k->a;
 77                     k->a=p->a;
 78                     p->a=t->a;
 79                     t->b=k->b;
 80                     k->b=p->b;
 81                     p->b=t->b;
 82                     t->c=k->c;
 83                     k->c=p->c;
 84                     p->c=t->c;
 85                     t->ave=k->ave;
 86                     k->ave=p->ave;
 87                     p->ave=t->ave;
 88                     t->sum=k->sum;
 89                     k->sum=p->sum;
 90                     p->sum=t->sum;
 91 
 92                 }
 93             }
 94           fp=fopen(f,"w");
 95            p=head;
 96         while(p->next)
 97         {   p=p->next;
 98            fputc(' ',fp);
 99            fputs(p->nam,fp);
100            fputc(' ',fp);
101            fputs(p->num,fp);
102            fputc(' ',fp);
103            fputc(p->x,fp);
104            fputc(' ',fp);
105            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
106            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
107         }
108         fclose(fp);
109         cout<<endl;
110             return ;
111          }
112          if(a==2)
113          {
114              struct stu *q,*k,*t;
115              t=(struct stu *)malloc(sizeof(struct stu));
116             while(p->next)
117             {   p=p->next;
118                 k=q=p;
119                 while(q->next)
120                 {    q=q->next;
121                      if(strcmp(q->num,k->num)>0)
122                      k=q;
123 
124                 }
125                 if(k!=p)
126                 {
127                     strcpy(t->nam,k->nam);
128                     strcpy(k->nam,p->nam);
129                     strcpy(p->nam,t->nam);
130                     strcpy(t->num,k->num);
131                     strcpy(k->num,p->num);
132                     strcpy(p->num,t->num);
133                     t->x=k->x;
134                     k->x=p->x;
135                     p->x=t->x;
136                     t->a=k->a;
137                     k->a=p->a;
138                     p->a=t->a;
139                     t->b=k->b;
140                     k->b=p->b;
141                     p->b=t->b;
142                     t->c=k->c;
143                     k->c=p->c;
144                     p->c=t->c;
145                     t->ave=k->ave;
146                     k->ave=p->ave;
147                     p->ave=t->ave;
148                     t->sum=k->sum;
149                     k->sum=p->sum;
150                     p->sum=t->sum;
151 
152                 }
153             }
154           fp=fopen(f,"w");
155            p=head;
156         while(p->next)
157         {   p=p->next;
158            fputc(' ',fp);
159            fputs(p->nam,fp);
160            fputc(' ',fp);
161            fputs(p->num,fp);
162            fputc(' ',fp);
163            fputc(p->x,fp);
164            fputc(' ',fp);
165            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
166            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
167         }
168         fclose(fp);
169         cout<<endl;
170             return ;
171          }
172          if(a==3)
173          {
174              struct stu *q,*k,*t;
175              t=(struct stu *)malloc(sizeof(struct stu));
176             while(p->next)
177             {   p=p->next;
178                  k=q=p;
179                 while(q->next)
180                 {   q=q->next;
181                     if(q->a>=k->a)
182                     k=q;
183 
184                 }
185                 if(k!=p)
186                 {
187                     strcpy(t->nam,k->nam);
188                     strcpy(k->nam,p->nam);
189                     strcpy(p->nam,t->nam);
190                     strcpy(t->num,k->num);
191                     strcpy(k->num,p->num);
192                     strcpy(p->num,t->num);
193                     t->x=k->x;
194                     k->x=p->x;
195                     p->x=t->x;
196                     t->a=k->a;
197                     k->a=p->a;
198                     p->a=t->a;
199                     t->b=k->b;
200                     k->b=p->b;
201                     p->b=t->b;
202                     t->c=k->c;
203                     k->c=p->c;
204                     p->c=t->c;
205                     t->ave=k->ave;
206                     k->ave=p->ave;
207                     p->ave=t->ave;
208                     t->sum=k->sum;
209                     k->sum=p->sum;
210                     p->sum=t->sum;
211 
212                 }
213             }
214           fp=fopen(f,"w");
215            p=head;
216         while(p->next)
217         {   p=p->next;
218            fputc(' ',fp);
219            fputs(p->nam,fp);
220            fputc(' ',fp);
221            fputs(p->num,fp);
222            fputc(' ',fp);
223            fputc(p->x,fp);
224            fputc(' ',fp);
225            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
226            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
227         }
228         fclose(fp);
229         cout<<endl;
230             return ;
231          }
232          if(a==4)
233          {
234           struct stu *q,*k,*t;
235           t=(struct stu *)malloc(sizeof(struct stu));
236             while(p->next)
237             {   p=p->next;
238                  k=q=p;
239                 while(q->next)
240                 {    q=q->next;
241                     if(q->b>=k->b)
242                     k=q;
243 
244                 }
245                 if(k!=p)
246                 {
247                     strcpy(t->nam,k->nam);
248                     strcpy(k->nam,p->nam);
249                     strcpy(p->nam,t->nam);
250                     strcpy(t->num,k->num);
251                     strcpy(k->num,p->num);
252                     strcpy(p->num,t->num);
253                     t->x=k->x;
254                     k->x=p->x;
255                     p->x=t->x;
256                     t->a=k->a;
257                     k->a=p->a;
258                     p->a=t->a;
259                     t->b=k->b;
260                     k->b=p->b;
261                     p->b=t->b;
262                     t->c=k->c;
263                     k->c=p->c;
264                     p->c=t->c;
265                     t->ave=k->ave;
266                     k->ave=p->ave;
267                     p->ave=t->ave;
268                     t->sum=k->sum;
269                     k->sum=p->sum;
270                     p->sum=t->sum;
271 
272                 }
273             }
274           fp=fopen(f,"w");
275            p=head;
276         while(p->next)
277         {   p=p->next;
278            fputc(' ',fp);
279            fputs(p->nam,fp);
280            fputc(' ',fp);
281            fputs(p->num,fp);
282            fputc(' ',fp);
283            fputc(p->x,fp);
284            fputc(' ',fp);
285            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
286            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
287         }
288         fclose(fp);
289         cout<<endl;
290             return ;
291          }
292          if(a==5)
293          {
294             struct stu *q,*k,*t;
295             t=(struct stu *)malloc(sizeof(struct stu));
296             while(p->next)
297             {   p=p->next;
298                  k=q=p;
299                 while(q->next)
300                 {   q=q->next;
301                     if(q->c>=k->c)
302                     k=q;
303 
304                 }
305                 if(k!=p)
306                 {
307                     strcpy(t->nam,k->nam);
308                     strcpy(k->nam,p->nam);
309                     strcpy(p->nam,t->nam);
310                     strcpy(t->num,k->num);
311                     strcpy(k->num,p->num);
312                     strcpy(p->num,t->num);
313                     t->x=k->x;
314                     k->x=p->x;
315                     p->x=t->x;
316                     t->a=k->a;
317                     k->a=p->a;
318                     p->a=t->a;
319                     t->b=k->b;
320                     k->b=p->b;
321                     p->b=t->b;
322                     t->c=k->c;
323                     k->c=p->c;
324                     p->c=t->c;
325                     t->ave=k->ave;
326                     k->ave=p->ave;
327                     p->ave=t->ave;
328                     t->sum=k->sum;
329                     k->sum=p->sum;
330                     p->sum=t->sum;
331 
332                 }
333             }
334           fp=fopen(f,"w");
335            p=head;
336         while(p->next)
337         {   p=p->next;
338         fputc(' ',fp);
339            fputs(p->nam,fp);
340            fputc(' ',fp);
341            fputs(p->num,fp);
342            fputc(' ',fp);
343            fputc(p->x,fp);
344            fputc(' ',fp);
345            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
346            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
347         }
348         fclose(fp);
349         cout<<endl;
350             return ;
351          }
352          if(a==6)
353          {
354              struct stu *q,*k,*t;
355              t=(struct stu *)malloc(sizeof(struct stu));
356             while(p->next)
357             {   p=p->next;
358                 k=q=p;
359                 while(q->next)
360                 {   q=q->next;
361                     if(q->ave>=k->ave)
362                     k=q;
363 
364                 }
365                 if(k!=p)
366                 {
367                     strcpy(t->nam,k->nam);
368                     strcpy(k->nam,p->nam);
369                     strcpy(p->nam,t->nam);
370                     strcpy(t->num,k->num);
371                     strcpy(k->num,p->num);
372                     strcpy(p->num,t->num);
373                     t->x=k->x;
374                     k->x=p->x;
375                     p->x=t->x;
376                     t->a=k->a;
377                     k->a=p->a;
378                     p->a=t->a;
379                     t->b=k->b;
380                     k->b=p->b;
381                     p->b=t->b;
382                     t->c=k->c;
383                     k->c=p->c;
384                     p->c=t->c;
385                     t->ave=k->ave;
386                     k->ave=p->ave;
387                     p->ave=t->ave;
388                     t->sum=k->sum;
389                     k->sum=p->sum;
390                     p->sum=t->sum;
391 
392                 }
393             }
394           fp=fopen(f,"w");
395            p=head;
396         while(p->next)
397         {   p=p->next;
398           fputc(' ',fp);
399            fputs(p->nam,fp);
400            fputc(' ',fp);
401            fputs(p->num,fp);
402            fputc(' ',fp);
403            fputc(p->x,fp);
404            fputc(' ',fp);
405            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
406            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
407         }
408         fclose(fp);
409         cout<<endl;
410             return ;
411          }
412          if(a==7)
413          {
414             struct stu *q,*k,*t;
415             t=(struct stu *)malloc(sizeof(struct stu));
416             while(p->next)
417             {   p=p->next;
418                  k=q=p;
419                 while(q->next)
420                 {   q=q->next;
421                     if(q->sum>=k->sum)
422                     k=q;
423 
424                 }
425                 if(k!=p)
426                 {
427                     strcpy(t->nam,k->nam);
428                     strcpy(k->nam,p->nam);
429                     strcpy(p->nam,t->nam);
430                     strcpy(t->num,k->num);
431                     strcpy(k->num,p->num);
432                     strcpy(p->num,t->num);
433                     t->x=k->x;
434                     k->x=p->x;
435                     p->x=t->x;
436                     t->a=k->a;
437                     k->a=p->a;
438                     p->a=t->a;
439                     t->b=k->b;
440                     k->b=p->b;
441                     p->b=t->b;
442                     t->c=k->c;
443                     k->c=p->c;
444                     p->c=t->c;
445                     t->ave=k->ave;
446                     k->ave=p->ave;
447                     p->ave=t->ave;
448                     t->sum=k->sum;
449                     k->sum=p->sum;
450                     p->sum=t->sum;
451 
452                 }
453             }
454           fp=fopen(f,"w");
455            p=head;
456         while(p->next)
457         {   p=p->next;
458            fputc(' ',fp);
459            fputs(p->nam,fp);
460            fputc(' ',fp);
461            fputs(p->num,fp);
462            fputc(' ',fp);
463            fputc(p->x,fp);
464            fputc(' ',fp);
465            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
466            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
467         }
468         fclose(fp);
469         cout<<endl;
470             return ;
471          }
472          if(a==8)
473          {
474          struct stu *q,*k,*t;
475          t=(struct stu *)malloc(sizeof(struct stu));
476             while(p->next)
477             {   p=p->next;
478                  k=q=p;
479                 while(q->next)
480                 {  q=q->next;
481                     if(q->x>=k->x)
482                     k=q;
483 
484                 }
485                 if(k!=p)
486                 {
487                     strcpy(t->nam,k->nam);
488                     strcpy(k->nam,p->nam);
489                     strcpy(p->nam,t->nam);
490                     strcpy(t->num,k->num);
491                     strcpy(k->num,p->num);
492                     strcpy(p->num,t->num);
493                     t->x=k->x;
494                     k->x=p->x;
495                     p->x=t->x;
496                     t->a=k->a;
497                     k->a=p->a;
498                     p->a=t->a;
499                     t->b=k->b;
500                     k->b=p->b;
501                     p->b=t->b;
502                     t->c=k->c;
503                     k->c=p->c;
504                     p->c=t->c;
505                     t->ave=k->ave;
506                     k->ave=p->ave;
507                     p->ave=t->ave;
508                     t->sum=k->sum;
509                     k->sum=p->sum;
510                     p->sum=t->sum;
511 
512                 }
513             }
514           fp=fopen(f,"w");
515            p=head;
516         while(p->next)
517         {   p=p->next;
518            fputc(' ',fp);
519            fputs(p->nam,fp);
520            fputc(' ',fp);
521            fputs(p->num,fp);
522            fputc(' ',fp);
523            fputc(p->x,fp);
524            fputc(' ',fp);
525            fprintf(fp,"%.2lf %.2lf %.2lf ",p->a,p->b,p->c);
526            fprintf(fp,"%.2lf %.2lf",p->ave,p->sum);
527         }
528         fclose(fp);
529         cout<<endl;
530             return ;
531          }
532      }
533 }

see4.cpp

 1 using namespace std;
 2 void see4()
 3 {
 4   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
 5   printf("%c                                                                          %cn",4,4);
 6   printf("%c             1、名字                  2、学号                             %cn",4,4);
 7   printf("%c                                                                          %cn",4,4);
 8   printf("%c             3、科目1                 4、科目2                            %cn",4,4);
 9   printf("%c                                                                          %cn",4,4);
10   printf("%c             5、科目3                 6、平均分                           %cn",4,4);
11   printf("%c                                                                          %cn",4,4);
12   printf("%c             7、总分                  8、性别                             %cn",4,4);
13   printf("%c                                                                          %cn",4,4);
14   printf("%c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %cn",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
15   cout<<endl;
16 }

copy.cpp

 1 int copy(char f[],char fc[])
 2  {   FILE *fp;
 3      fp=fopen(f,"r");
 4      int flag=0;
 5      if(fp==0)
 6      {
 7          cout<<endl;
 8          cout<<"没有找到文件 "<<f<<"...."<<endl;
 9          return flag;
10      }
11      long long a,b;
12      a=ftell(fp);
13      fseek(fp,0,2);
14      b=ftell(fp);
15      fseek(fp,0,0);
16      if(a==b)
17      {   cout<<endl;
18          cout<<"目前肚肚里没有任何东西,先添加吧"<<endl;
19           flag=1;
20          return flag;
21      }
22      else
23      {
24      struct stu *p,*head;
25      head=p=(struct stu*)malloc(sizeof(struct stu));
26      while(!feof(fp))
27        {
28         p->next=(struct stu*)malloc(sizeof(struct stu));
29         p=p->next;
30         fscanf(fp,"%s",p->nam);
31         fscanf(fp,"%s",p->num);
32         fgetc(fp);
33         p->x=fgetc(fp);
34         fscanf(fp,"%lf%lf%lf%lf%lf",&p->a,&p->b,&p->c,&p->ave,&p->sum);
35         p->next=NULL;
36         }
37          fclose(fp);
38          fp=fopen(fc,"a");
39           if(fp==0)
40          {
41          cout<<endl<<"没找到文件 "<<f<<"... "<<endl;
42           return 1;
43          }
44          p=head;
45          cout<<endl<<endl;
46          while(p->next!=NULL)
47          {
48              p=p->next;
49              fputs(p->nam,fp);
50              fputc(' ',fp);
51              fputs(p->num,fp);
52              fputc(' ',fp);
53              fputc(p->x,fp);
54              fputc(' ',fp);
55             fprintf(fp,"%.2lf     %.2lf    %.2lf    %.2lf   %.2lfn",p->a,p->b,p->c,p->ave,p->sum);
56             fputc(' ',fp);
57          }
58          fclose(fp);
59          cout<<endl;
60          return flag;
61      }
62      }

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!