发布网友 发布时间:2022-04-26 03:01
共2个回答
热心网友 时间:2022-06-20 07:55
#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 , _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n\n );
fprintf( stderr , ssm.c : Students' score manager V1.01\n );
fprintf( stderr , Copyright (C) 2003 by syuui . All rights reserved .\n\n );
fprintf( stderr , Usage : ssm -axnlh [-i ] [-o ]\n );
fprintf( stderr , -a : calculate classes' average score\n );
fprintf( stderr , -x : calculate students' max score\n );
fprintf( stderr , -n : calculate students' min score\n );
fprintf( stderr , -l : list all records\n );
fprintf( stderr , -h : print this screen\n );
fprintf( stderr , -i [input file] : read data from [input file]\n );
fprintf( stderr , default : in.src\n );
fprintf( stderr , -o [output file] : output result to [output file]\n );
fprintf( stderr , default : out.src\n\n );
fprintf( stderr , _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/\n\n );
}
/*-=-=-=-=-=-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 ;
}
热心网友 时间:2022-06-20 07:55
好烦啊