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
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
Related questions
Question
100%
In
(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.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education