In Programming Exercise 13 (Chapter 8), you are asked to write a program to calculate students’ average test scores and their grades. Improve this programming exercise by adding a function to sort students’ names so that students’ data is output into ascending order according to their name

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In Programming Exercise 13 (Chapter 8), you are asked to write a program to calculate students’ average test scores and their grades. Improve this programming exercise by adding a function to sort students’ names so that students’ data is output into ascending order according to their name.

 

(data.txt)

Johnson 85 83 77 91 76

Cooper 78 81 11 90 73

Gupta 92 83 30 69 87

Blair 23 45 96 38 59

Clark 60 85 45 39 67

Kennedy 77 31 52 74 83

Bronson 93 94 89 77 97

Sunny 79 85 28 93 82

Smith 85 72 49 75 63

Aniston 80 90 95 93 48

 

(Program to Improve)

    
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

void getData(ifstream& inf, string n[], double tstData[][6], int count);
void calculateAverage(double tstData[][6], int count);
void calculateGrade(double tstData[][6], char gr[], int count);
void print(string n[], double tstData[][6], char gr[], int count);
  
int main()
{
  string names[10];
    double testData[10][6];
    char grade[10];

    ifstream inFile;

    inFile.open("data.txt");

    if (!inFile)
    {
        cout << "Cannot open the input file: ch8_Ex13Data.txt." << endl;
        cout << "Program terminates!" << endl;
        return 1;
    }

    cout << fixed << showpoint << setprecision(2);

    getData(inFile, names, testData, 10);
    calculateAverage(testData, 10);
    calculateGrade(testData, grade, 10);
    print(names, testData, grade, 10);

    inFile.close();

  return 0;
}

void getData(ifstream& inf, string n[], double tstData[][6], int count)
{
    for (int i = 0; i < count; i++)
    {
        inf >> n[i];
        
        for (int j = 0; j < 5; j++)
            inf >> tstData[i][j];

        tstData[i][5] = 0.0;
    }
}

void calculateAverage(double tstData[][6], int count)
    double sum;

    for (int i = 0; i < count; i++)
    {
        sum = 0.0;
        for (int j = 0; j < 5; j++)
            sum = sum + tstData[i][j];
        tstData[i][5] = sum / 5;
    }
}

void calculateGrade(double tstData[][6], char gr[], int count)
{
    for (int i = 0; i < count; i++)
        if (tstData[i][5] >= 90)
            gr[i] = 'A';
        else if (tstData[i][5] >= 80)
            gr[i] = 'B';
        else if (tstData[i][5] >= 70)
            gr[i] = 'C';
        else if (tstData[i][5] >= 60)
            gr[i] = 'D';
        else 
            gr[i] = 'F';
}

void print(string n[], double tstData[][6], char gr[], int count)
{
    double sum = 0.0;

    cout << left << setw(10) << "Name"
         << right << setw(8) << "Test 1"
         << setw(8) << "Test 2"
         << setw(8) << "Test 3"
         << setw(8) << "Test 4"
         << setw(8) << "Test 5"
         << setw(10) << "Average"
         << setw(8) << "Grade" << endl;

    for (int i = 0; i < count; i++)
    {
        cout << left << setw(10) << n[i];
        cout << right;

        for (int j = 0; j < 5; j++)
            cout << setw(8) << tstData[i][j];

        cout << setw(10) << tstData[i][5]
             << setw(6) << gr[i] << endl;
        sum = sum + tstData[i][5];
    }

    cout << endl << endl;
    cout << "Class average: " << sum / count << endl;
}
 
 
The Output must match all data below, say for the exception that it must be sorted. The last answer I received was less than satisfactory.
 
Name
Test 1 Test 2 Test 3 Test 4 Test 5
Average
Grade
Johnson
85.00
83.00
77.00
91.00
76.00
82.40
Сооper
Gupta
78.00
81.00
11.00
90.00
73.00
66.60
92.00
83.00
30.00
69.00
87.00
72.20
Blair
23.00
45.00
96.00
38.00
59.00
52.20
F
Clark
60.00
85.00
45.00
39.00
67.00
59.20
F
Kennedy
77.00
31.00
52.00
74.00
83.00
63.40
Bronson
93.00
94.00
89.00
77.00
97.00
90.00
A
Sunny
79.00
85.00
28.00
93.00
82.00
73.40
C
Smith
85.00
72.00
49.00
75.00
63.00
68.80
Aniston
80.00
90.00
95.00
93.00
48.00
81.20
Class average: 70.94
Transcribed Image Text:Name Test 1 Test 2 Test 3 Test 4 Test 5 Average Grade Johnson 85.00 83.00 77.00 91.00 76.00 82.40 Сооper Gupta 78.00 81.00 11.00 90.00 73.00 66.60 92.00 83.00 30.00 69.00 87.00 72.20 Blair 23.00 45.00 96.00 38.00 59.00 52.20 F Clark 60.00 85.00 45.00 39.00 67.00 59.20 F Kennedy 77.00 31.00 52.00 74.00 83.00 63.40 Bronson 93.00 94.00 89.00 77.00 97.00 90.00 A Sunny 79.00 85.00 28.00 93.00 82.00 73.40 C Smith 85.00 72.00 49.00 75.00 63.00 68.80 Aniston 80.00 90.00 95.00 93.00 48.00 81.20 Class average: 70.94
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education