I need help to complete this assignment ASAP due tomorrow night . Thank you A. M
ID: 3849833 • Letter: I
Question
I need help to complete this assignment ASAP due tomorrow night . Thank you
A.Modification of recursion assignment as per instruction in exhibit B blow C+++ code programming
#include <iostream> //cin & cout
#include <conio.h> //getch
#include <iomanip> //setiosflags & setprecision
using namespace std;
//declarations for the functions
float fGetGrades(int); //The recursive function...
void fOutputGPA(const char *[], float[]);
inline float fCalculateGPA(float fGrades) {return fGrades / 5.0;};
inline void ProgramHeader() {cout << "Programmed by Hugh Schuett. " <<
"Student GPA Calculator. " << "Enter five (5) alphabetical (ABCDF) " <<
"grades for each student. " << flush; };
//the main
int main()
{
const char *cStudentName [4] = {"Freddie", "Jane", "Jonathan", "Mary"};
float fGradeTotals [4] = {0.0, 0.0, 0.0, 0.0};
int iCounter2;
ProgramHeader(); //function call for the program header
//the loop to fill the GradeTotals
for (int iCounter1 = 0; iCounter1 < 4; iCounter1++)
{
cout << " The students name is " << cStudentName[iCounter1] << " " << flush;
iCounter2 = 0;
fGradeTotals[iCounter1] = fGetGrades(iCounter2++);
cout << "*****" << fGradeTotals[iCounter1]<< endl << endl;
} //end for loop
fOutputGPA(cStudentName, fGradeTotals);
return 0;
}//end main
//recursive function to get the grades and fill the array
float fGetGrades(int iGradeCounter)
{
char cGradeInput;
if (iGradeCounter < 5) //only gets 5 valid grades
{
cout << "Enter grade #" << (iGradeCounter + 1) << ": " << flush;
cGradeInput = getch();
cout << cGradeInput << " " << flush;
//the case to add up the grades
switch (cGradeInput)
{
case 'A':
case 'a':
return fGetGrades(iGradeCounter + 1) + 4.0;
break;
case 'B':
case 'b':
return fGetGrades(iGradeCounter + 1) + 3.0;
break;
case 'C':
case 'c':
return fGetGrades(iGradeCounter + 1) + 2.0;
break;
case 'D':
case 'd':
return fGetGrades(iGradeCounter + 1) + 1.0;
break;
case 'F':
case 'f':
return fGetGrades(iGradeCounter + 1) + 0.0;
break;
default: //the catch all for error checking
cout << "You must enter an A, B, C, D or F." << " " << flush;
return fGetGrades(iGradeCounter); //calls the function with out changing counter
} //end switch
}//end if
else
{
return 0.0; //returns a 0.0 when it is called again and has 5 valid grades
}//end else
}//end fGetGrades
//function for output
void fOutputGPA(const char *cNameStudent[], float fGPAs[])
{
//the begining of the output
cout << " The following are the GPA's for each of the students. " <<
setw(12) << setiosflags(ios::fixed | ios::left) << "Student"
<< "GPA " << "-------- ----- " << flush;
//output for loop. it's to go thru the arrays
for (int iOutCounter = 0; iOutCounter < 4; iOutCounter++)
{
cout << setw(12) << setiosflags(ios::fixed | ios::left) << cNameStudent[iOutCounter] <<
setiosflags(ios::fixed | ios::showpoint) <<
setprecision (3) << fCalculateGPA(fGPAs[iOutCounter]) << " " << flush;
} //end of output for loop
cout << " Press any key to continue..." << flush;
getch();
}
EXHIBIT B. assignment 2 instructions to modify using the above code in A. as per c++ programming
An inline function for the “programmed by”. 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.
This project requires the use of various control structures for calculating the grade point averages (GPA) for four students. Your program should ask for the grades for each student. Each student will have five grades. After all the students’ grades have been entered, the program will then display each student name and their calculated GPA.
Project Requirements:
1. Find a function to use recursion in and use it.
2. Do not include any unused header files.
3. Grades can be entered in upper or lower case.
4. The input will be A, B, C, D, & F. Standard letter grades.
5. GPA’s are 4.0, 3.0, 2.0, 1.0 & 0.0 respectively
6. Format output to 3 decimal points (i.e. 3.500, 2.750).
7. There will be only four students (Freddie, Jane, Jonathan, & Mary)
8. Each student will have 5 grades to enter.
9. The final output for the GPA’s will be in columnar output.
10. Only catch common incorrect letter grades (i.e. K, Z, O, etc…).
Explanation / Answer
Hi,
I have checked your assignment. The code is perfect and seems to meet all the points asked in question including recursion. I have just removed getch() and replace it with cin at one place and removed one header file.
Updated code-
#include <iostream>
#include <iomanip>
using namespace std;
//declarations for the functions
float fGetGrades(int); //The recursive function...
void fOutputGPA(const char *[], float[]);
inline float fCalculateGPA(float fGrades) {return fGrades / 5.0;};
inline void ProgramHeader() {cout << "Programmed by Hugh Schuett. " <<
"Student GPA Calculator. " << "Enter five (5) alphabetical (ABCDF) " <<
"grades for each student. " << flush; };
//the main
int main()
{
const char *cStudentName [4] = {"Freddie", "Jane", "Jonathan", "Mary"};
float fGradeTotals [4] = {0.0, 0.0, 0.0, 0.0};
int iCounter2;
ProgramHeader(); //function call for the program header
//the loop to fill the GradeTotals
for (int iCounter1 = 0; iCounter1 < 4; iCounter1++)
{
cout << " The students name is " << cStudentName[iCounter1] << " " << flush;
iCounter2 = 0;
fGradeTotals[iCounter1] = fGetGrades(iCounter2++);
cout << "*****" << fGradeTotals[iCounter1]<< endl << endl;
} //end for loop
fOutputGPA(cStudentName, fGradeTotals);
return 0;
}//end main
//recursive function to get the grades and fill the array
float fGetGrades(int iGradeCounter)
{
char cGradeInput;
if (iGradeCounter < 5) //only gets 5 valid grades
{
cout << "Enter grade #" << (iGradeCounter + 1) << ": " << flush;
cin>>cGradeInput;
cout << cGradeInput << " " << flush;
//the case to add up the grades
switch (cGradeInput)
{
case 'A':
case 'a':
return fGetGrades(iGradeCounter + 1) + 4.0;
break;
case 'B':
case 'b':
return fGetGrades(iGradeCounter + 1) + 3.0;
break;
case 'C':
case 'c':
return fGetGrades(iGradeCounter + 1) + 2.0;
break;
case 'D':
case 'd':
return fGetGrades(iGradeCounter + 1) + 1.0;
break;
case 'F':
case 'f':
return fGetGrades(iGradeCounter + 1) + 0.0;
break;
default: //the catch all for error checking
cout << "You must enter an A, B, C, D or F." << " " << flush;
return fGetGrades(iGradeCounter); //calls the function with out changing counter
} //end switch
}//end if
else
{
return 0.0; //returns a 0.0 when it is called again and has 5 valid grades
}//end else
}//end fGetGrades
//function for output
void fOutputGPA(const char *cNameStudent[], float fGPAs[])
{
//the begining of the output
cout << " The following are the GPA's for each of the students. " <<
setw(12) << setiosflags(ios::fixed | ios::left) << "Student"
<< "GPA " << "-------- ----- " << flush;
//output for loop. it's to go thru the arrays
for (int iOutCounter = 0; iOutCounter < 4; iOutCounter++)
{
cout << setw(12) << setiosflags(ios::fixed | ios::left) << cNameStudent[iOutCounter] <<
setiosflags(ios::fixed | ios::showpoint) <<
setprecision (3) << fCalculateGPA(fGPAs[iOutCounter]) << " " << flush;
} //end of output for loop
cout << " Press any key to continue..." << flush;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.