Question

Create 4 arrays: a 1-D array to store the students’ id, 1-D array to store the...

Create 4 arrays: a 1-D array to store the students’ id, 1-D array to store the students’ names, a parallel 2-D array to store the test scores, and a parallel 1-D array to store letter grades.
Read data into the 3 arrays from the file data121.txt. If the file is not found, the program needs to terminate with this error, “Data file not found.”
           Calculate and store a letter grade into a 1-D array based on the total score, sum up all scores for each student, for example if the total score is 82, then the grade is a B.
Score   Letter grade
90 ~ 100 A
80 ~ 89   B
70 ~ 79   C
60 ~ 70   D
0 ~ 60   F
Once the data has been read into the arrays, implement the following 3 steps.
Display all students’ names, scores, and their grades,
Calculate and display a student name that received overall maximum points,
Calculate and display the average of all elements in the array test scores,
Generate a new text file report121.txt and save students’ names and grades.

data.121.txt;(id numbers on the left)

3450, Guido VanRossum, 10, 15, 14, 18, 20
6120, Yukihiro Matsumoto, 10, 9, 13, 12, 14
9230, James Gosling, 10, 16, 13, 12, 10
2340, Dennis Ritchie, 11, 15, 14, 18, 11
3180, Kathleen Booth, 9, 11, 14, 18, 12
7800, Bjarne Stroustrup, 18, 20, 20, 19, 20
5410, Rasmus Lerdorf, 10, 12, 14, 18, 20
1590, Larry Wall, 12, 15, 14, 16, 8
2170, Brendan Eich, 20, 15, 14, 18, 20
6530, Ada Lovelace, 10, 5, 14, 8, 10

Using C++ language

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

data121.txt

3450, Guido VanRossum, 10, 15, 14, 18, 20
6120, Yukihiro Matsumoto, 10, 9, 13, 12, 14
9230, James Gosling, 10, 16, 13, 12, 10
2340, Dennis Ritchie, 11, 15, 14, 18, 11
3180, Kathleen Booth, 9, 11, 14, 18, 12
7800, Bjarne Stroustrup, 18, 20, 20, 19, 20
5410, Rasmus Lerdorf, 10, 12, 14, 18, 20
1590, Larry Wall, 12, 15, 14, 16, 8
2170, Brendan Eich, 20, 15, 14, 18, 20
6530, Ada Lovelace, 10, 5, 14, 8, 10

_________________________

#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdlib.h> /* atof */
#include <fstream>
using namespace std;

//Function Declarations
void calLetterGrade(int** scores, char letterGrades[], int count);
void display(int id[], string names[], int** scores, char letterGrades[], int count);
void displayMaxScores(string names[], int** scores, int count);
void displayOverallAverage(int** scores, int count);
void writeToFile(string names[], char letterGrades[], int count);
int main()
{

// Getting the input entered by the user
int count = 0, i = 0;
string name;
double val;

// setting the precision to two decimal places
std::cout << std::setprecision(2) << std::fixed;

// defines an input stream for the data file
ifstream dataIn;

// Opening the input file
dataIn.open("data121.txt");
// checking whether the file name is valid or not
if (dataIn.fail()) {
cout << "** File Not Found **";
return 1;
}
else {
// reading the data from the file
while (getline(dataIn, name)) {
count++;
}
dataIn.close();

// Creating array dynamically
int* id = new int[count];
string* names = new string[count];
// Creating 2-D array Dynamically
int** scores = new int*[count];
for (int i = 0; i < count; ++i)
scores[i] = new int[5];
char letterGrades[count];

// Opening the input file
dataIn.open("data121.txt");
char ch;
string token;
// reading the data from the file and populating into arrays
for (int i = 0; i < count; i++) {
getline(dataIn, name);

stringstream ss(name);

while (getline(ss, token, ',')) {

//cout<<token<<endl;
id[i] = atoi(token.c_str());
getline(ss, token, ',');
//cout<<token<<endl;

names[i] = token;
for (int j = 0; j < 5; j++) {
getline(ss, token, ',');
//cout<<token<<endl;
scores[i][j] = atoi(token.c_str());
}
}
}

dataIn.close();

//calling the functions
calLetterGrade(scores, letterGrades, count);
display(id, names, scores, letterGrades, count);
displayMaxScores(names, scores, count);
displayOverallAverage(scores, count);
writeToFile(names, letterGrades, count);
}

return 0;
}

