
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
thumb_up100%
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.

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

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 nowThis is a popular solution!
Step by stepSolved 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.Similar questions
- Write the following program in c++.Combine your first and second name and pick only the first five characters of your name for the project.i. Declare an array named name1 and put all the first five characters into it.ii. Write a for loop with an if condition that will find and output the index value of a searched character in the array. Let the program be such that the user will input the character being searched for.arrow_forwardWrite a C++ program that will read monthly sales into a dynamically allocated array. The program will input the size of the array from the user (must be less than or equal to 12). It will call a function that will find the sum of all sales. It will also call a function to find the average. It will also call a function to sort the array using either a bubble or selection sort in descending order and then display the results. You must have a comment block header at the top of your program. See the Standards document in Course Content You must use pointers for your arrays and dynamically allocate them based on the number of month You must remove and reset the array when completed You must use the correct data types for your variables You must validate your input. The number of months must be between 1 and 12 You must use a loop to read in the sales You must use at least 3 functions to calculate the average, sort the array and display the sales Your output should be…arrow_forwardWrite a C++ program that uses a 1D array to store 25 students' computer programming grades (total grade 100). The program should not accept incorrect or invalid grades, and the user should be able to enter marks one at a time. Once the user has completed the entry, the program should output the following. a) Maximum grade b) The average grade (sum of all grades/total number of students) c) Minimum grade Write the C++ code in the space provided (Full marks are awarded for a complete solution.)arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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