C PROGRAM You are to write a C program that will load a 2D array with values. Yo
ID: 3889147 • Letter: C
Question
C PROGRAMYou are to write a C program that will load a 2D array with values. You can assume that the array has 4 columns. Each column will represent an exam score for a student. Each row will represent an individual student’s scores. The row subscript will become a ID for a student.
• You need to create a menu that will added 4 exam scores for a new student each time it is executed • You need a menu choice that will display the average exam scores for a student • You need a menu choice that will display the average scores by exam • You need a menu choice that will display the class average • You need a menu choice that will clear out the gradebook • You need a menu choice that will output the contents of the gradebook to a TEXT FILE • Each time the program ends the data will be saved to a binary file • Each time the programs the data will be loaded from the binary file (if exists) C PROGRAM
You are to write a C program that will load a 2D array with values. You can assume that the array has 4 columns. Each column will represent an exam score for a student. Each row will represent an individual student’s scores. The row subscript will become a ID for a student.
• You need to create a menu that will added 4 exam scores for a new student each time it is executed • You need a menu choice that will display the average exam scores for a student • You need a menu choice that will display the average scores by exam • You need a menu choice that will display the class average • You need a menu choice that will clear out the gradebook • You need a menu choice that will output the contents of the gradebook to a TEXT FILE • Each time the program ends the data will be saved to a binary file • Each time the programs the data will be loaded from the binary file (if exists)
You are to write a C program that will load a 2D array with values. You can assume that the array has 4 columns. Each column will represent an exam score for a student. Each row will represent an individual student’s scores. The row subscript will become a ID for a student.
• You need to create a menu that will added 4 exam scores for a new student each time it is executed • You need a menu choice that will display the average exam scores for a student • You need a menu choice that will display the average scores by exam • You need a menu choice that will display the class average • You need a menu choice that will clear out the gradebook • You need a menu choice that will output the contents of the gradebook to a TEXT FILE • Each time the program ends the data will be saved to a binary file • Each time the programs the data will be loaded from the binary file (if exists) You are to write a C program that will load a 2D array with values. You can assume that the array has 4 columns. Each column will represent an exam score for a student. Each row will represent an individual student’s scores. The row subscript will become a ID for a student.
• You need to create a menu that will added 4 exam scores for a new student each time it is executed • You need a menu choice that will display the average exam scores for a student • You need a menu choice that will display the average scores by exam • You need a menu choice that will display the class average • You need a menu choice that will clear out the gradebook • You need a menu choice that will output the contents of the gradebook to a TEXT FILE • Each time the program ends the data will be saved to a binary file • Each time the programs the data will be loaded from the binary file (if exists)
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#define NUMBERofSTUDENTS 3
#define EXAMSCORES 2
int scores[NUMBERofSTUDENTS][EXAMSCORES];
void initialScores(int[NUMBERofSTUDENTS][EXAMSCORES]);
double examAverage(int[], int);
double studentAverage(int[], int);
int main()
{
int i; //counter for for-loop
int j; //counter for for-loop
int NUMBERofSTUDENTSGrades; //int for total number of grades
numOfGrades = NUMBERofSTUDENTS * EXAMSCORES;
initialScores(scores); //seed initialScores to scan scores
//print table DELETE LATER!
printf("%d,%d,%d ", NUMBERofSTUDENTS, EXAMSCORES,
numOfGrades);
for(i = 0; i < NUMBERofSTUDENTS; i++)
{
for(j = 0; j < EXAMSCORES; j++)
{
printf("%5d", scores[i][j]);
}
printf(" ");
}
printf(" ");
//print average for each test
for(i=0; i < EXAMSCORES; i++)
{
printf("The average grade for test %d is %.2f ",
i+1, examAverage(scores[i], NUMBERofSTUDENTS));
}
printf(" ");
//each student average
for(i=0; i < NUMBERofSTUDENTS; i++)
{
printf("Student %d's average is: %.2f ",
i+1, studentAverage(scores[i], EXAMSCORES));
}
printf(" ");
}
void initialScores(int scores[NUMBERofSTUDENTS][EXAMSCORES])
{
int i;
int j;
for(i=0; i < NUMBERofSTUDENTS; i++)
{
for(j=0; j < EXAMSCORES; j++)
{
scanf("%d", &scores[i][j]);
}
}
}
double examAverage(int column[], int students)
{
int i; //exam counter
int sumOfGrades = 0; //sum of a column
for(i = 0; i < students; i++)
{
sumOfGrades += column[i];
}
return(double) sumOfGrades / students;
}
double studentAverage(int student[], int numOfGrades)
{
int i;
int sumStudentGrades = 0;
for(i=0; i < numOfGrades; i++)
{
sumStudentGrades += student[i];
}
return(double) sumStudentGrades / numOfGrades;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.