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

Lab6 Grade Program You are to write a program that uses arrays to process the fo

ID: 3801303 • Letter: L

Question

Lab6 Grade Program

You are to write a program that uses arrays to process the following data:

Name    Exam1   Exam2   Exam3

John      90.9        69.9        60.0

Jane       87.0        71.0        91.0

Bill          95.5        80.7        88.0

Susan    75.0        75.1        80.0

Create the following report to a file named initialGrades.txt:

Name

Exam1

Exam2

Exam3

TotaOfScores

AverageScore

John

90.9

69.9

60.0

220.8

73.6

Jane

87.0

71.0

91.0

249.0

83.0

Bill

95.5

80.7

88.0

264.2

88.1

Susan

75.0

75.1

80.0

230.1

76.7

AverageTestScore

87.1

74.2

79.8

241.0

80.3

Prompt for an exam to change and a percentage increase.

Test you program using an Increase of 10% on Exam2 and output the revised report to revisedGrades.txt

Submit your source Lab6.cpp file, your initial.Grades.txt and revisedGrades.txt to Catalyst

Note, you may input the initial data from a file or using console input. Report the data as real numbers and 1 decimal place

Name

Exam1

Exam2

Exam3

TotaOfScores

AverageScore

John

90.9

69.9

60.0

220.8

73.6

Jane

87.0

71.0

91.0

249.0

83.0

Bill

95.5

80.7

88.0

264.2

88.1

Susan

75.0

75.1

80.0

230.1

76.7

AverageTestScore

87.1

74.2

79.8

241.0

80.3

Explanation / Answer

Here is the code for you:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void createReport(string names[], double scores[][3], ofstream &fout)
{
    double scoreTotals[3];
    for(int i = 0; i < 3; i++)
        scoreTotals[i] = 0;
    for(int i = 0; i < 4; i++)
    {
       fout << setw(15) << names[i];
       double sum = 0.0;
       for(int j = 0; j < 3; j++)
       {
          fout << setw(6) << fixed << setprecision(1) << scores[i][j];
          sum += scores[i][j];
          scoreTotals[j] += scores[i][j];
       }
       fout << setw(6) << fixed << setprecision(1) << sum;
       fout << setw(6) << fixed << setprecision(1) << sum/3 << endl;
    }  
    double sum = 0;
    fout << setw(15) << "AverageTestScore";
    for(int i = 0; i < 3; i++)
    {
       fout << setw(6) << fixed << setprecision(1) << scoreTotals[i]/4;
       sum += scoreTotals[i]/4;
    }  
    fout << setw(6) << fixed << setprecision(1) << sum;  
    fout << setw(6) << fixed << setprecision(1) << sum/3 << endl;
}
int main()
{
    string names[4];
    double scores[4][3];
    /*Reads names and scores of 4 students, 3 scores each*/
    for(int i = 0; i < 4; i++)
    {
       cout << "Enter name of student #" << i+1 << ": ";
       cin >> names[i];
       for(int j = 0; j < 3; j++)
       {
          cout << "Enter score for Exam #" << j+1 << ": ";
          cin >> scores[i][j];
       }
    }
   
    ofstream fout;
    fout.open("initialGrades.txt");
    createReport(names, scores, fout);
    fout.close();
   
    //Updates data from initialGrades.txt in the array.
    ifstream fin;
    fin.open("initialGrades.txt");
    for(int i = 0; i < 4; i++)
    {
       fin >> names[i];
       for(int j = 0; j < 3; j++)
           fin >> scores[i][j];
       //Just read away the sum and averages.
       double temp;
       fin >> temp;
       fin >> temp;  
    }
    fin.close();
   
    //Prompt for an exam to change and a percentage increase.
    int exam;
    double percent;
    cout << "1. Exam1 2. Exam2 3.Exam3..." << endl;
    cout << "Enter the exam you want to change: ";
    cin >> exam;
    cout << "Enter the percentage increase: ";
    cin >> percent;
    for(int i = 0; i < 4; i++)
        scores[i][exam] *= (1 + percent / 100);
       
    fout.open("revisedGrades.txt");
    createReport(names, scores, fout);
}

And the initialGrades.txt is:

John 90.9 69.9 60.0 220.8 73.6
Jane 87.0 71.0 91.0 249.0 83.0
Bill 95.5 80.7 88.0 264.2 88.1
Susan 75.0 75.1 80.0 230.1 76.7
AverageTestScore 87.1 74.2 79.8 241.0 80.3