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 least5 students and 6 grades each. calculate average grade and letter grade of each and printthem 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;}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
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;}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here