For C Programming Class. You are going to create a class grades info system with
ID: 3566980 • Letter: F
Question
For C Programming Class.
You are going to create a class grades info system with at most 15 grades capacity. In your program you have 6 functions. Add grades to class, Remove grades, Print grades, Sort grades, Find Max/Min grades and Calculate average. To make debugging your program easier, enter the first four grades of the class inside your program, so every time you run the program you will have at least four records readyTo solve this problem you need to declare 6 functions:addGrade, removeGrade, printGrade, sortGrade, findMinMax, calcAverage. In your main function you need to declare grades array with size 15 and initialize it with at least four grades also you need to have a variable to keep the number of grades initially 4. Then for every function you need to pass grades array and number to them. And as you see, inside your sort function, you need to call your print function to print the list of the grades after sorting.
This Is what I have so far:
#include <stdio.h>
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);
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);
void addGrade(float grades[],int counter);
{
//Calculate the number of free locations
int number=15-counter;
//get number of grades from user
int numbgrade;
//get grades
int i;
for(i=0;i<numbgrade;i++)
scanf("%f",&grades[counter+numbgrade+i]);
counter=counter+numbgrade;
}
void removeGrade(float grades[], int counter);
{
int number;//get index number of grades
scanf("%d",&number);
printf("Are you sure to remove %f ",grades[number]);
printf("yes or no ");
int i;
for(i=number;i<14;i++)
grades[i]=grades[i+1];
//validation of that number
//remove grade
}
void sortGrade(float grades[],int counter);
{
//bubble sort grades
}
void printGrade(float grades[],int counter);
{
int x;
for(x=0;x<15;x++);
printf("%f %d",grades, counter);
}
void findMinMax(float grades[],int counter);
{
//find min max in slides
}
void calcAverage(float grades[],int counter);
{
//calculate average
}
}
Explanation / Answer
//Student grades program to add grade, remover grades,sort ,print ,maximum grade and average of the grades.
#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
Hope this would be helpful.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.