Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help on thses assigment, to analyze the differeces and similarities

ID: 3851351 • Letter: I

Question

I need some help on thses assigment, to analyze the differeces and similarities between :

a. SOLUTION 3 and SOLUTION 2 and

b. SOLUTION 3 and SOLUTION 1

SOLUTION 1

#include <iostream> //cin & cout

#include <conio.h> //getch

#include <iomanip> //setiosflags & setprecision

using namespace std;

//declarations for the functions

float fGetGrades(int);

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++);

       }      //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();

}

SOLUTION 2

#include <iostream> //cin & cout

#include <conio.h> //getch

#include <iomanip> //setiosflags & setprecision

#include <string> //to use strings

using namespace std;

//declarations for the functions

float fGetGrades(int);

void fOutputGPA(const string[], 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 string 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++);

       }      //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 string 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();

}

SOLUTION 3

#include "stdafx.h"

#include <iostream>

#include <string>

#include <iomanip>

#include <conio.h>

using namespace std;

inline void get(char g[4][5], int i)

{

      

      

       cout << " Enter grade of student" << i +1;

       for (int j = 0;j < 5;j++)

              cin >> g[i][j];

       i++;

       if (i< 4)

              get (g, i);

}

inline void find_cgp(char letter [4][5], float gpa[4], int id)

{

       int sum = 0;

              for (int k = 0;k < 5;k++)

              {

                     if (letter[id][k] == 'A')

                           sum = sum + 4.0;

                     else if (letter[id][k] == 'B')

                           sum = sum + 3.0;

                     else if (letter[id][k] == 'C')

                 sum = sum + 2.0;

                     else if (letter[id][k] == 'D')

                           sum = sum + 1.0;

                     else

                           sum = sum + 0.0;

              }

              gpa[id] = sum / 5;

}

void out (float gpa[4], string name [4])

{

       for (int i = 0;i < 4;i++)

       {

              std::cout << std::setprecision(2) << std::fixed;

              cout << " GPA for student" << name[i] << ": " << gpa[i];

       }

}

int main() {

       int n = 4;

              string name[4] = { "Freddie", "Jane", "Jonathan", "Mary"};

       char grade[4][5];

       float gpa[4];

       int i = 0;

       get (grade, i);

       for (int i = 0;i < n;i++)

       {

              find_cgp(grade,gpa,i);

       }

       (gpa,name);

       system ("pause");

       _getch();

       return 0;

}

Explanation / Answer

Solution:

The three solutions are for the computation of GPA of students.

Difference and similarities between Solution 3 and solution 2

Difference and similarities between Solution 3 and solution 1