Nov 16, 2003 22:17
Well been home from work for a while now. This is my first post. Hoping that you may care about me if you are reading this. These last few days have been tough and i'm at a down right now.
Once I spend time tomorrow i'll get this updated and lookin shnazzy.
I have a ton of homework to do tonight so i'm off. Peace.
Leave a comment
#include
#define STUDENTS 3
#define EXAMS 4
void minimum( int [][ EXAMS ], int, int );
void maximum( int [][ EXAMS ], int, int );
void average( int [][ EXAMS ], int, int );
void printArray( int [][ EXAMS ], int, int );
void printMenu( void );
int main()
{
void ( *processGrades[ 4 ] )( int [][ EXAMS ], int, int )
= { printArray, minimum, maximum, average};
int student, input = 0,
studentGrades[ STUDENTS ][ EXAMS ] =
{ { 77, 68, 86, 73 },
{ 96, 87, 89, 78 },
{ 70, 90, 86, 81 } };
while ( input != 4 ) {
do {
printMenu();
scanf( "%d", &input );
} while ( input < 0 || input > 4 );
if ( input != 4 )
( *processGrades[ input ] )( studentGrades, STUDENTS, EXAMS );
else
printf( "Program Ended.\n" );
}
return 0;
}
void minimum( int grades[][ EXAMS ], int pupils, int tests )
{
int i, j, lowGrade = 100;
for ( i = 0; i <= pupils - 1; i++ )
for ( j = 0; j <= tests - 1; j++ )
if ( grades[ i ][ j ] < lowGrade )
lowGrade = grades[ i ][ j ];
printf( "\nThe lowest grade is %d\n", lowGrade );
}
void maximum( int grades[][ EXAMS ], int pupils, int tests )
{
int i, j, highGrade = 0;
for ( i = 0; i <= pupils - 1; i++ )
for ( j = 0; j <= tests - 1; j++ )
if ( grades[ i ][ j ] > highGrade )
highGrade = grades[ i ][ j ];
printf( "\nThe highest grade is %d\n", highGrade );
}
void average( int grades[][ EXAMS ], int pupils, int tests )
{
int i, j, total;
printf( "\n" );
for ( i = 0; i <= pupils - 1; i++ ) {
total = 0; /* reset total */
for ( j = 0; j <= tests - 1; j++ )
total += grades[ i ][ j ];
printf( "The average for student %d is %.1f\n",
i + 1, ( double ) total / tests );
}
}
void printArray( int grades[][ EXAMS ],
int pupils, int tests )
{
int i, j;
printf( "\n [0] [1] [2] [3]" );
for ( i = 0; i <= pupils - 1; i++ ) {
printf( "\nstudentGrades[ %d ] ", i );
for ( j = 0; j <= tests - 1; j++ )
printf( "%-5d", grades[ i ][ j ] );
}
printf( "\n" );
}
void printMenu( void )
{
printf( "\nEnter a input:\n"
"0 Print the array of grades\n"
"1 Find the minimum grade\n"
"2 Find the maximum grade\n"
"3 Print the average on all"
" tests for each student\n"
"4 End program\n"
" ? " );
}
Reply
Leave a comment