write a program that automates the process of generating the final student report for DC faculty considering the following restrictions.
Consider declaring three arrays for processing the student data:
studID studName studGrade
The student ID is a random number generated by the 5-digit system in the range of (10000 - 99999). Create a function to assign the student ID generated in an array of numbers.
Consider the following to generate the random number:
Add the libraries: #include <stdlib.h> #include <ctime>
In the main function add the instruction that generates unique values:
srand(time(0))
Use the following formula to generate the random number in the range of the minValue = 10000 and maxValue = 99999:
randomNumber = (rand() % (maxValue- minValue + 1)) + minValue;
Use studID for the name of the array.
Student names must be assigned when the array is declared. Use studName for the name of the array.
Example:
string studName[] = { "Adam", "Josue", "Carlos", "Frank", "Alison",
"Adrian" , "Candy", "Steven", "Albert", "Alice" };
Create a function to read student grades and store them in the student grade array. The program must validate that the range of possible values is from 0 to 100. If an incorrect value is entered, the system must ask again for this grade. Use studGrade for the name of the array. Consider the following code example for validation.
void GetInputGrades(int studGrade[])
{
//Ask for students grades.
for (int index = 0; index < A_SIZE; index++)
{
do
{
cout << "Grade: ";
cin >> studGrade[index];
} while (studGrade[index] > 100 || studGrade[index] < 0);
}
}
Create a function to calculate the grade with letter that corresponds to the numeric grade and show it as part of the report. Generate a new array (studGradeLetter) to assign the letter that corresponds to the numeric grade. Consider the following example code.
void SetGradeLetter(int studGrade[], char studGradeLetter[])
{
//Process the student's grades and assign the letter that corresponds to the grade
//in a new array (studGradeLetter)
for (int index = 0; index < A_SIZE; index++)
{
if (studGrade[index] <= 100 && studGrade[index] >= 90) //90 - 100 studGradeLetter[index] = 'A';
Create a function to calculate the number of students per grade (grade letter), and display the counter in the output report.
Create a function to calculate the total number of students approved or failed. Display the result in numeric format and percentage. Example:
Hint: % Approved Students = (Total Approved * 100) / Total Students
% Fail Students = (Total Failed * 100) / Total Students
Create a function to search for the student (s) with the highest grade. Display the result with the below data students.
Consider the following example code:
for (int index = 0; index < A_SIZE; index++)
{
if (studGradeLetter[index] == 'A')
cout << studID[index] << ' ' << studName[index]
<< ' ' << studGrade[index] << ' ' << studGradeLetter[index] << endl;
}
Create a function to calculate the general average of the course. Display the result in the output report. For example:
The final report should include the information below: Example Output:
Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code. PPlease get back to me if you need any change in the output report as you have not added the sample output report. Else please upvote.
CODE:
#include <iostream>
#include <stdlib.h>
#include <ctime>
#define A_SIZE 10 //Declare number of students as constant
using namespace std;
//Function prototype
void GetInputGrades(int studGrade[]);
void SetGradeLetter(int studGrade[], char studGradeLetter[]);
void CalculateNumStudentsPerGrade(char studGradeLetter[]);
void CalculateApprovedFailedStudents(char studGradeLetter[]);
void SearchHighestGradeStudents(int studID[], string studName[], int studGrade[], char studGradeLetter[]);
void CalculateGeneralAverage(int studGrade[]);
//main function
int main()
{
//Array declaration and initialization for students names
string studName[] = { "Adam", "Josue", "Carlos", "Frank", "Alison", "Adrian" , "Candy", "Steven", "Albert", "Alice" };
int studID[A_SIZE]; //declaring array for storing student id's
int studGrade[A_SIZE]; //declaring array for storing student grade values
char studGradeLetter[A_SIZE]; //declaring array for storing student grade letters
//Variables used for random number generator
int minValue = 10000;
int maxValue = 99999;
int randomNumber;
// Use current time as seed for random generator to prevent randomNumber repetition
srand(time(0));
for(int index = 0; index<A_SIZE; index++){ //loop through each student index
randomNumber = (rand() % (maxValue - minValue + 1)) + minValue; //generate the random number between the range
studID[index] = randomNumber; //assign randomNumber generated to studId
}
//calling functions to generate the final report
GetInputGrades(studGrade);
SetGradeLetter(studGrade, studGradeLetter);
CalculateNumStudentsPerGrade(studGradeLetter);
CalculateApprovedFailedStudents(studGradeLetter);
SearchHighestGradeStudents(studID, studName, studGrade, studGradeLetter);
CalculateGeneralAverage(studGrade);
return 0;
}
/***********************************************************
* Function to read the students grade values
* Argument: studGrade array
* Return Value: None
* *********************************************************/
void GetInputGrades(int studGrade[])
{
//Ask for students grades.
for (int index = 0; index < A_SIZE; index++) {
do {
cout << "Grade of Student "<<index+1<<": ";
cin >> studGrade[index]; //Reading the student grade into array
} while (studGrade[index] > 100 || studGrade[index] < 0); //Validating the grade
}
}
/***********************************************************
* Function to Process the student's grades and
* assign the letter that corresponds to the grade
* Argument: studGrade array and studGradeLetter array
* Return Value: None
* *********************************************************/
void SetGradeLetter(int studGrade[], char studGradeLetter[])
{
//Process the student's grades and assign the letter that corresponds to the grade
//in a new array (studGradeLetter)
for (int index = 0; index < A_SIZE; index++){
if (studGrade[index] <= 100 && studGrade[index] >= 90) //90 - 100
studGradeLetter[index] = 'A';
else if(studGrade[index] <= 89 && studGrade[index] >= 80) //80 - 89
studGradeLetter[index] = 'B';
else if(studGrade[index] <= 79 && studGrade[index] >= 70) //70 - 79
studGradeLetter[index] = 'C';
else if(studGrade[index] <= 69 && studGrade[index] >= 60) //60 - 69
studGradeLetter[index] = 'D';
else if(studGrade[index] < 60) //less than 60
studGradeLetter[index] = 'F';
}
}
/***********************************************************
* Function to calculate the number of students per grade (grade letter),
* approved or failed
* Argument: studGradeLetter array
* Return Value: None
* *********************************************************/
void CalculateNumStudentsPerGrade(char studGradeLetter[])
{
//Initialize counter Variables as 0
int A_grade_count = 0;
int B_grade_count = 0;
int C_grade_count = 0;
int D_grade_count = 0;
int F_grade_count = 0;
for (int index = 0; index < A_SIZE; index++){ //loop through each student grade letter
switch(studGradeLetter[index]){
//Increment appropriate counter for each grade letter
case 'A': A_grade_count++; break;
case 'B': B_grade_count++; break;
case 'C': C_grade_count++; break;
case 'D': D_grade_count++; break;
case 'F': F_grade_count++; break;
}
}
//displaying the counter in the output report.
cout <<"\n\nNumber of students with 'A' grade: " << A_grade_count;
cout <<"\nNumber of students with 'B' grade: " << B_grade_count;
cout <<"\nNumber of students with 'C' grade: " << C_grade_count;
cout <<"\nNumber of students with 'D' grade: " << D_grade_count;
cout <<"\nNumber of students with 'F' grade: " << F_grade_count;
}
/***********************************************************
* Function to calculate the total number of students
* approved or failed
* Argument: studGradeLetter array
* Return Value: None
* *********************************************************/
void CalculateApprovedFailedStudents(char studGradeLetter[])
{
int total_approved = 0;
int total_failed = 0;
float percentage_approved;
float percentage_failed;
for (int index = 0; index < A_SIZE; index++){ //loop through each student grade letter
if (studGradeLetter[index] == 'F') //If grade letter if 'F', increment total_failed
total_failed++;
else
total_approved++; //else increment total_approved
}
//calculate percentage of Approved and Failed Students
percentage_approved = (total_approved * 100)/ A_SIZE;
percentage_failed = (total_failed * 100)/ A_SIZE;
//Displaying the result in numeric format and percentage
cout <<"\n\nNumber of Approved Students: " << total_approved;
cout <<"\nNumber of Failed Students: " << total_failed;
cout <<"\nPercentage of Approved Students: " << percentage_approved <<"%";
cout <<"\nPercentage of failed Students: " << percentage_failed <<"%";
}
/******************************************************************
* Function to search for the student (s) with the highest grade.
* Argument: studID, studName, studGrade and studGradeLetter array
* Return Value: None
* ***************************************************************/
void SearchHighestGradeStudents(int studID[], string studName[], int studGrade[], char studGradeLetter[])
{
cout <<"\n\nStudents with the highest grade 'A': " << endl;
for (int index = 0; index < A_SIZE; index++){ //loop through each student grade letter
if (studGradeLetter[index] == 'A') //If grade letter if 'A', dislay the student details
cout << studID[index] << ' ' << studName[index] << ' ' << studGrade[index] << ' ' << studGradeLetter[index] << endl;
}
}
/******************************************************************
* Function to calculate the general average of the course
* Argument: studGrade array
* Return Value: None
* ***************************************************************/
void CalculateGeneralAverage(int studGrade[])
{
float total_grade = 0;
float average;
for (int index = 0; index < A_SIZE; index++){ //loop through each student grade Value
total_grade = total_grade + studGrade[index]; //add the grade value to total_grade
}
average = total_grade/A_SIZE; //calculating the average of course
//Displaying the average in output report
cout <<"\nAverage of the course: " << average;
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.