Question
C++ Instructions: Convert all of the arrays to dynamic arrays. Dont forget to delete the dynamic memory before your program ends. You must have three
C++
Instructions:
Convert all of the arrays to dynamic arrays. Dont forget to delete the dynamic memory before your program ends.
You must have three regular functions, one for getting the data on the four students, one for calculating the GPA, and one for the output. One of the functions must be recursive.
CODE:
#include "stdafx.h"
#include
#include
using namespace std;
float readGradRecur(int);
void displayGPA(const char *[], float[]);
inline float fCalculateGPA(float totGrade) { return totGrade / 5.0; };
inline void ProgramHeader() {
cout << "Programmed by ... " <<
"Student GPA Calculator. " << "Enter five (5) alphabetical (ABCDF) " <<
"grades for each student. " << flush;
};
int main()
{
const char *students[4] = { "Freddie", "Jane", "Jonathan", "Mary" };
float totalGrads[4] = { 0.0, 0.0, 0.0, 0.0 };
int itr;
for (int itr1 = 0; itr1 < 4; itr1++)
{
cout << " " << students[itr1] << " " << flush;
itr = 0;
totalGrads[itr1] = readGradRecur(itr++);
cout << " *****" << totalGrads[itr1] << endl << endl;
}
displayGPA(students, totalGrads);
cout << endl;
system("pause");
return 0;
}
float readGradRecur(int inpGradeNum)
{
char inpGrade;
if (inpGradeNum < 5)
{
cout << " Please enter grade " << (inpGradeNum + 1) << ": " << flush;
cin >> inpGrade;
switch (inpGrade)
{
case 'A':
case 'a':
return readGradRecur(inpGradeNum + 1) + 4.0;
break;
case 'B':
case 'b':
return readGradRecur(inpGradeNum + 1) + 3.0;
break;
case 'C':
case 'c':
return readGradRecur(inpGradeNum + 1) + 2.0;
break;
case 'D':
case 'd':
return readGradRecur(inpGradeNum + 1) + 1.0;
break;
case 'F':
case 'f':
return readGradRecur(inpGradeNum + 1) + 0.0;
break;
default:
cout << " Error: Grade should be A, B, C, D or F." << " " << flush;
return readGradRecur(inpGradeNum);
}
}
else
{
return 0.0;
}
}
void displayGPA(const char *studentName[], float gpaTot[])
{
cout << " GPA of the students: " <<
setw(12) << setiosflags(ios::fixed | ios::left) << " Student"
<< " GPA " << " --------- ----- " << flush;
for (int vi = 0; vi < 4; vi++)
{
cout << " " << setw(12) << setiosflags(ios::fixed | ios::left) << studentName[vi] <<
setiosflags(ios::fixed | ios::showpoint) <<
setprecision(3) << fCalculateGPA(gpaTot[vi]) << " " << flush;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started