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

Modify the Test Scores program from the above Debug Section into a class grade b

ID: 3539846 • Letter: M

Question

Modify the Test Scores program from the above Debug Section into a class grade book that

includes a class of up to 20 students and 3 test grades. Each test is read in as a separate

file, so 3 Test files are required. The students grades should be kept in an array. Once

all three test scores are read in, calculate each students average and grade for the class.

Also print a report of the each students test grades, average and final grade as a

table, and then print the averages of each Test and overall Test Average, as well as

highest Test Grade of all Tests and the student with the highest class grade.




#include <iostream>

#include <iomanip>

#include<fstream>

using namespace std;

void readData(ifstream& inputFile, int list[], int size);

void holdscrn( );    // void function to hold screen open before exit

void print(int list[], int size);//.....error2

int main()

{

    int scores[8] = {0};

    ifstream infile;

    infile.open("TestScoresData.txt");

          if (!infile)

          {

                   cout << "Cannot open the input file. Program terminates!"

                             << endl;

                   holdscrn( );   // Hold screen before exit      

                   return 1;

          }

          readData(infile, scores, 8);

          print(scores, 8);

          cout << endl;

          infile.close();

          holdscrn( );   // Hold screen before exit

          return 0;

}

void readData(ifstream& inputFile, int list[], int size)

{

          int score;

          int index;

          inputFile>> score;

          while (inputFile)

          {

                   index = score / 25;

                   if (index == size)

                             index--;

                   if (index >=0 && index )>

                             list[index]++;

                   inputFile >> score;

          }

    //return 0;

}

void print(int list[], int size)

{

    int range;

    int lowRange = 0;

    int upperRange = 24;

    cout << "   Range       # of Students" << endl;

    for (range = 0; range < size; range++)

    {

        cout << setw(3) << lowRange << " - "

             << upperRange << setw(15)

             << list[range] << endl;

        lowRange = upperRange + 1;

        upperRange = upperRange + 25;

        if (range == size - 2)

            upperRange++;

    }

    cout << endl;

    return;

}

void holdscrn( )   // void function to hold screen open before exit

{

    char holdscreen;

    cout << " Enter one character and press return to exit program: ";

    cin >> holdscreen;

    return;

}


Explanation / Answer

// Test Scores Debug
// Debug Program -- there are 6 errors in this program
// Correct this program
#include<iostream>
#include<fstream>
// #include
using namespace std;
void readData(ifstream& inputFile, int list[][3],int index, int size);
void holdscrn( );    // void function to hold screen open before exit
void print(int list[][3],double average[20],char grade[20],int size);
void calc_average(int list[][3],double average[20],char grade[20],int size);
int main()
{
    int scores[20][3] = {0};
    double average[20];
    char grade[20];
    ifstream infile;
    infile.open("TestScoresData1.txt");
          if (!infile)
          {
                   cout << "Cannot open the input file. Program terminates!"<< endl;
                   holdscrn( );   // Hold screen before exit     
                   return 1;
          }
          readData(infile, scores, 0, 8);
        infile.close();
    ifstream infile1;
    infile1.open("TestScoresData2.txt");
          if (!infile1)
          {
                   cout << "Cannot open the input file. Program terminates!"<< endl;
                   holdscrn( );   // Hold screen before exit     
                   return 1;
          }
          readData(infile1, scores, 1, 8);
          infile1.close();
              ifstream infile2;
          infile2.open("TestScoresData3.txt");
          if (!infile2)
          {
                   cout << "Cannot open the input file. Program terminates!"<< endl;
                   holdscrn( );   // Hold screen before exit     
                   return 1;
          }
          readData(infile2, scores, 2, 8);
        infile.close();
        calc_average(scores,average,grade,8);
        print(scores,average,grade,8);
          double test_avg[3];
          double overall_avg;
          double overall_sum = 0;
          for(int j=0; j<3; j++)
          {
              double sum = 0;
              for(int i=0; i<8; i++)
              {
                  sum = sum + static_cast<double> (scores[i][j]);
              }
              overall_sum = overall_sum+sum;
            test_avg[j] = sum/8.0;
          }
        overall_avg = overall_sum/24.0;
       for(int i=0; i<3; i++)
       {
           cout << "test " << (i+1) << " average is " << test_avg[i] << endl;
       }
        cout << " Overall test average is " << overall_avg << endl;
        int high_grade = grade[0];
        int high_grade_index = 0;
        for(int i=1; i<8; i++)
        {
            if(grade[i] > high_grade)
            {
                high_grade = grade[i];
                high_grade_index = i;
            }
        }
        cout << " highest test grade is " << high_grade << " and student number is " << (high_grade_index+1) << endl;
        system("pause");
}
void readData(ifstream& inputFile, int list[][3], int index,int size)
{
        int i=0;
          while (!inputFile.eof())
          {
          inputFile >> list[i++][index];
          }
    //return 0;
}
void print(int list[][3],double average[20],char grade[20],int size)
{
for(int i=0; i<size; i++)
cout <<" Student " << (i+1) << " Average is " << average[i] << " and Grade is " << grade[i] << endl;
}
void holdscrn( )   // void function to hold screen open before exit
{
    char holdscreen;
    cout << " Enter one character and press return to exit program: ";
    cin >> holdscreen;
    return;
}
void calc_average(int list[][3],double average[20],char grade[20],int size)
{
for(int i=0; i<size; i++)
{

average[i] = static_cast<double> (list[i][0] + list[i][1]+ list[i][2])/3.0;

if(average[i] >= 90 && average[i] <=100)
grade[i] = 'A';
else if(average[i] >= 80 && average[i] <=89)
grade[i] = 'B';
else if(average[i] >= 70 && average[i] <=79)
grade[i] = 'C';
else if(average[i] >= 60 && average[i] <=69)
grade[i] = 'D';
else if(average[i] >= 50 && average[i] <=59)
grade[i] = 'E';
else
grade[i] = 'F';
}
}

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