In this c program I have to be able to read from a file that can have up to 40 students. print the high, low, and average of quizzes, and students grade while quiz 1, 2, 3 are 50% and 3, 4 are the other 50%. I'm stuck ...........help please..
Input looks like:
Student Quiz Quiz Quiz Quiz Quiz
5052 78 23 78 78 99
5022 89 65 87 89 76
5552 98 87 78 90 67
Output should look like:
Student Quiz Quiz Quiz Quiz Quiz Grade
5052 78 23 78 78 99 73.83
5022 89 65 87 89 76 81.45
5552 98 87 78 90 67 83.08
High Score 98 87 87 90 99
Low Score 78 23 78 78 67
Average 88.33 58.3 81 85.67 80.67 79.45
This is what I have so far any help this is all new to me.
#include <stdio.h>
#include <stdlib.h>
#define MAXROW 40
#define MAXCOL 5
#define FLUSH fflush(stdin)
// function declarations
void getData (FILE* dataInput, int* scores[MAXROW][MAXCOL]);
int small ( const int scores[MAXROW][MAXCOL], int students, int tests );
int large ( const int scores[MAXROW][MAXCOL], int students, int tests);
void quizAvg (const int scores[MAXROW][MAXCOL], float colAvg[]);
void studentAvg (const int scores[MAXROW][MAXCOL], float *rowAvg1[][MAXCOL], float *rowAvg2 [][MAXCOL], float rowAvg [][MAXCOL]);
int printData (FILE* results, const int scores[MAXROW][MAXCOL]);
int calcorderAmt (int quantHand, int reorderPt, int minOrder);
int main (void)
{
// Local Declarations
FILE* dataInput;
FILE* results;
int row, col;
int scores [MAXROW][MAXCOL];
// Statements
printf ("Begin Report.\n");
if (!(dataInput = fopen("inventory.txt", "r")))
{
printf ("Error opening file\n\n");
return (100);
} // if open input
if (!(results = fopen ("result.txt", "w")))
{
printf ("\aError opening grades file\n");
return (102);
} // if open output
fprintf (results, " ", printData);
// while (getData
// (dataInput, &)
fprintf (results, "\tEnd of Report\n\n");
fclose (dataInput);
fclose (results);
printf ("End of Report\n");
system ("PAUSE");
return (0);
}// main
/*========================getInventory=============================
Pre dataInput is an open file.
Post reads the array
if data read -- returns 1
if EOF or error --returns 0
*/
void getData (FILE* dataInput, int* scores[MAXROW][MAXCOL])
{
// Local Declarations
int i,j;
int ioResult [i][j];
// Statements
ioResult [i][j]= fscanf (dataInput, "%d", scores[MAXROW][MAXCOL]);
if (ioResult[i][j] ==EOF)
return 0;
else if (ioResult [i][j]!=40)
{
printf ("\aError reading data\n");
return 0;
} // if
else
return;
} // getData
/*===============================Find the maximum grade====================================*/
int large ( const int scores[MAXROW][MAXCOL], int students, int tests)
{
int i;
int j;
int highGrade = 0; //initialize to lowest possible grade
for (i=1; j < tests; j++) //
{
for (j=1; j < tests; j++) // loop through columns of scores
{
if (scores[i][j] > highGrade)
{
highGrade = scores[i][j];
}
}
}
return highGrade;
}
/*========================Find the minimum grade===============================================*/
int small( const int scores[MAXROW][MAXCOL], int students, int test )
{
int i; //student counter
int j; //exam counter
int lowGrade = 100; //highest possible grade
for (i=1; j < test; j++)
{
for (j=1; j < test; j++) // loop through columns of scores
{
if (scores[i][j] < lowGrade)
{
lowGrade = scores[i][j];
}
}
}
return lowGrade; //return lowGrade;
}
/*===========================Column/Quiz Average=============================================*/
void quizAvg (const int scores[MAXROW][MAXCOL], float colAvg[])
{
int i;
int j;
for (int j = 1; j < MAXCOL; j++)
{
for (int i = 1; i < MAXROW; i++)
colAvg [j] += scores [i][j];
colAvg [j] /= MAXROW;
}
return;
}
/*=============================Row/Student Averages===================================*/
void studentAvg (const int scores[MAXROW][MAXCOL], float *rowAvg1[][MAXCOL], float *rowAvg2 [][MAXCOL], float rowAvg [][MAXCOL])
{
float *rowAvg1 [][MAXCOL];
float *rowAvg2 [][MAXCOL];
int i;
int j;
for (int i = 1; i < MAXROW; i++)
{
//for (int j = 1; j < MAXCOL; j++)
*rowAvg1 [MAXROW][j] = ((scores [MAXROW][1] + scores [MAXROW][2] + scores [MAXROW][3]) /3 *0.5);
*rowAvg2 [MAXROW][j]= ((scores [MAXROW][4] + scores [MAXROW][5]) /2 * 0.5);
rowAvg [i][j]= (*rowAvg1[MAXROW][j] + *rowAvg2[MAXROW][j]) /2;
}
return;
}//rowAvg
/* ====================printData=============================================
Writes student grade data to output file
Pre results is an open file
Post Data written to files
*/
int printData (FILE* results, const int scores[MAXROW][MAXCOL])
{
// statements
fprintf (results, " %d\n", getData);
fprintf (results, "High Score %d", highGrade);
fprintf (results, "Low Score %d", lowGrade);
fprintf (results, "Average %5.2f", quizAvg);
fprintf (results, "Grade %5.2f", studentAvg);
return 0;
} // printData