c语言学生信息管理系统 C语言学生成绩管理系统

c语言学生信息管理系统 C语言学生成绩管理系统
C语言学生成绩管理系统C语言学生成绩管理系统――步骤/方法

C语言学生成绩管理系统 1、
/*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
ssm.c : Students' score manager V 1.01
Copyright (C) 2003 by syuui . All rights reserved .
Red Hat 9.0 , gcc 3.2.2 compiling passed .
Usage : ssm -axnlh [-i [input file]] [-o [output file]]
-a : calculate classes' average score
-x : calculate students' max score
-n : calculate students' min score
-l : list all records
-h : print help page
-i [input file] : read data from [input file]
Default file : in.src
-o [output file] : output result to [output file]
Default file : out.src
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/*/
#include
#include
#define FNAME_LEN 255 //--------------file name length
#define NM_LEN 255 //--------------name length
#define _DFLT_OUT out.src //------default output file name
#define _DFLT_INP in.src //------default input file name
/*-=-=-=-definations of flags-=-=-=-*/
#define LIST 1
#define AVER 2
#define MAX 4
#define MIN 8
#define INPUT 16
#define OUTPUT 32
struct MODEL {
/*-=-=-=- Name -=-=-=-*/
char name[NM_LEN] ;
/*-=-=-=- scores -=-=-=-*/
int c1 , //--------------score 1
c2 , //--------------score 2
c3 , //--------------score 3
c4 , //--------------score 4
c5 , //--------------score 5
total ; //--------------total of score
float aver ; //--------------average of score
struct MODEL *next ; //------link pointer
};
typedef struct MODEL SCORE ;
typedef int FLAG ;
/*-=-=-=-=-=-Function _help-=-=-=-=-=-*/
void _help()
{
fprintf( stderr , n );
fprintf( stderr , _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/nn );
fprintf( stderr , ssm.c : Students' score manager V1.01n );
fprintf( stderr , Copyright (C) 2003 by syuui . All rights reserved .nn );
fprintf( stderr , Usage : ssm -axnlh [-i ] [-o ]n );
fprintf( stderr , -a : calculate classes' average scoren );
fprintf( stderr , -x : calculate students' max scoren );
fprintf( stderr , -n : calculate students' min scoren );
fprintf( stderr , -l : list all recordsn );
fprintf( stderr , -h : print this screenn );
fprintf( stderr , -i [input file] : read data from [input file]n );
fprintf( stderr , default : in.srcn );
fprintf( stderr , -o [output file] : output result to [output file]n );
fprintf( stderr , default : out.srcnn );
fprintf( stderr , _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/nn );
}
/*-=-=-=-=-=-Function push-=-=-=-=-=-*/
/* This function will push a node to link */
/* If this function successfully exited , return 0 */
int push( SCORE **head , //--------------head of the link
const char *dname , //----------student's name
const int dc1 , //--------------score 1
const int dc2 , //--------------score 2
const int dc3 , //--------------score 3
const int dc4 , //--------------score 4
const int dc5 ) //--------------score 5
{
SCORE *tmp ,
*new ; //------new node
/*-=-=-=-Open a node-=-=-=-*/
new = (SCORE *)malloc( sizeof(SCORE) );
/*-=-=-=-Set data-=-=-=-*/
strcpy( new->name , dname );
new->c1 = dc1 ;
new->c2 = dc2 ;
new->c3 = dc3 ;
new->c4 = dc4 ;
new->c5 = dc5 ;
/*-=-=-=-Push node into the link-=-=-=-*/
if( *head == NULL )
{
*head = new ;
(*head)->next = NULL ;
}
else
{
tmp = *head ;
*head = new ;
(*head)->next = tmp ;
}
return 0;
}
/*-=-=-=-=-=-Function class_aver-=-=-=-=-=-*/
/* This function will claculate average score */
/* This function returns number of the records */
int class_aver( SCORE *head , //--------------head of the link
float *ac1 , //--------------average score 1
float *ac2 , //--------------average score 2
float *ac3 , //--------------average score 3
float *ac4 , //--------------average score 4
float *ac5 ) //--------------average score 5
{
float tc1 , tc2 , tc3 , tc4 , tc5 ; //------total of a class
SCORE *pr ;
int n=0 ;
pr = head ;
tc1 = tc2 = tc3 = tc4 = tc5 = 0.0 ;
while( pr != NULL )
{
/*-=-=-=-Claculate total score of each class-=-=-=-*/
tc1 += pr->c1 ;
tc2 += pr->c2 ;
tc3 += pr->c3 ;
tc4 += pr->c4 ;
tc5 += pr->c5 ;
pr = pr->next ;
n++ ;
}
*ac1 = tc1 / n ;
*ac2 = tc2 / n ;
*ac3 = tc3 / n ;
*ac4 = tc4 / n ;
*ac5 = tc5 / n ;
return n ;
}
/*-=-=-=-=-=-Function stu_ttl_aver-=-=-=-=-=-*/
/* This function will claculate average score
and total score for each student */
/* This function returns number of the records */
int stu_ttl_aver( SCORE *head ) //------head of the link
{
SCORE *pr ;
int n = 0 ;
pr = head ;
while( pr != NULL )
{
/*-=-=-=-claculating total-=-=-=-*/
pr->total =
pr->c1 +
pr->c2 +
pr->c3 +
pr->c4 +
pr->c5 ;
/*-=-=-=-claculating average-=-=-=-*/
pr->aver = (float)pr->total / 5.0 ;
n++ ;
pr = pr->next ;
}
return n ;
}
/*-=-=-=-=-=-Function srch_max-=-=-=-=-=-*/
/* This function will search the record
which has the max value of total score */
/* This function returns a SCORE pointer
which points to the result */
SCORE *srch_max( SCORE *head ) //------head of the link
{
SCORE *pr ;
int max ;
pr = head ;
max = -1 ;
while( pr != NULL )
{
/*-=-=-=-search max value-=-=-=-*/
if( pr->total > max )
max = pr->total ;
pr = pr->next ;
}
pr = head ;
while( pr != NULL )
{
/*-=-=-=-search record-=-=-=-*/
if( pr->total == max )
break ;
pr = pr->next ;
}
return pr ;
}
/*-=-=-=-=-=-Function srch_min-=-=-=-=-=-*/
/* This function will search the record
which has the min value of total score */
/* This function returns a SCORE pointer
which points to the result */
SCORE *srch_min( SCORE *head ) //------head of the link
{
SCORE *pr ;
int min ;
pr = head ;
min = 9999 ;
while( pr != NULL )
{
/*-=-=-=-search min value-=-=-=-*/
if( pr->total < min )
min = pr->total ;
pr = pr->next ;
}
pr = head ;
while( pr != NULL )
{
/*-=-=-=-search record-=-=-=-*/
if( pr->total == min )
break ;
pr = pr->next ;
}
return pr ;
}
C语言学生成绩管理系统 2、
/*-=-=-=-=-=-functon main-=-=-=-=-=-*/
int main( int argc , char *argv[] )
{
FILE *fp ; //----------------------I/O file stream
FLAG flag=0 ; //----------------------operations flag
SCORE *head , *pr;
int i , ndata ,
c1 , c2 , c3 , c4 , c5 ;
char in_fname[FNAME_LEN] , //--------input file name
out_fname[FNAME_LEN] , //------output file name
name[NM_LEN] ;
float ac1 , ac2 , ac3 , ac4 , ac5 ;
head = NULL ;
pr = NULL ;
fp = NULL ;
/*-=-=-=-check number of the parameters-=-=-=-*/
if( argc<2 )
{
fprintf( stderr , %s -atxnlh [-i ] [-o ]n , argv[0] );
fprintf( stderr , %s -h to get more help.n , argv[0] );
exit(1);
}
strcpy( in_fname , _DFLT_INP );
strcpy( out_fname , _DFLT_OUT );
/*-=-=-=-get the parameters and mark the flag-=-=-=-*/
for( i=1 ; i {
if( argv[i][0] != '-' )
{
fprintf( stderr , Unknown argument %s .n , argv[i] );
exit(1);
}
else
{
switch( argv[i][1] )
{
case 'h' :
_help();
exit(0);
break ;
case 'l' :
flag |= LIST ;
break ;
case 'a' :
flag |= AVER ;
break ;
case 'x' :
flag |= MAX ;
break ;
case 'n' :
flag |= MIN ;
break ;
case 'i' :
flag |= INPUT ;
i++ ;
if( i >= argc )
break ;
if( argv[i][0] != '-' )
{
/*-=-=-=-get input file name-=-=-=-*/
strcpy( in_fname , argv[i] );
break ;
}
else
{
i-- ;
break ;
}
case 'o' :
flag |= OUTPUT ;
i++ ;
if( i >= argc )
break ;
if( argv[i][0] != '-' )
{
/*-=-=-=-get output file name-=-=-=-*/
strcpy( out_fname , argv[i] );
break ;
}
else
{
i-- ;
break ;
}
default :
fprintf( stderr , Unknown parameter %s .n , argv[i] );
exit(1);
break ;
}
}
}
/*-=-=-=-=-=-Input data-=-=-=-=-=-*/
if( (flag & INPUT) == INPUT )
{
/*-=-=-=-opne input file stream-=-=-=-*/
fp = fopen( in_fname , r );
if( fp==NULL )
{
fprintf( stderr , %s not found or not useable .n , in_fname );
exit(1);
}
}
if( (flag & INPUT) != INPUT )
{
/*-=-=-=-input from keyboard-=-=-=-*/
while( printf( Now input students' score :n ) )
{
if( ( printf( Name : ) , scanf( %s , name)!=1 )
|| ( printf( C1 : ) , scanf( %d , &c1 )!=1 )
|| ( printf( C2 : ) , scanf( %d , &c2 )!=1 )
|| ( printf( C3 : ) , scanf( %d , &c3 )!=1 )
|| ( printf( C4 : ) , scanf( %d , &c4 )!=1 )
|| ( printf( C5 : ) , scanf( %d , &c5 )!=1 ) )
break ;
push( &head, name, c1, c2, c3, c4, c5 ) ;
}
}
else
{
/*-=-=-=-input from file-=-=-=-*/
while( !feof( fp ) )
{
if( fscanf( fp , %s , name ) != 1
|| fscanf( fp , %d , &c1 )!=1
|| fscanf( fp , %d , &c2 )!=1
|| fscanf( fp , %d , &c3 )!=1
|| fscanf( fp , %d , &c4 )!=1
|| fscanf( fp , %d , &c5 )!=1 )
break ;
push( &head, name, c1, c2, c3, c4, c5 ) ;
}
}
if( (flag & INPUT) == INPUT )
{
/*-=-=-=-close input file stream-=-=-=-*/
fclose( fp );
}
/*-=-=-=-claculate total and average score for each student-=-=-=-*/
ndata = stu_ttl_aver( head );
if( (flag & OUTPUT) != OUTPUT )
{
;
/*-=-=-=-Output to screen-=-=-=-*/
}
else
{
/*-=-=-=-Output to file , open output file stream-=-=-=-*/
fp = fopen( out_fname , w );
if( fp==NULL )
{
fprintf( stderr , %s not useable .n , out_fname );
exit(1);
}
}
if( (flag & LIST) == LIST )
{
/*-=-=-=-make a list-=-=-=-*/
pr = head ;
while( pr != NULL )
{
if( (flag & OUTPUT) != 0 )
{
/*-=-=-=-outout to file-=-=-=-*/
fprintf( fp , Name : %sn , pr->name );
fprintf( fp , %3d %3d %3d %3d %3dt%4dt%3.2fn ,
pr->c1 ,
pr->c2 ,
pr->c3 ,
pr->c4 ,
pr->c5 ,
pr->total ,
pr->aver );
}
else
{
/*-=-=-=-output to screen-=-=-=-*/
printf( Name : %sn , pr->name );
printf( %3d %3d %3d %3d %3dt%4dt%3.2fn ,
pr->c1 ,
pr->c2 ,
pr->c3 ,
pr->c4 ,
pr->c5 ,
pr->total ,
pr->aver );
}
pr = pr->next ;
}
}
if( (flag & MAX) == MAX )
{
/*-=-=-=-search max-=-=-=-*/
pr = srch_max( head );
if( (flag & OUTPUT) == OUTPUT )
{
/*-=-=-=-output to file-=-=-=-*/
fprintf( fp , MAX : %sn , pr->name );
fprintf( fp , %3d %3d %3d %3d %3dt%4dt%3.2fn ,
pr->c1 ,
pr->c2 ,
pr->c3 ,
pr->c4 ,
pr->c5 ,
pr->total ,
pr->aver );
}
else
{
/*-=-=-=-output to screen-=-=-=-*/
printf( MAX : %sn , pr->name );
printf( %3d %3d %3d %3d %3dt%4dt%3.2fn ,
pr->c1 ,
pr->c2 ,
pr->c3 ,
pr->c4 ,
pr->c5 ,
pr->total ,
pr->aver );
}
}
if( (flag & MIN) == MIN )
{ /*-=-=-=-search min-=-=-=-*/
pr = srch_min( head );
if( (flag & OUTPUT) == OUTPUT )
{
/*-=-=-=-output to file-=-=-=-*/
fprintf( fp , MIN : %sn , pr->name );
fprintf( fp , %3d %3d %3d %3d %3dt%4dt%3.2fn ,
pr->c1 ,
pr->c2 ,
pr->c3 ,
pr->c4 ,
pr->c5 ,
pr->total ,
pr->aver );
}
else
{
/*-=-=-=-output to screen-=-=-=-*/
printf( MIN : %sn , pr->name );
printf( %3d %3d %3d %3d %3dt%4dt%3.2fn ,
pr->c1 ,
pr->c2 ,
pr->c3 ,
pr->c4 ,
pr->c5 ,
pr->total ,
pr->aver );
}
}
if( (flag & AVER) == AVER )
{
/*-=-=-=-claculate average value for each class-=-=-=-*/
class_aver( head , &ac1 , &ac2 , &ac3 , &ac4 , &ac5 );
if( (flag & OUTPUT) == OUTPUT )
{
/*-=-=-=-output to file-=-=-=-*/
fprintf( fp , Average class :n );
fprintf( fp , %3.2ft%3.2ft%3.2ft%3.2ft%3.2fn ,
ac1 , ac2 , ac3 , ac4 , ac5 );
}
else
{
/*-=-=-=-output to screen-=-=-=-*/
printf( Average class :n );
printf( %3.2ft%3.2ft%3.2ft%3.2ft%3.2fn ,
ac1 , ac2 , ac3 , ac4 , ac5 );
}
}
if( (flag & OUTPUT)==OUTPUT )
{
/*-=-=-=-close output file stream-=-=-=-*/
fclose( fp );
}
/*-=-=-=-delete link to clear memory-=-=-=-*/
while( head->next != NULL )
{
pr = head->next ;
free( (void *)head );
head = pr ;
}
free( (void *)head );
return 0;
}
/*-=-=-=-end of ssm.c-=-=-=-*/
C语言学生成绩管理系统 3、
贴main函数那部分的时候居然说我贴子里有禁用词!我晕。
查了半天,原来是这么回事。我用的一个变量flag,原来是写的缩写,被当成禁用词了。
继续。下面是测试数据:
SyuuI
100 90 80 97 88
FukataKyouko
99 78 96 99 60
MatudaJyonko
89 90 67 89 95
SakuraiHanamiti
78 98 94 79 100
下面是Makefile
CC = gcc
TAR = ssm
BINPATH = $(HOME)/bin
PROG: .c.o
$(CC) $(TAR).o -o $(TAR)
.c.o:
$(CC) $(TAR).c -c -o $(TAR).o
clean:
rm -f core* *~ *.o
binclean:
rm -f $(TAR)
install:
cp $(TAR) $(BINPATH)C语言学生成绩管理系统――注意事项
本文仅供参考。

  

爱华网本文地址 » http://www.413yy.cn/a/8104300103/236314.html

更多阅读

一体化医院信息管理系统 一体化管理系统

[MedTrak ------新一代一体化医院信息管理系统]秦笃烈1  韩士斌2  Andrew Leong3 1首都医科大学BME系  2 东华诚信电脑科技发展公司 3 Trak公司亚洲部   前言 1998年在汉城出席MEDINFO 98',了解到澳大利亚Trak公司开发的一体化HI

商业特许经营信息管理系统 中国商业特许经营网

怎样防止误入连锁加盟骗局?时间: 2010-06-21 来源: 商贸服务司第一,应该通过商务部商业特许经营信息管理系统查询。重点了解企业是否已经通过备案,查明以后应要求特许人出示其拥有的经营资源的权利证书。如出示其注册商标、企业标志、专

学生档案管理系统课程设计 学生档案查询管理系统

C#软件开发工具实训 前言随着学校的发展,学生人数不断增加,各种需要处理的学生信息也变多了。那么一款用于处理学生信息的学生信息管理系统应运而生,该系统具有提高学生管理工作效率的特点。学生信息管理系统可以让学生信息管理工作

声明:《c语言学生信息管理系统 C语言学生成绩管理系统》为网友你是王分享!如侵犯到您的合法权益请联系我们删除