The program will grade a series of exams and then print a grade report for stude
ID: 639528 • Letter: T
Question
The program will grade a series of exams and then print a grade report for students in a course. Have a function that grades the exam and returns the score when passed the key and and one set of answers.Have functions that take an array and number of questions as parameters and find the high, low, and mean. Note that you have 11 possible scores 0-10 and the number of exams you have to grade is 10.
Input: An instructor has a class of students each of whom takes a multiple-choice exam with 10 questions. For each student in the class, there is one line in the input file. The line contains the answers that student gave for the exam. You don't need to store the exam answers in your program.The input file named "grade_data.txt" will have the following format:
line 1: the key for the exam (e.g.)
bccbbadbca
lines 2-n:
a set of answers. You know you are done when you get to a line with no data.
Processing: The program is to read the input file and grade each exam and print out the score for that exam. You will also keep track of how many students earned each score (0-10) and print a report after the grading.
Output: Here is an example of how the output might appear. You will write the report to an output file named "grade_report.txt"
student 1 - 8
student 2 - 10
student 3 - 1
etc.
Final Report
------------
10 - 4
9 - 2
8 - 3
.
.
1 - 3
0 - 0
high score - 10
low score - 1
mean score - 6.25
Explanation / Answer
#include <stdio.h>
#include<conio.h>
//function prototypes
void addGrade(float grades[],int &counter);
void removeGrade(float grades[],int &counter);
void sortGrade(float grades[],int &counter);
void printGrade(float grades[],int &counter);
void findMinMax(float grades[],int &counter);
void calcAverage(float grades[],int &counter);
//Note :reference varaible &counter is used to track
//count of the grades in the program
//global count variable
void main()
{
float grades[15]={87,69,98,48};
int counter=4;
int option;
printf("Grade Information System Menu ");
do
{
printf("Select one of the options: ");
printf("1. Add Grades ");
printf("2. Remove Grades ");
printf("3. Sort Grades ");
printf("4. Print Grades ");
printf("5. Find Max/Min Grades ");
printf("6. Calculate Average ");
printf("7. Quit ");
scanf("%d",&option);
fflush(stdin);
switch(option)
{
case 1: //add Grades
printf("Add Grades ");
addGrade(grades,counter);
break;
case 2://Remove Grades
printf("Remove Grades ");
removeGrade(grades,counter);
break;
case 3://Sort Grades
printf("Sort Grades ");
sortGrade(grades,counter);
break;
case 4://Print Grades
printf("Print Grades ");
printGrade(grades,counter);
break;
case 5://Find Max Min
printf("Find Max/Min Grades ");
findMinMax(grades,counter);
break;
case 6://Calculate Average
printf("Calculate Average ");
calcAverage(grades,counter);
break;
case 7:
printf("Bye Bye Mr. American Pie! ");
break;
}
}while(option!=7);
}
//Add grdes to the array of grades
void addGrade(float grades[],int &counter)
{
//get number of grades from user
int numbgrade;
//get grades
int i;
printf("How many grades you want to enter :");
scanf("%d",&numbgrade);
for(i=0;i<numbgrade;i++)
scanf("%f",&grades[counter]);
counter=counter+numbgrade;
}
//Remover grade from the array using the index value
void removeGrade(float grades[], int &counter)
{
int index;//get index number of grades
printf("Enter index of grade");
scanf("%d",&index);
printf("Are you sure to remove %f ",grades[index-1]);
grades[index-1]=0;
//validation of that number
//remove grade
}
//sort the grades array in ascending order and calls the printgrades method to display
void sortGrade(float grades[],int &counter)
{
//bubble sort grades
float swap=0;
int c,d;
for (c = 0 ; c < ( counter - 1 ); c++)
{
for (d = 0 ; d < counter - c - 1; d++)
{
if (grades[d] > grades[d+1])
{
swap = grades[d];
grades[d] = grades[d+1];
grades[d+1] = swap;
}
}
}
printGrade(grades,counter);
}
//prints the grades values
void printGrade(float grades[],int &counter)
{
int i;
for(i=0;i<counter;i++)
printf("%f ",grades[i]);
}
//Finds and display the maximum inthe grades
void findMinMax(float grades[],int &counter)
{
//find min max in slides
float max=grades[0];
for(int i=1;i<counter;i++)
{
if(grades[i]>max)
max=grades[i];
}
printf("Maximum Grade : %f",max);
}
//Calculates the average of the grades
void calcAverage(float grades[],int &counter)
{
//calculate average
//find min max in slides
float total=0;
for(int i=1;i<counter;i++)
{
total=total+grades[i];
}
printf("Average of Grades : %f",total/counter);
}
--------------------------------------------------------------------------------------------------------
Sample output:
Grade Information System Menu
Select one of the options: 1. Add Grades
2. Remove Grades
3. Sort Grades
4. Print Grades
5. Find Max/Min Grades
6. Calculate Average
7. Quit
1
Add Grades
How many grades you want to enter :1
99
Select one of the options: 1. Add Grades
2. Remove Grades
3. Sort Grades
4. Print Grades
5. Find Max/Min Grades
6. Calculate Average
7. Quit
4
Print Grades
87.000000 69.000000 98.000000 48.000000 99.000000
Select one of the options: 1. Add Grades
2. Remove Grades
3. Sort Grades
4. Print Grades
5. Find Max/Min Grades
6. Calculate Average
7. Quit
3
Sort Grades
48.000000 69.000000 87.000000 98.000000 99.000000
Select one of the options: 1. Add Grades
2. Remove Grades
3. Sort Grades
4. Print Grades
5. Find Max/Min Grades
6. Calculate Average
7. Quit
5
Find Max/Min Grades
Maximum Grade : 99.000000Select one of the options: 1. Add Grades
2. Remove Grades
3. Sort Grades
4. Print Grades
5. Find Max/Min Grades
6. Calculate Average
7. Quit
6
Calculate Average
Average of Grades : 70.600000Select one of the options: 1. Add Grades
2. Remove Grades
3. Sort Grades
4. Print Grades
5. Find Max/Min Grades
6. Calculate Average
7. Quit
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.