C语言学生成绩管理系统设计报告(大一c语言学生成绩管理系统设计报告)
你们好,最近小活发现有诸多的小伙伴们对于c语言学生成绩管理系统成绩排序,c语言学生成绩管理系统这个问题都颇为感兴趣的,今天小活为大家梳理了下,一起往下看看吧。

1、 /*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2、 ssm.c : Students' score manager V 1.01
3、 Copyright (C) 2003 by syuui . All rights reserved .
4、 Red Hat 9.0 , gcc 3.2.2 compiling passed .
5、 Usage : ssm -axnlh [-i [input file]] [-o [output file]]
6、 -a : calculate classes' average score
7、 -x : calculate students' max score
8、 -n : calculate students' min score
9、 -l : list all records
10、 -h : print help page
11、 -i [input file] : read data from [input file]
12、 Default file : in.src
13、 -o [output file] : output result to [output file]
14、 Default file : out.src
15、 _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/*/
16、 #include
17、 #include
18、 #define FNAME_LEN 255 //--------------file name length
19、 #define NM_LEN 255 //--------------name length
20、 #define _DFLT_OUT out.src //------default output file name
21、 #define _DFLT_INP in.src //------default input file name
22、 /*-=-=-=-definations of flags-=-=-=-*/
23、 #define LIST 1
24、 #define AVER 2
25、 #define MAX 4
26、 #define MIN 8
27、 #define INPUT 16
28、 #define OUTPUT 32
29、 struct MODEL {
30、 /*-=-=-=- Name -=-=-=-*/
31、 char name[NM_LEN] ;
32、 /*-=-=-=- scores -=-=-=-*/
33、 int c1 , //--------------score 1
34、 c2 , //--------------score 2
35、 c3 , //--------------score 3
36、 c4 , //--------------score 4
37、 c5 , //--------------score 5
38、 total ; //--------------total of score
39、 float aver ; //--------------average of score
40、 struct MODEL *next ; //------link pointer
41、 };
42、 typedef struct MODEL SCORE ;
43、 typedef int FLAG ;
44、 /*-=-=-=-=-=-Function _help-=-=-=-=-=-*/
45、 void _help()
46、 {
47、 fprintf( stderr , \n );
48、 fprintf( stderr , _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n\n );
49、 fprintf( stderr , ssm.c : Students' score manager V1.01\n );
50、 fprintf( stderr , Copyright (C) 2003 by syuui . All rights reserved .\n\n );
51、 fprintf( stderr , Usage : ssm -axnlh [-i ] [-o ]\n );
52、 fprintf( stderr , -a : calculate classes' average score\n );
53、 fprintf( stderr , -x : calculate students' max score\n );
54、 fprintf( stderr , -n : calculate students' min score\n );
55、 fprintf( stderr , -l : list all records\n );
56、 fprintf( stderr , -h : print this screen\n );
57、 fprintf( stderr , -i [input file] : read data from [input file]\n );
58、 fprintf( stderr , default : in.src\n );
59、 fprintf( stderr , -o [output file] : output result to [output file]\n );
60、 fprintf( stderr , default : out.src\n\n );
61、 fprintf( stderr , _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n\n );
62、 }
63、 /*-=-=-=-=-=-Function push-=-=-=-=-=-*/
64、 /* This function will push a node to link */
65、 /* If this function successfully exited , return 0 */
66、 int push( SCORE **head , //--------------head of the link
67、 const char *dname , //----------student's name
68、 const int dc1 , //--------------score 1
69、 const int dc2 , //--------------score 2
70、 const int dc3 , //--------------score 3
71、 const int dc4 , //--------------score 4
72、 const int dc5 ) //--------------score 5
73、 {
74、 SCORE *tmp ,
75、 *new ; //------new node
76、 /*-=-=-=-Open a node-=-=-=-*/
77、 new=(SCORE *)malloc( sizeof(SCORE) );
78、 /*-=-=-=-Set data-=-=-=-*/
79、 strcpy( new-name , dname );
80、 new-c1=dc1 ;
81、 new-c2=dc2 ;
82、 new-c3=dc3 ;
83、 new-c4=dc4 ;
84、 new-c5=dc5 ;
85、 /*-=-=-=-Push node into the link-=-=-=-*/
86、 if( *head==NULL )
87、 {
88、 *head=new ;
89、 (*head)-next=NULL ;
90、 }
91、 else
92、 {
93、 tmp=*head ;
94、 *head=new ;
95、 (*head)-next=tmp ;
96、 }
97、 return 0;
98、 }
99、 /*-=-=-=-=-=-Function class_aver-=-=-=-=-=-*/
100、 /* This function will claculate average score */
101、 /* This function returns number of the records */
102、 int class_aver( SCORE *head , //--------------head of the link
103、 float *ac1 , //--------------average score 1
104、 float *ac2 , //--------------average score 2
105、 float *ac3 , //--------------average score 3
106、 float *ac4 , //--------------average score 4
107、 float *ac5 ) //--------------average score 5
108、 {
109、 float tc1 , tc2 , tc3 , tc4 , tc5 ; //------total of a class
110、 SCORE *pr ;
111、 int n=0 ;
112、 pr=head ;
113、 tc1=tc2=tc3=tc4=tc5=0.0 ;
114、 while( pr !=NULL )
115、 {
116、 /*-=-=-=-Claculate total score of each class-=-=-=-*/
117、 tc1 +=pr-c1 ;
118、 tc2 +=pr-c2 ;
119、 tc3 +=pr-c3 ;
120、 tc4 +=pr-c4 ;
121、 tc5 +=pr-c5 ;
122、 pr=pr-next ;
123、 n++ ;
124、 }
125、 *ac1=tc1/n ;
126、 *ac2=tc2/n ;
127、 *ac3=tc3/n ;
128、 *ac4=tc4/n ;
129、 *ac5=tc5/n ;
130、 return n ;
131、 }
132、 /*-=-=-=-=-=-Function stu_ttl_aver-=-=-=-=-=-*/
133、 /* This function will claculate average score
134、 and total score for each student */
135、 /* This function returns number of the records */
136、 int stu_ttl_aver( SCORE *head ) //------head of the link
137、 {
138、 SCORE *pr ;
139、 int n=0 ;
140、 pr=head ;
141、 while( pr !=NULL )
142、 {
143、 /*-=-=-=-claculating total-=-=-=-*/
144、 pr-total=
145、 pr-c1 +
146、 pr-c2 +
147、 pr-c3 +
148、 pr-c4 +
149、 pr-c5 ;
150、 /*-=-=-=-claculating average-=-=-=-*/
151、 pr-aver=(float)pr-total/5.0 ;
152、 n++ ;
153、 pr=pr-next ;
154、 }
155、 return n ;
156、 }
157、 /*-=-=-=-=-=-Function srch_max-=-=-=-=-=-*/
158、 /* This function will search the record
159、 which has the max value of total score */
160、 /* This function returns a SCORE pointer
161、 which points to the result */
162、 SCORE *srch_max( SCORE *head ) //------head of the link
163、 {
164、 SCORE *pr ;
165、 int max ;
166、 pr=head ;
167、 max=-1 ;
168、 while( pr !=NULL )
169、 {
170、 /*-=-=-=-search max value-=-=-=-*/
171、 if( pr-total max )
172、 max=pr-total ;
173、 pr=pr-next ;
174、 }
175、 pr=head ;
176、 while( pr !=NULL )
177、 {
178、 /*-=-=-=-search record-=-=-=-*/
179、 if( pr-total==max )
180、 break ;
181、 pr=pr-next ;
182、 }
183、 return pr ;
184、 }
185、 /*-=-=-=-=-=-Function srch_min-=-=-=-=-=-*/
186、 /* This function will search the record
187、 which has the min value of total score */
188、 /* This function returns a SCORE pointer
189、 which points to the result */
190、 SCORE *srch_min( SCORE *head ) //------head of the link
191、 {
192、 SCORE *pr ;
193、 int min ;
194、 pr=head ;
195、 min=9999 ;
196、 while( pr !=NULL )
197、 {
198、 /*-=-=-=-search min value-=-=-=-*/
199、 if( pr-total min )
200、 min=pr-total ;
201、 pr=pr-next ;
202、 }
203、 pr=head ;
204、 while( pr !=NULL )
205、 {
206、 /*-=-=-=-search record-=-=-=-*/
207、 if( pr-total==min )
208、 break ;
209、 pr=pr-next ;
210、 }
211、 return pr ;
212、 }/*-=-=-=-=-=-functon main-=-=-=-=-=-*/
213、 int main( int argc , char *argv[] )
214、 {
215、 FILE *fp ; //----------------------I/O file stream
216、 FLAG flag=0 ; //----------------------operations flag
217、 SCORE *head , *pr;
218、 int i , ndata ,
219、 c1 , c2 , c3 , c4 , c5 ;
220、 char in_fname[FNAME_LEN] , //--------input file name
221、 out_fname[FNAME_LEN] , //------output file name
222、 name[NM_LEN] ;
223、 float ac1 , ac2 , ac3 , ac4 , ac5 ;
224、 head=NULL ;
225、 pr=NULL ;
226、 fp=NULL ;
227、 /*-=-=-=-check number of the parameters-=-=-=-*/
228、 if( argc2 )
229、 {
230、 fprintf( stderr , %s -atxnlh [-i ] [-o ]\n , argv[0] );
231、 fprintf( stderr , %s -h to get more help.\n , argv[0] );
232、 exit(1);
233、 }
234、 strcpy( in_fname , _DFLT_INP );
235、 strcpy( out_fname , _DFLT_OUT );
236、 /*-=-=-=-get the parameters and mark the flag-=-=-=-*/
237、 for( i=1 ; i {
238、 if( argv[i][0] !='-' )
239、 {
240、 fprintf( stderr , Unknown argument %s .\n , argv[i] );
241、 exit(1);
242、 }
243、 else
244、 {
245、 switch( argv[i][1] )
246、 {
247、 case 'h' :
248、 _help();
249、 exit(0);
250、 break ;
251、 case 'l' :
252、 flag |=LIST ;
253、 break ;
254、 case 'a' :
255、 flag |=AVER ;
256、 break ;
257、 case 'x' :
258、 flag |=MAX ;
259、 break ;
260、 case 'n' :
261、 flag |=MIN ;
262、 break ;
263、 case 'i' :
264、 flag |=INPUT ;
265、 i++ ;
266、 if( i=argc )
267、 break ;
268、 if( argv[i][0] !='-' )
269、 {
270、 /*-=-=-=-get input file name-=-=-=-*/
271、 strcpy( in_fname , argv[i] );
272、 break ;
273、 }
274、 else
275、 {
276、 i-- ;
277、 break ;
278、 }
279、 case 'o' :
280、 flag |=OUTPUT ;
281、 i++ ;
282、 if( i=argc )
283、 break ;
284、 if( argv[i][0] !='-' )
285、 {
286、 /*-=-=-=-get output file name-=-=-=-*/
287、 strcpy( out_fname , argv[i] );
288、 break ;
289、 }
290、 else
291、 {
292、 i-- ;
293、 break ;
294、 }
295、 default :
296、 fprintf( stderr , Unknown parameter %s .\n , argv[i] );
297、 exit(1);
298、 break ;
299、 }
300、 }
301、 }
302、 /*-=-=-=-=-=-Input data-=-=-=-=-=-*/
303、 if( (flag INPUT)==INPUT )
304、 {
305、 /*-=-=-=-opne input file stream-=-=-=-*/
306、 fp=fopen( in_fname , r );
307、 if( fp==NULL )
308、 {
309、 fprintf( stderr , %s not found or not useable .\n , in_fname );
310、 exit(1);
311、 }
312、 }
313、 if( (flag INPUT) !=INPUT )
314、 {
315、 /*-=-=-=-input from keyboard-=-=-=-*/
316、 while( printf( Now input students' score :\n ) )
317、 {
318、 if( ( printf( Name : ) , scanf( %s , name)!=1 )
319、 || ( printf( C1 : ) , scanf( %d , c1 )!=1 )
320、 || ( printf( C2 : ) , scanf( %d , c2 )!=1 )
321、 || ( printf( C3 : ) , scanf( %d , c3 )!=1 )
322、 || ( printf( C4 : ) , scanf( %d , c4 )!=1 )
323、 || ( printf( C5 : ) , scanf( %d , c5 )!=1 ) )
324、 break ;
325、 push( head, name, c1, c2, c3, c4, c5 ) ;
326、 }
327、 }
328、 else
329、 {
330、 /*-=-=-=-input from file-=-=-=-*/
331、 while( !feof( fp ) )
332、 {
333、 if( fscanf( fp , %s , name ) !=1
334、 || fscanf( fp , %d , c1 )!=1
335、 || fscanf( fp , %d , c2 )!=1
336、 || fscanf( fp , %d , c3 )!=1
337、 || fscanf( fp , %d , c4 )!=1
338、 || fscanf( fp , %d , c5 )!=1 )
339、 break ;
340、 push( head, name, c1, c2, c3, c4, c5 ) ;
341、 }
342、 }
343、 if( (flag INPUT)==INPUT )
344、 {
345、 /*-=-=-=-close input file stream-=-=-=-*/
346、 fclose( fp );
347、 }
348、 /*-=-=-=-claculate total and average score for each student-=-=-=-*/
349、 ndata=stu_ttl_aver( head );
350、 if( (flag OUTPUT) !=OUTPUT )
351、 {
352、 ;
353、 /*-=-=-=-Output to screen-=-=-=-*/
354、 }
355、 else
356、 {
357、 /*-=-=-=-Output to file , open output file stream-=-=-=-*/
358、 fp=fopen( out_fname , w );
359、 if( fp==NULL )
360、 {
361、 fprintf( stderr , %s not useable .\n , out_fname );
362、 exit(1);
363、 }
364、 }
365、 if( (flag LIST)==LIST )
366、 {
367、 /*-=-=-=-make a list-=-=-=-*/
368、 pr=head ;
369、 while( pr !=NULL )
370、 {
371、 if( (flag OUTPUT) !=0 )
372、 {
373、 /*-=-=-=-outout to file-=-=-=-*/
374、 fprintf( fp , Name : %s\n , pr-name );
375、 fprintf( fp , %3d %3d %3d %3d %3d\t%4d\t%3.2f\n ,
376、 pr-c1 ,
377、 pr-c2 ,
378、 pr-c3 ,
379、 pr-c4 ,
380、 pr-c5 ,
381、 pr-total ,
382、 pr-aver );
383、 }
384、 else
385、 {
386、 /*-=-=-=-output to screen-=-=-=-*/
387、 printf( Name : %s\n , pr-name );
388、 printf( %3d %3d %3d %3d %3d\t%4d\t%3.2f\n ,
389、 pr-c1 ,
390、 pr-c2 ,
391、 pr-c3 ,
392、 pr-c4 ,
393、 pr-c5 ,
394、 pr-total ,
395、 pr-aver );
396、 }
397、 pr=pr-next ;
398、 }
399、 }
400、 if( (flag MAX)==MAX )
401、 {
402、 /*-=-=-=-search max-=-=-=-*/
403、 pr=srch_max( head );
404、 if( (flag OUTPUT)==OUTPUT )
405、 {
406、 /*-=-=-=-output to file-=-=-=-*/
407、 fprintf( fp , MAX : %s\n , pr-name );
408、 fprintf( fp , %3d %3d %3d %3d %3d\t%4d\t%3.2f\n ,
409、 pr-c1 ,
410、 pr-c2 ,
411、 pr-c3 ,
412、 pr-c4 ,
413、 pr-c5 ,
414、 pr-total ,
415、 pr-aver );
416、 }
417、 else
418、 {
419、 /*-=-=-=-output to screen-=-=-=-*/
420、 printf( MAX : %s\n , pr-name );
421、 printf( %3d %3d %3d %3d %3d\t%4d\t%3.2f\n ,
422、 pr-c1 ,
423、 pr-c2 ,
424、 pr-c3 ,
425、 pr-c4 ,
426、 pr-c5 ,
427、 pr-total ,
428、 pr-aver );
429、 }
430、 }
431、 if( (flag MIN)==MIN )
432、 { /*-=-=-=-search min-=-=-=-*/
433、 pr=srch_min( head );
434、 if( (flag OUTPUT)==OUTPUT )
435、 {
436、 /*-=-=-=-output to file-=-=-=-*/
437、 fprintf( fp , MIN : %s\n , pr-name );
438、 fprintf( fp , %3d %3d %3d %3d %3d\t%4d\t%3.2f\n ,
439、 pr-c1 ,
440、 pr-c2 ,
441、 pr-c3 ,
442、 pr-c4 ,
443、 pr-c5 ,
444、 pr-total ,
445、 pr-aver );
446、 }
447、 else
448、 {
449、 /*-=-=-=-output to screen-=-=-=-*/
450、 printf( MIN : %s\n , pr-name );
451、 printf( %3d %3d %3d %3d %3d\t%4d\t%3.2f\n ,
452、 pr-c1 ,
453、 pr-c2 ,
454、 pr-c3 ,
455、 pr-c4 ,
456、 pr-c5 ,
457、 pr-total ,
458、 pr-aver );
459、 }
460、 }
461、 if( (flag AVER)==AVER )
462、 {
463、 /*-=-=-=-claculate average value for each class-=-=-=-*/
464、 class_aver( head , ac1 , ac2 , ac3 , ac4 , ac5 );
465、 if( (flag OUTPUT)==OUTPUT )
466、 {
467、 /*-=-=-=-output to file-=-=-=-*/
468、 fprintf( fp , Average class :\n );
469、 fprintf( fp , %3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\n ,
470、 ac1 , ac2 , ac3 , ac4 , ac5 );
471、 }
472、 else
473、 {
474、 /*-=-=-=-output to screen-=-=-=-*/
475、 printf( Average class :\n );
476、 printf( %3.2f\t%3.2f\t%3.2f\t%3.2f\t%3.2f\n ,
477、 ac1 , ac2 , ac3 , ac4 , ac5 );
478、 }
479、 }
480、 if( (flag OUTPUT)==OUTPUT )
481、 {
482、 /*-=-=-=-close output file stream-=-=-=-*/
483、 fclose( fp );
484、 }
485、 /*-=-=-=-delete link to clear memory-=-=-=-*/
486、 while( head-next !=NULL )
487、 {
488、 pr=head-next ;
489、 free( (void *)head );
490、 head=pr ;
491、 }
492、 free( (void *)head );
493、 return 0;
494、 }
495、 /*-=-=-SSM结束。c-=-=-=-*/主函数发帖的时候居然说我帖子里有禁语!我觉得头晕。
496、 找了半天,原来是这么回事。我用的一个变量标志,本来是书写的缩写,被当成了禁语。
497、 继续吧。以下是测试数据:
498、 SyuuI
499、 100 90 80 97 88
500、 FukataKyouko
501、 99 78 96 99 60
502、 MatudaJyonko
503、 89 90 67 89 95
504、 SakuraiHanamiti
505、 78 98 94 79 100
506、 以下是Makefile
507、 CC=gcc
508、 TAR=ssm
509、 BINPATH=$(HOME)/bin
510、 PROG:c.o
511、 $(CC) $(TAR).o -o $(TAR)
512、 .c.o:
513、 $(CC) $(TAR).c -c -o $(TAR).o
514、 clean:
515、 rm -f core* *~ *.o
516、 binclean:
517、 rm -f $(TAR)
518、 install:
519、 cp $(TAR) $(BINPATH)
以上就是c语言学生成绩管理系统这篇文章的一些介绍,希望能帮助到大家。
扫描二维码推送至手机访问。
版权声明:文章内容摘自网络,如果无意之中侵犯了您的版权,请联系本站,本站将在3个工作日内删除。谢谢!
