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

C++ programming. Three regular functions, one for getting the data on the four s

ID: 3582036 • Letter: C

Question

C++ programming. 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

/*

Functions used:
1) getGrade() that reads a character from input and checks if it is correct grade. This function uses recursion.
2) calculateGPA() that calculates cumulative GPA for a student.
3) displayResult() that displays student name and GPA for four students in columnar form.

*/

#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

// constant char array used for checking correct grades
char gradeList[] = "ABCDFabcdf";

// structure for student with attributes name,grades of five subjects and cumulative GPA.
struct student
{
   string name;
   char grades[5];
   float avgGPA;
}students[4];

char getGrade()
{
   char grade;
   cin >> grade;
   if(strchr(gradeList,grade) == NULL)
   {
       cout<<"This is an incorrect grade, enter again ";
       grade = getGrade(); //function calls recusively itself
   }
   return grade;
}

student calculateGPA(student obj)
{
   float marks[5], total = 0.0;
   for(int i=0;i<5;i++)
   {
       switch(obj.grades[i])
       {
           case 'A' | 'a' : marks[i] = 4.0; break;
           case 'B' | 'b' : marks[i] = 3.0; break;
           case 'C' | 'c' : marks[i] = 2.0; break;
           case 'D' | 'd' : marks[i] = 1.0; break;
           case 'F' | 'f' : marks[i] = 0.0; break;
       }
       total += marks[i];
   }
   obj.avgGPA = total/5.0;
   return obj;
}

void displayResult(student obj[4])
{
   cout<<" NAME GPA"<<endl;
   cout<<" -------- ---"<<endl;
   for(int i=0;i<4; i++)
       cout<<setw(10)<<obj[i].name<<" "<<setprecision(3)<<obj[i].avgGPA<<endl;
}  

int main()
{
   students[0].name="Freddie";
   students[1].name="Jane";
   students[2].name="Jonathan";
   students[3].name="Mary";

   for(int i=0;i<4;i++)
   {
       cout<<"Enter five grades of "<<students[i].name<<endl;
       for(int j=0;j<5;j++)
           students[i].grades[j] = getGrade();
       students[i] = calculateGPA(students[i]);          
   }

   displayResult(students);
   return 0;
}

/*

Sample Input:and Output:

Enter five grades of Freddie
a
a
a
a
a
Enter five grades of Jane
a
b
a
b
d
Enter five grades of Jonathan
d
f
c
c
c
Enter five grades of Mary
c
s
This is an incorrect grade, enter again d
f
b
a

NAME    GPA

--------    ---
Freddie   4
Jane   3
Jonathan   1.4
Mary   2

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote