学生成绩管理

  1 #include <cstdlib>
  2 #include <iostream>
  3 #include <string.h>
  4 #include <stdio.h>
  5 #include <conio.h>
  6 using namespace std;
  7 struct student
  8 {
  9     char num[20];//学号
 10     char name[20];//姓名
 11     int foxscore;//fox成绩
 12     int cscore;//C语言成绩
 13     int englishscore;//英语成绩
 14     int sum;
 15     struct student *next;
 16 };
 17 struct st{
 18        student *head;
 19        int length;
 20        };
 21 
 22 void output_worker(struct student *p)//输出一个学生信息 
 23 {int n;
 24 printf("%-13s|",p->num);
 25 printf("%-13s|",p->name);
 26 printf("%-13d|",p->foxscore);
 27 printf("%-13d|",p->cscore); 
 28 printf("%-11d|",p->englishscore); 
 29 printf("%d",p->sum); 
 30 cout<<endl;
 31 for(n=1;n<=80;n++)
 32 cout<<"-"; 
 33 }
 34 
 35 int Output_surface_two()//界面; 
 36 {    system("cls");
 37      printf("\n%15s","*");
 38      cout<<"*************************************************";
 39      printf("\n%15s","*");cout<<"***************学生成绩管理系统******************\n";
 40      printf("\n%15s","(");cout<<"1) ";cout<<"信息输入(INPUT)\n";
 41      printf("\n%15s","(");cout<<"2) ";cout<<"总分统计(COUNT)\n";
 42      printf("\n%15s","(");cout<<"3) ";cout<<"总分排序(SORT)\n";
 43      printf("\n%15s","(");cout<<"4) ";cout<<"查询(QUERY)\n";
 44      printf("\n%15s","(");cout<<"5) ";cout<<"退出(EXIT)\n";
 45      printf("\n%15s","*");
 46      cout<<"请选择您要进行的操作并确认"; 
 47      int n;
 48      cin>>n;
 49     while(n<1||n>5)
 50     {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>n;} 
 51     system("cls");//清屏函数;
 52     return n;
 53 }
 54 
 55 int  insert_info(struct st &STU)//插入新员工信息;
 56 {printf("\n%15s","*");cout<<"请依次输入学生信息\n";
 57 struct student *p,*p1;
 58 p=(struct student *)malloc(sizeof(struct student));
 59  printf("\n%15s","*");cout<<"学号:";
 60  cin>>p->num;
 61  p1=STU.head;
 62  while(p1)
 63  {if(strcmp(p1->num,p->num)==0)
 64   {printf("\n%15s","*");cout<<"该学生已经存在";goto L;}
 65   p1=p1->next;
 66  }  
 67  printf("\n%15s","*");cout<<"姓名:"; 
 68  cin>>p->name;
 69  printf("\n%15s","*");cout<<"fox成绩:";
 70  cin>>p->foxscore;  
 71  printf("\n%15s","*");cout<<"C语言成绩:";
 72  cin>>p->cscore;
 73  printf("\n%15s","*");cout<<"英语成绩:";
 74  cin>>p->englishscore;
 75  p->sum=0;
 76  p->next=NULL;
 77  p->next=STU.head;
 78  STU.head=p;
 79  system("cls");
 80  printf("\n%15s","*");
 81  cout<<"添加成功\n";
 82  
 83  printf("\n%15s","*");
 84  cout<<"您所添加的学生信息为:\n\n";
 85  STU.length++;
 86  
 87  cout<<"学号         |姓名         |fox成绩      |C语言成绩    |英语成绩   |总分\n";
 88  int i;
 89  for(i=1;i<=80;i++)
 90  cout<<"-";
 91  output_worker(p);
 92  L:;
 93  printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出";
 94  int n;
 95  cin>>n;
 96  while(n<1||n>2)
 97  {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>n;}
 98  int k;
 99  if(n==1)
100  {k=Output_surface_two();
101  return k;
102  }
103  else
104  return 5;
105 }
106 
107 int score_sum(struct st &STU)//sum
108 {
109     struct student *p;
110     p=STU.head;
111     while(p)
112     {
113             p->sum=p->foxscore+p->cscore+p->englishscore;
114      p=p->next;
115     }
116 printf("\n\n%15s","*");cout<<"总分统计完毕";
117 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出";
118  int n;
119  cin>>n;
120  while(n<1||n>2)
121  {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>n;}
122  int k;
123  if(n==1)
124  {k=Output_surface_two();
125  return k;
126  }
127  else
128  return 5;
129 }
130 
131 
132 
133 
134 
135 int output_info(struct st STU)//输出所有员工信息;
136 {printf("\n%15s","*");cout<<"请选择每页要显示的信息数,最多15条";
137 int n;
138 cin>>n;
139 while(n<1||n>15)
140 {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>n;}
141  system("cls");
142 if( STU.length==0)
143 {printf("\n%15s","*");cout<<"系统中没有信息";
144  printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出";
145  int nn;
146  cin>>nn;
147  while(nn<1||nn>2)
148  {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>nn;}
149  int k;
150  if(nn==1)
151  {k=Output_surface_two();
152  return k;
153  }
154  else
155  return 5;
156 }
157 
158 struct student *p1;//信息的输出
159 p1=STU.head;
160 int count;
161 int i;
162 while(p1)
163 {system("cls");
164  cout<<"学号         |姓名         |fox成绩      |C语言成绩    |英语成绩   |总分\n";
165  for(i=1;i<=80;i++)
166  cout<<"-";
167  count=n;
168  while((count--)&&(p1))
169  {output_worker(p1);p1=p1->next;}
170  printf("\n%15s","*");cout<<"按确认键翻页"; getch();
171 }
172 printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出";
173 int nn;
174  cin>>nn;
175  while(nn<1||nn>2)
176  {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>nn;}
177  int k;
178  if(nn==1)
179  {k=Output_surface_two();
180  return k;
181  }
182  else
183  return 5;
184 }
185 
186 
187 
188 
189 
190  
191  
192 int  sort_info(struct st &STU)//对员工进行排序;
193 {system("cls");
194 
195 struct student *p1,*p2,*p3;     
196    int i,j;  
197    struct student p;
198    p1=p2=p3=STU.head;
199                  for(i=1;i<STU.length;i++,p1=p1->next)
200                   {p3=p1;
201                    for(j=i+1,p2=p1->next;j<=STU.length;j++,p2=p2->next)
202                    {if(p3->sum<p2->sum)
203                       p3=p2;
204                    }
205                    if(p3!=p1)
206                    {strcpy(p.num,p3->num);strcpy(p3->num,p1->num);strcpy(p1->num,p.num);
207                     strcpy(p.name,p3->name);strcpy(p3->name,p1->name);strcpy(p1->name,p.name);
208                     p.foxscore=p3->foxscore;p3->foxscore=p1->foxscore;p1->foxscore=p.foxscore;
209                     p.cscore=p3->cscore;p3->cscore=p1->cscore;p1->cscore=p.cscore;
210                     p.englishscore=p3->englishscore;p3->englishscore=p1->englishscore;p1->englishscore=p.englishscore;
211                     p.sum=p3->sum;p3->sum=p1->sum;p1->sum=p.sum;
212     
213                   }
214                   
215                   
216            
217           }
218           system("cls");
219           printf("\n%15s","");cout<<"排序后输出\n";
220           return 6;
221 }
222 
223 int find_info(struct st STU)// 查询员工信息;
224 {system("cls");
225 struct student *p1=(struct student *)malloc(sizeof(struct student));
226 struct student *p2=STU.head;
227 printf("\n%15s","*"); cout<<"请输入学号";
228          
229            cin>>p1->num;
230            while(p2)
231            {if(strcmp(p1->num,p2->num)==0)
232             break;
233             p2=p2->next;
234            }
235           
236           
237 if(!p2)
238 {printf("\n%15s","*");cout<<"系统中没有员工信息";
239  printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出";
240  int n;
241  cin>>n;
242  while(n<1||n>2)
243  {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>n;}
244  int k;
245  if(n==1)
246  {k=Output_surface_two();
247  return k;
248  }
249  else
250  return 5;
251 }
252 else
253 {system("cls");
254 printf("\n%15s","*");cout<<"    您所查询的员工信息    *\n\n";
255 cout<<"学号         |姓名         |fox成绩      |C语言成绩    |英语成绩   |总分\n";
256 int i;
257 for(i=1;i<=80;i++)
258 cout<<"-";
259           output_worker(p2);
260           printf("\n\n%15s","*");cout<<"按1键并确认返回,按2键将退出";
261           int n;
262           cin>>n;
263           while(n<1||n>2)
264           {printf("\n%15s","*");cout<<"输入错误,请重新输入";cin>>n;}
265           int k;
266           if(n==1)
267           {k=Output_surface_two();
268           return k;
269           }
270           else
271           return 5;
272 }
273 }
274                 
275  
276 
277        
278 
279 
280 int main(int argc, char *argv[])
281 {struct st STU;
282 int n=Output_surface_two();
283 STU.head=NULL;
284 STU.length=0;
285 while(1)
286 {
287  switch(n)
288  {case 1:n=insert_info(STU);break;
289   case 2:n=score_sum(STU);break;
290   case 3:n=sort_info(STU);break;
291   case 4:n=find_info(STU);break;
292   case 5:exit(1);break;
293   case 6:n=output_info(STU);break;
294  }
295 }
296 
297 
298     
299     return EXIT_SUCCESS;
300 }
posted @ 2012-05-30 21:56  cseriscser  阅读(525)  评论(0编辑  收藏  举报