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

I need someone to help me with the analysis assignment below: Thank you Perform

ID: 3858474 • Letter: I

Question

I need someone to help me with the analysis assignment below: Thank you

Perform a detailed analysis of the differences and similarities between M1 and M2 below.

M1

#include<iostream>

#include<iomanip>

#include<conio.h>

#include <string>

int numberStudents = 4;

using namespace std;

//functions

inline void Header(){cout << " ...programmed by Hugh...... ";};

int getData(char grade,int& num, string *name, double *totalGPA);

void calGPA(char& grade, float& gpa);

void output(double *totalGPA, string *name);

void main ()

{

       string *name;

       name = new string[4];

       double *totalGPA;

       totalGPA = new double[5];

       *name = "Freddie"; name++;

       *name = "Jane"; name++;

       *name = "Jonathan"; name++;

       *name = "Mary";

       name = name - 3;

       char grade = ' ';

       int num = 0;

      

       Header();

       grade = getData(grade, num, name, totalGPA);

       output(totalGPA, name);

       delete [] name; //Can't forget to delete the dynamic memory...

       delete [] totalGPA; //Can't forget to delete the dynamic memory...

      

} // end main

int getData(char grade, int& num, string *name, double *totalGPA)

{

       float gpa = 0;

       if (num == (numberStudents))

              return 1;

       else

       {

              cout<<" Enter "<<*name<<"'s Grades"<<endl;

              calGPA(grade, gpa);

              *totalGPA=gpa;

              system("cls");

              num++;

              name++;

              totalGPA++;

              return getData(grade, num, name, totalGPA);

       }

}// end getData

void calGPA(char& grade, float& gpa)

{     

       for (int y=1; y<6; y++)

       {

              cout<<" Grade # "<<y<<"'s Letter Grade: ";

              cin>>grade;

              switch(grade)

              {

                     case 'A': case 'a': gpa=gpa+4;

                     break;

                     case 'B': case 'b': gpa=gpa+3;

                     break;

                     case 'C': case 'c': gpa=gpa+2;

                     break;

                     case 'D': case 'd': gpa=gpa+1;

                     break;

                     case 'F': case 'f': gpa=gpa+0;

                     break;

                     default: cout<<" A Valid Letter Grade is A, B, C, D, or F "<<endl;

                     y--;

              }//end switch

       } //end for

}// end calGPA

void output(double *totalGPA, string *name)

{

       cout<<fixed<<showpoint<<setprecision(3);

       cout<<setw(30)<<left<<" STUDENT"<<right<<"GPA "<<endl;

      

       for(int x=0; x<numberStudents; x++)

       {

              cout<<" "<<setw(27)<<left<<*name<<right<<*totalGPA/5<<endl;

              totalGPA++;

              name++;

       }

              cout<<" press anyKey to continue ..."<<flush;

              _getch();

}//end output

M2

#include "stdafx.h"

#include <iostream>

#include <iomanip>

using namespace std;

//function prototypes

//recursive function to get the grades

float readGradRecur(int);

//function to output results

void displayGPA(const char *[], float[]);

//inline functions

//to calculate the GPA

inline float fCalculateGPA(float totGrade) {return totGrade / 5.0;};

//complete this function by your name

inline void printCredit() {cout << "Programmed by Me :) " << flush; };

//the main

int main()

{

   //student array

   const char *students[4] = {"Freddie", "Jane", "Jonathan", "Mary"};

   //declare the grade array

   float totalGrads [4] = {0.0, 0.0, 0.0, 0.0};

   int itr;

   //print the program header

   printCredit();

   //the loop to fill the GradeTotals

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

   //for visual studio console freze

   system("pause");

   return 0;

}//end main

//recursive function to get the grades

float readGradRecur(int inpGradeNum)

{

char inpGrade;

//to take 5 grades

if (inpGradeNum < 5)

{

cout << "Please enter grade for subject " << (inpGradeNum + 1) << ": " << flush;

cin>>inpGrade;

//to add the grades

switch (inpGrade)

{

case 'A':

case 'a':

return readGradRecur(inpGradeNum + 1) + 4.0;

break;

//if grade is B

case 'B':

case 'b':

return readGradRecur(inpGradeNum + 1) + 3.0;

break;

//if grade is c

case 'C':

case 'c':

return readGradRecur(inpGradeNum + 1) + 2.0;

break;

//if gade is d

case 'D':

case 'd':

return readGradRecur(inpGradeNum + 1) + 1.0;

break;

//if gade is f

case 'F':

case 'f':

return readGradRecur(inpGradeNum + 1) + 0.0;

break;

//if invalid grade

default:

//print the error message

cout << "Error !!!Grade should be A, B, C, D or F." << " " << flush;

return readGradRecur(inpGradeNum);

}

}

else

{

return 0.0;

}

}

//function to output the results

void displayGPA(const char *studentName[], float gpaTot[])

{

cout << " The 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;

}

}

Explanation / Answer

(1) switch case

(2) Recursive function is used in M2 to get grades

(3) Differs in displaying output

(1) Students name has been assigned

(2) Both calculated for 5 subjects

(3) usage of flush

Differences Similarities M1 and M2

(1) switch case

(2) Recursive function is used in M2 to get grades

(3) Differs in displaying output

(1) Students name has been assigned

(2) Both calculated for 5 subjects

(3) usage of flush