//This function will calculate the letter grade
void calLetterGrade(int** scores, char letterGrades[], int count)
{
double average, sum = 0;
char gradeLetter;
for (int i = 0; i < count; i++) {
sum = 0;
for (int j = 0; j < 5; j++) {
sum += scores[i][j];
}
average = (sum / 5) * 5;

if (average >= 90)
gradeLetter = 'A';
else if (average >= 80 && average < 90)
gradeLetter = 'B';
else if (average >= 70 && average < 80)
gradeLetter = 'C';
else if (average >= 60 && average < 70)
gradeLetter = 'D';
else if (average < 60)
gradeLetter = 'E';

letterGrades[i] = gradeLetter;
}
}
//This function will display the names,scores,letter grades
void display(int id[], string names[], int** scores, char letterGrades[], int count)
{
for (int i = 0; i < count; i++) {
cout << id[i] << setw(20) << left << names[i] << setw(10) << right;
for (int j = 0; j < 5; j++) {
cout << scores[i][j] << " ";
}
cout << letterGrades[i] << endl;
}
}
//Thus function will calculate and display the over all average of all scores
void displayOverallAverage(int** scores, int count)
{
double sum = 0, avg;
for (int i = 0; i < count; i++) {
for (int j = 0; j < 5; j++) {
sum += scores[i][j];
}
}
avg = sum / (count * 5);
cout << " Overall Average :" << avg << endl;
}

void displayMaxScores(string names[], int** scores, int count)
{
int max;
cout << " Displaying Names and Maximum Scores:" << endl;
cout << "Name Maximum Score" << endl;
cout << "---- -------------" << endl;

for (int i = 0; i < count; i++) {
max = scores[0][0];
for (int j = 0; j < 5; j++) {
if (max < scores[i][j])
max = scores[i][j];
}
cout << setw(20) << left << names[i] << setw(5) << right << max << endl;
}
}
//This function will write the names and grades to the out file
void writeToFile(string names[], char letterGrades[], int count)
{
//Defines an output stream for the data file
ofstream dataOut;
//creating and Opening the output file
dataOut.open("report121.txt");
dataOut << "Name Grade Letter" << endl;
dataOut << "---- ------------" << endl;

for (int i = 0; i < count; i++) {
dataOut << setw(20) << left << names[i] << setw(5) << right << letterGrades[i] << endl;
}
dataOut.close();
}

_______________________

Output:(Console)

______________________

Output file (report121.txt):

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Create 4 arrays: a 1-D array to store the students’ id, 1-D array to store the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • codeblock c++ language Write a program that reads students test scores in the range 0-200 from...

    codeblock c++ language Write a program that reads students test scores in the range 0-200 from a file until end of file (use e of() to check if ifstream reaches the End of File Stream) and store those scores in an array. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100- 124, 125–149, 150-174, and 175–200. Finally, the program outputs the total number of students, each score range...

  • Student average array program

    Having a bit of trouble in my c++ class, was wondering if anyone can help.Write a program to calculate students' average test scores and their grades. You may assume the following input data:Johnson 85 83 77 91 76Aniston 80 90 95 93 48Cooper 78 81 11 90 73Gupta 92 83 30 68 87Blair 23 45 96 38 59Clark 60 85 45 39 67Kennedy 77 31 52 74 83Bronson 93 94 89 77 97Sunny 79 85 28 93 82Smith 85 72...

  • C++ Write a program to calculate final grade in this class, for the scores given below...

    C++ Write a program to calculate final grade in this class, for the scores given below . Remember to exclude one lowest quiz score out of the 4 while initializing the array. Display final numeric score and letter grade. Use standard include <iostream> Implementation: Use arrays for quizzes, labs, projects and exams. Follow Sample Output for formatting. May use initialization lists for arrays. Weight distribution is as follows: Labs: 15% Projects: 20% Quizzes: 20% Exams: 25% Final Project: 20% Display...

  • java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array...

    java: 1d arrays PLEASE NEED HELp THANK YOU!!! One dimensional (1D) array 1. Create an array of 1000 integers. Name the array: x 2. Assign 95 to the ninth element, 25 to the twentieth element of array x. 3. Assign the sum of the ninth and the twentieth element to the sixtieth element of array x. 4. Display the sixtieth element of the array. 5. Use the for statement to generate all indexes to read and display all elements in...

  • C++ Use C++ functions and build a program that does the most basic job all students...

    C++ Use C++ functions and build a program that does the most basic job all students have to contend with, process the grades on a test and produce a summary of the results. The big wrinkle is, it should be a multi-file program. -Requires three simple things: Figure out the best score of all scores produced Figure out the worst score of all scores produced Assign a letter grade for each score produced Complete this lab by writing three functions....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT