39.0k views
3 votes
Write a C++ program that manage the student’s grades. Starting with a fixed number of students (use 10 for simplicity) the user will input the grades for each student. The number of grades is given by the user. The grades are stored in an array. Two functions are called for each student. One function will give the numeric average of their grades. The other function will give a letter grade to that average. Grades are assigned on a 10-point spread. 90-100 A 80- 89 B 70-79 C 60-69 D Below 60 F

1 Answer

4 votes

Answer:

#include <iostream>

using namespace std;

float findAverage(double grades[], int numOfgrades) {

float sum = 0;

for ( int i = 0 ; i < numOfgrades; i++ ) {

sum += grades[i];

}

return (sum / numOfgrades);

}

char findLetterGrade(double grades[], int numOfgrades) {

char letter;

if(findAverage(grades, numOfgrades) >= 90 && findAverage(grades, numOfgrades) <= 100)

letter = 'A';

else if(findAverage(grades, numOfgrades) >= 80 && findAverage(grades, numOfgrades) <= 89)

letter = 'B';

else if(findAverage(grades, numOfgrades) >= 70 && findAverage(grades, numOfgrades) <= 79)

letter = 'C';

else if(findAverage(grades, numOfgrades) >= 60 && findAverage(grades, numOfgrades) <= 69)

letter = 'D';

else if(findAverage(grades, numOfgrades) >= 0 && findAverage(grades, numOfgrades) <= 59)

letter = 'F';

return letter;

}

int main()

{

int numOfgrades, grade;

for (int i = 0; i < 10; i++) {

cout<<"Enter the number of grades for student #" << i+1 <<": ";

cin >> numOfgrades;

double grades[numOfgrades];

for (int j = 0; j < numOfgrades; j++) {

cout<<"Enter the grade" << j+1 <<" for student #" << i+1 <<": ";

cin >> grade;

grades[j] = grade;

}

cout << "Student #" << i+1 << " got " << findLetterGrade(grades, numOfgrades) << endl;

}

return 0;

}

Step-by-step explanation:

Create a function named findAverage that takes two parameters, grades array and numOfgrades

Inside the function, create a for loop that iterates through the grades and calculates the sum of the grades. Then, return the average, sum/numOfgrades

Create another function named findLetterGrade that takes two parameters, grades array and numOfgrades

Inside the function, check the average grade by calling the findAverage() function. Set the letter grade using the given ranges. For example, if the result returned from findAverage() function is between 80 and 89, set the letter to 'B'. Then, return the letter.

In the main:

Create a for loop that iterates for each student, in this case 10 students. Inside the loop:

Ask the user to enter the number of grades for student. Using this value, create a grades array.

Create another for loop (inner for loop) that will set the grades array using the values entered by the user.

When the inner loop is done, call the findLetterGrade() function passing the grades array and numOfgrades as parameter and print the result

User Yurii Verbytskyi
by
5.3k points