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

// Test Scores Debug // Debug Program -- there are 6 errors in this program // C

ID: 3560149 • Letter: #

Question

// Test Scores Debug
// Debug Program -- there are 6 errors in this program
// Correct this program

#include <iostream>
#include <iomanip>


using namespace std;

void readData(ifstream& inputFile, int list[], int size);
void holdscrn( ); // void function to hold screen open before exit


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;

   cin >> score;

   while (inputFile)
   {
       index = score / 25;

       if (index == size)
           index--;
       if (index < size)
           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;
}

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

Explanation / Answer

#include <iostream>

#include <iomanip>

#include<fstream>

using namespace std;

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

void holdscrn( );    

void print(int list[], int size);

int main()

{

    int scores[20][3] = {};

    ifstream infile;

    infile.open("Test1.txt");

    if (!infile) // need to add ! for not successful open

    {

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

             << endl;

        holdscrn( );   // Hold screen before exit    

        return 1;

    }

    readData(infile, scores, 20,1);

infile.close();

infile.open("Test2.txt");

    if (!infile) // need to add ! for not successful open

    {

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

             << endl;

        holdscrn( );   // Hold screen before exit    

        return 1;

    }

    readData(infile, scores, 20,2);

infile.close();

infile.open("Test3.txt");

    if (!infile) // need to add ! for not successful open

    {

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

             << endl;

        holdscrn( );   // Hold screen before exit    

        return 1;

    }

    readData(infile, scores, 20,3);

infile.close();

    print(scores,20,3);

  cout << endl;

   

    holdscrn( );   // Hold screen before exit

    return 0;

}

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

{

    int score;

    int index;

int i=0;

    inputFile >> score;

    while (inputFile)

    {

list[i][x-1]=score;

        inputFile >> score;

i++;

    }

    return;

}

void print(int list[][], int size,int x)

{

float y;

char z;

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

{

y=(list[i][0]+list[i][1]+list[i][2])/3;

z=(char)(((int)y)/20+65);

cout<<"Student "<<i+1<<" test 1 score:"<<list[i][0]<<" test 2 score:"<<list[i][1]<<" test 3 score:"<<list[i][2]<<" average:"<<y<<" Final grade:"<<z;

}

    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;

}

Please rate me. Thanks a lot.