I need assistance fixing a program written in C++. It is supposed to open a file called "students.txt," which contains the name of 5 students, who each have 6 grade scores. It extracts the information from the file to create averages for each student. Each student is assigned a letter grade based on their averages. The student's name, letter grade, and average score is supposed to be written onto a new file called "studentsresults.txt" and displayed on the output monitor with cout. However when I run the program, I get weird values in both the created file and the output monitor, as seen in the image below. I wanted to know what is the issue and how to fix it.   Here's the program: /* write a program to open a data file called "student.txt" which contains name of at least 5 students and 6 grades each. calculate average grade and letter grade of each and print them into file.(to another file)*/ #include #include using namespace std; int main() { ifstream in_stream; ofstream out_stream; char student_name[5][20]; int test_grades[6]; int i; int j; double average_grade = 0.0; char letter_grade; double total = 0.0; in_stream.open("students.txt"); out_stream.open("studentresults.txt"); for (i = 0; i < 5; i++) { in_stream >> student_name[i]; cout << i << " " << student_name[i] << endl; for (j = 0; j < 6; j++) { in_stream >> test_grades[j]; cout << i << " " << j << " " << test_grades[j] << endl; average_grade = test_grades[j] + average_grade; } average_grade = average_grade / 6; if (average_grade >= 90) { letter_grade = 'A'; } else if (average_grade >= 80) { letter_grade = 'B'; } else if (average_grade >= 70) { letter_grade = 'C'; } else if (average_grade >= 60) { letter_grade = 'D'; } else { letter_grade = 'F'; } cout << "Student: " << student_name[i] << "\tLetter Grade : " << letter_grade << "\tAverage grade:"; cout << average_grade << endl; out_stream << "Student: " << student_name << "\tLetter Grade : " << letter_grade << "\tAverage: " << average_grade << endl; } in_stream.close(); out_stream.close(); return 0; }

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
Topic Video
Question
100%

I need assistance fixing a program written in C++. It is supposed to open a file called "students.txt," which contains the name of 5 students, who each have 6 grade scores. It extracts the information from the file to create averages for each student. Each student is assigned a letter grade based on their averages.

The student's name, letter grade, and average score is supposed to be written onto a new file called "studentsresults.txt" and displayed on the output monitor with cout.

However when I run the program, I get weird values in both the created file and the output monitor, as seen in the image below. I wanted to know what is the issue and how to fix it.

 

Here's the program:

/*
write a program to open a data file called "student.txt" which contains name of at least
5 students and 6 grades each. calculate average grade and letter grade of each and print
them into file.(to another file)*/

#include <iostream>
#include <fstream>

using namespace std;
int main()
{
ifstream in_stream;
ofstream out_stream;

char student_name[5][20];
int test_grades[6];
int i;
int j;
double average_grade = 0.0;
char letter_grade;
double total = 0.0;

in_stream.open("students.txt");
out_stream.open("studentresults.txt");


for (i = 0; i < 5; i++)
{
in_stream >> student_name[i];
cout << i << " " << student_name[i] << endl;
for (j = 0; j < 6; j++)
{
in_stream >> test_grades[j];
cout << i << " " << j << " " << test_grades[j] << endl;
average_grade = test_grades[j] + average_grade;


}
average_grade = average_grade / 6;


if (average_grade >= 90)
{
letter_grade = 'A';
}
else if (average_grade >= 80)
{
letter_grade = 'B';
}
else if (average_grade >= 70)
{
letter_grade = 'C';
}
else if (average_grade >= 60)
{
letter_grade = 'D';
}
else
{
letter_grade = 'F';
}

cout << "Student: " << student_name[i] << "\tLetter Grade : " << letter_grade << "\tAverage grade:";
cout << average_grade << endl;

out_stream << "Student: " << student_name << "\tLetter Grade : " << letter_grade << "\tAverage: " << average_grade << endl;
}
in_stream.close();
out_stream.close();

return 0;
}

O studentresults - Notepad
CA Microsoft Visual Studio Debug Console
File Edit Format View Help
2
4
-858993460
Average: -8.58993e+08 A 2
Average: -1.00216e+09
Average: -1.02602e+09
Average: -1.03e+09
Average: -1.03066e+09
Student: 00D9FBE8
Letter Grade : F
Letter Grade : F
Letter Grade : F
Letter Grade : F
Letter Grade : F
5
-858993460
Student: 00D9FBE8
Student:
Letter Grade : F
Average grade: -1.02602e+09
Student: 00D9FBE8
-858993460
Student: 00D9FBE8
1.
-858993460
Student: 00D9FBE8
2
-858993460
3
3
3
3
-858993460
4
-858993460
5
-858993460
Student:
Letter Grade : F
Average grade:-1.03e+09
4
-858993460
-858993460
2
-858993460
3
-858993460
4
4
-858993460
4
5
-858993460
Student:
Letter Grade : F
Average grade: -1.03066e+09
Transcribed Image Text:O studentresults - Notepad CA Microsoft Visual Studio Debug Console File Edit Format View Help 2 4 -858993460 Average: -8.58993e+08 A 2 Average: -1.00216e+09 Average: -1.02602e+09 Average: -1.03e+09 Average: -1.03066e+09 Student: 00D9FBE8 Letter Grade : F Letter Grade : F Letter Grade : F Letter Grade : F Letter Grade : F 5 -858993460 Student: 00D9FBE8 Student: Letter Grade : F Average grade: -1.02602e+09 Student: 00D9FBE8 -858993460 Student: 00D9FBE8 1. -858993460 Student: 00D9FBE8 2 -858993460 3 3 3 3 -858993460 4 -858993460 5 -858993460 Student: Letter Grade : F Average grade:-1.03e+09 4 -858993460 -858993460 2 -858993460 3 -858993460 4 4 -858993460 4 5 -858993460 Student: Letter Grade : F Average grade: -1.03066e+09
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Instruction Format
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
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