码迷,mamicode.com
首页 > 其他好文 > 详细

学生成绩管理系统

时间:2018-07-05 23:20:53      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:core   int   struct   bsp   flag   iter   before   ace   3.0   

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stack>
  4 #include<string.h>
  5 #include<queue>
  6 #include<algorithm>
  7 #include<stdlib.h>
  8 #include<map>
  9 #include<vector>
 10 #define PI acos(-1.0)
 11 using namespace std;
 12 typedef long long ll;
 13 map<ll,ll>::iterator it;
 14 void stuednt_insert();
 15 struct student
 16 {
 17     int num;
 18     char name[15];
 19     int score[3];
 20     double avr;
 21     struct student *next;
 22     struct student *before;
 23 };
 24 struct student *p;
 25 int num_stu=0;
 26 void student_input()
 27 {
 28     int i,j;
 29     char ch;
 30     puts("请逐个输入学生的基本信息");
 31     struct student *head,*tail,*q;
 32     head=(struct student*)malloc(sizeof(struct student));
 33     head->next=NULL;
 34     head->before=NULL;
 35     tail=head;
 36     while(1)
 37     {
 38         p=(struct student*)malloc(sizeof(struct student));
 39         scanf("%d %s %d %d %d",&p->num,&p->name,&p->score[0],&p->score[1],&p->score[2]);
 40         p->avr=(p->score[0]+p->score[1]+p->score[2])/3.0;
 41         p->next=NULL;
 42         p->before=NULL;
 43         tail->next=p;
 44         p->before=tail;
 45         tail=p;
 46         puts("若继续请输入‘y‘,否则输入‘n‘");
 47         num_stu++;
 48         scanf(" %c",&ch);
 49         if(ch==n||ch==N)
 50             break;
 51     }
 52     p=head;
 53 }
 54 void student_output()
 55 {
 56     int i,j;
 57     struct student *q;
 58     q=p->next;
 59     while(q)
 60     {
 61         printf("%d %s %d %d %d %lf\n",q->num,q->name,q->score[0],q->score[1],q->score[2],q->avr);
 62         q=q->next;
 63     }
 64 }
 65 void student_order()
 66 {
 67     int i,j;
 68     struct student *q,*t,*tail,*head,*ppq;
 69     head=p;ppq=p;
 70     q=head;
 71     for(i=0; i<num_stu-1; i++)
 72     {
 73         q=head->next;
 74         while(q->next!=NULL)
 75         {
 76             t=q->next;
 77             printf("  %d\n",t->num);
 78             if(q->avr<t->avr)
 79             {
 80 
 81                tail=q->before;
 82                tail->next=t;
 83                q->next=t->next;
 84                t->next=q;
 85             }
 86             else
 87             q=q->next;
 88         }
 89         head=head->next;
 90     }
 91 
 92     while(ppq->next!=NULL)
 93     {
 94         t=ppq->next;
 95         t->before=ppq;
 96         ppq=ppq->next;
 97 
 98     }
 99     puts("");
100     student_output();
101 }
102 void stuednt_insert()
103 {
104     int i,j;
105     char ch;
106     puts("请输入你要添加的学生的基本信息");
107     while(1)
108     {
109         struct student *t,*s,*q,*head;
110         t=(struct student*)malloc(sizeof(struct student));
111         scanf("%d %s %d %d %d",&t->num,&t->name,&t->score[0],&t->score[1],&t->score[2]);
112         t->avr=(t->score[0]+t->score[1]+t->score[2])/3.0;
113         t->next=NULL;
114         int flag=0,num=0;
115         q=p->next;
116         while(q)
117         {
118             num++;
119             printf("%d %d\n",q->num,q->before->num);
120             if(t->avr>=q->avr)
121             {
122                 head=q->next;
123                 s=q->before;
124                 s->next=t;
125                 t->next=q;
126                 q->before=t;
127                 t->before=s;
128                 q->next=head;
129                 break;
130             }
131             if(num==num_stu)
132             {
133                 puts("1");
134                 q->next=t;
135                 t->before=q;
136                 break;
137             }
138             q=q->next;
139         }
140         num_stu++;
141         puts("若继续请输入‘y‘,否则输入‘n‘");
142         scanf(" %c",&ch);
143         if(ch==n||ch==N)
144             break;
145     }
146     puts("");
147     student_output();
148 }
149 void student_Delete()
150 {
151     int i,j;
152     char ch;
153     puts("请输入你要删除的学生的学号");
154     int num,flag=0;
155     struct student *t,*s,*q,*tail;
156     while(1)
157     {
158         int l=0;
159 
160         scanf("%d",&num);
161         q=p->next;
162         while(q->next!=NULL)
163         {
164             tail=q->next;
165             if(q->num==num)
166             {
167                 t=q->before;
168                 t->next=tail;
169                 tail->before=t;
170                 break;
171             }
172             q=q->next;
173         }
174         num_stu--;;
175         puts("若继续请输入‘y‘,否则输入‘n‘");
176         scanf(" %c",&ch);
177         if(ch==n||ch==N)
178             break;
179 
180     }
181     student_output();
182     printf("%d\n",num_stu);
183 
184 
185 }
186 int main()
187 {
188     student_input();
189     student_output();
190     student_order();
191     stuednt_insert();
192     student_Delete();
193 }

 

学生成绩管理系统

标签:core   int   struct   bsp   flag   iter   before   ace   3.0   

原文地址:https://www.cnblogs.com/moomcake/p/9270554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!