In: Computer Science
There will be three grades for each student in "grades.txt" (see example file bellow). In "student.txt" there are two students first and last names. In "grades.txt" the grades for each student will be on the same line number as the students name was on in "students.txt".
So if line 1 of "students.txt" contains:
Joe Blow
then line 1 of "grades.txt" would contain Joe Blow's grades:
85 54.3 56
Into an output file called "report.txt" output the student's last name then a comma the their first name. Following this, calculate their average and assign a letter grade using the following scale:
'A': grade >= 90
'B': 90 > grade >= 80
'C': 80 > grade >= 70
'D': 70 > grade >= 60
'F': grade < 60
If the final grade of a student is greater than 100 instead of printing their letter grade output the statement "Teacher was far too easy". The "report.txt" should have a heading on each of the columns the first saying "Student's Name" and the second saying "Student's Grade".
//C++ program
#include<iostream>
#include<fstream>
using namespace std;
char findLetterGrade(double marks){
if(marks>=90)return 'A';
if(marks>=80)return 'B';
if(marks>=70)return 'C';
if(marks>=60)return 'D';
return 'F';
}
int main(){
ifstream in1,in2;
ofstream out;
string firstName,lastName;
int grade1,grade2,grade3;
double average;
char letterGrade;
in1.open("students.txt");
in2.open("grades.txt");
out.open("report.txt");
if(!in1){
cout<<"grades file not
opened\n";
return 0;
}
if(!in2){
cout<<"students file not
opened\n";
return 0;
}
if(!out){
cout<<"report file not
opened\n";
return 0;
}
out<<"Student's Name\tStudent's Grade\n";
while(!in1.eof() && !in2.eof()){
in1>>firstName>>lastName;
in2>>grade1>>grade2>>grade3;
average =
(double)(grade1+grade2+grade3)/3;
letterGrade =
findLetterGrade(average);
out<<lastName<<","<<firstName<<"\t\t";
if(average<=100)out<<letterGrade<<"\n";
else out<<"Teacher was far
too easy\n";
}
in1.close();
in2.close();
out.close();
return 0;
}