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...


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;="">
{
in_stream >> student_name[i];
cout < i="">< "="" "="">< student_name[i]=""><>
for (j = 0; j < 6;="">
{
in_stream >> test_grades[j];
cout < i="">< "="" "="">< j="">< "="" "="">< test_grades[j]=""><>
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="">
cout < average_grade=""><>


out_stream < "student:="" "="">< student_name="">< "\tletter="" grade="" :="" "="">< letter_grade="">< "\taverage:="" "="">< average_grade=""><>
}
in_stream.close();
out_stream.close();


return 0;
}


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

Extracted 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
Jun 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here