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

please write this program in C++ include the comment in the program Description:

ID: 3740008 • Letter: P

Question

please write this program in C++ include the comment in the program

Description: This program is going to allow you to calculate your grade for the class. In your program, you will ask for the user name (it should be able to include spaces). You will then ask for grades for homework assignments and have the user enter -1 when they have entered all of the grades. Next, you will ask the user for programming grades and again have them enter -1 when all are entered. You will ask for the quiz grades or -1 to end. You will ask for the exam grades or 1 to end. You will read the values into an array so that you can pass them to a function (the function is defined below). Consider: Do you need more than one array? You will calculate the grade percentage as follows: if homework grades sum the homework grades divide the sum of the homework grades by the number of homework grades entered multiple the result by 10 Add the result to the overall score

Explanation / Answer

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

// Function declarations
int hw_asg_fn (void);
int prg_asg_fn (void);
int qz_asg_fn (void);
int exm_asg_fn (void);
float calc_hw (int);
float calc_prg (int, int);
float calc_qz (int);
float calc_exm (int);
string letr_grd (float);

// Global arrays & fields
int *hw_asg = new int[5];
int *prg_asg = new int[5];
int *qz_asg = new int[5];
int *exm_asg = new int[5];
char failed;

main ()
{
char user[100];
string user_upper, ltr_grd;
int hw_asg_count, prg_asg_count, qz_asg_count, exm_asg_count, loop;
float overall;

cout << "User Name:";
cin.get (user, 100);
user_upper = user;
// Transform the name to uppercase
transform (user_upper.begin (), user_upper.end (),
         user_upper.begin (),::toupper);

// Get homework assignment grades
cout << endl << "Enter grades for homework assignments (-1 to stop):" <<
    endl;
hw_asg_count = hw_asg_fn ();

// Get programming grades
cout << endl << "Enter grades for programming assignments (-1 to stop):" <<
    endl;
prg_asg_count = prg_asg_fn ();

// Get quiz grades
cout << endl << "Enter grades for quiz assignments (-1 to stop):" << endl;
qz_asg_count = qz_asg_fn ();

// Get exam grades
cout << endl << "Enter grades for exam assignments (-1 to stop):" << endl;
exm_asg_count = exm_asg_fn ();

// Calculate overall score
overall = calc_hw (hw_asg_count);
overall = overall + calc_prg (prg_asg_count, hw_asg_count);
overall = overall + calc_qz (qz_asg_count);
overall = overall + calc_exm (exm_asg_count);
ltr_grd = letr_grd (overall);

cout << endl << user_upper << " " << overall << " " << ltr_grd;
return 0;
}

// Find the letter grade
string
letr_grd (float ovrall)
{
if (failed == 'X')
    return "F";
else
    {
      if (ovrall >= 93.0 && ovrall <= 100.0)
   return "A";
      else if (ovrall >= 90.0 && ovrall <= 92.9)
   return "A-";
      else if (ovrall >= 85.0 && ovrall <= 89.9)
   return "B+";
      else if (ovrall >= 82.0 && ovrall <= 84.9)
   return "B";
      else if (ovrall >= 80.0 && ovrall <= 81.9)
   return "B-";
      else if (ovrall >= 76.0 && ovrall <= 79.9)
   return "C+";
      else if (ovrall >= 72.0 && ovrall <= 75.9)
   return "C";
      else if (ovrall >= 69.5 && ovrall <= 71.9)
   return "C-";
      else if (ovrall >= 68.0 && ovrall <= 69.5)
   return "D+";
      else if (ovrall >= 65.0 && ovrall <= 67.9)
   return "D";
      else if (ovrall >= 60.0 && ovrall <= 64.9)
   return "D-";
      else if (ovrall < 60.0)
   return "F";
    }
}

// Calculate the homework grades
float
calc_hw (int count)
{
int loop, total;
float avg;
for (loop = 0; loop <= count; loop++)
    {
      total = total + hw_asg[loop];
    }
avg = total / count;
return (avg * 10.0);
}

// Calculate the programming grades
float
calc_prg (int count, int count1)
{
int loop, total;
float avg;
for (loop = 0; loop <= count; loop++)
    {
      total = total + prg_asg[loop];
    }
avg = total / count;
if (count1 == 0)
    {
      return (avg * 50);
    }
else
    {
      return (avg * 40);
    }
}

// Calculate the quiz grades
float
calc_qz (int count)
{
int loop, total;
float avg;
for (loop = 0; loop <= count; loop++)
    {
      total = total + qz_asg[loop];
    }
avg = total / count;
return (avg * 10.0);
}

// Calculate the exam grades
float
calc_exm (int count)
{
int loop, total;
float avg;
for (loop = 0; loop <= count; loop++)
    {
      total = total + exm_asg[loop];
      if (exm_asg[loop] < 60.0)
   failed = 'X';
    }
avg = total / count;
return (avg * 40.0);
}

// Input the homework grades using dynamic array
int
hw_asg_fn (void)
{
int n = 0, max = 5;
int var;
while (cin >> var)
    {
      if (var == -1)
   {
      return (n - 1);
   }
      hw_asg[n] = var;
      n++;
      if (n > max)
   {
      max = max * 2;   // double the previous size
      int *temp = new int[max];   // create new bigger array.
      for (int i = 0; i < n; i++)
        {
          temp[i] = hw_asg[i];   // copy values to new array.
        }
      delete[]hw_asg;   // free old array memory.
      hw_asg = temp;   // now a points to new array.
   }
    }
}

// Input the programming grades using dynamic array
int
prg_asg_fn (void)
{
int n = 0, max = 5;
int var;
while (cin >> var)
    {
      if (var == -1)
   {
      return (n - 1);
   }
      prg_asg[n] = var;
      n++;
      if (n > max)
   {
      max = max * 2;   // double the previous size
      int *temp = new int[max];   // create new bigger array.
      for (int i = 0; i < n; i++)
        {
          temp[i] = prg_asg[i];   // copy values to new array.
        }
      delete[]prg_asg;   // free old array memory.
      prg_asg = temp;   // now a points to new array.
   }
    }
}

// Input the quiz grades using dynamic array
int
qz_asg_fn (void)
{
int n = 0, max = 5;
int var;
while (cin >> var)
    {
      if (var == -1)
   {
      return (n - 1);
   }
      qz_asg[n] = var;
      n++;
      if (n > max)
   {
      max = max * 2;   // double the previous size
      int *temp = new int[max];   // create new bigger array.
      for (int i = 0; i < n; i++)
        {
          temp[i] = qz_asg[i];   // copy values to new array.
        }
      delete[]qz_asg;   // free old array memory.
      qz_asg = temp;   // now a points to new array.
   }
    }
}

// Input the exam using dynamic array
int
exm_asg_fn (void)
{
int n = 0, max = 5;
int var;
while (cin >> var)
    {
      if (var == -1)
   {
      return (n - 1);
   }
      exm_asg[n] = var;
      n++;
      if (n > max)
   {
      max = max * 2;   // double the previous size
      int *temp = new int[max];   // create new bigger array.
      for (int i = 0; i < n; i++)
        {
          temp[i] = exm_asg[i];   // copy values to new array.
        }
      delete[]exm_asg;   // free old array memory.
      exm_asg = temp;   // now a points to new array.
   }
    }
}