This program will be design to read students first name and last name along with
ID: 3691169 • Letter: T
Question
This program will be design to read students first name and last name along with the scores for exam 1, exam 2, exam 3, exam 4, and a final exam and calculate the student's final grade. The student's information will be read from a file called students and the output of the program should be to an output file called finalgrades and the grades should be arranged in the descending order. The program needs to load the student's information to an array associating the students name and scores together. Read the students information using the end of file command since we do not know how long the list will be. The output file should include the student names, exam scores, final score, final grade (A-F), grade percentage, and pass or fail, and the total number of students in the class. The input file should be formatted as follows: Student Name1 75 80 80 95 87 Student Name 2 78 85 89 85 56 Student Name3 78 85 85 96 74 Student Name4 78 85 97 85 89 This lab is doe af the end tab on 4/18. For full credit the lab must include the following: Read information from a file called students Output to a file called fianlgrades in descending order The program must use arrays to load the information of the students End of file command to scan the information from the studonts file Number of students in the class Good report appearance Use the following scale to assign grades: 100% - 90%: A 89%-80%: B 79%-70%: C 69%-60%: D 59%Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
struct Student{
string firstName;
string lastName;
int exam1,exam2,exam3,exam4,finalexam;
int finalGrade;
};
int main(){
struct Student st[4];
ifstream myfile;
int i=0;
myfile.open("students.txt",ios::in);
ofstream ofs ("finalgrades.txt", std::ofstream::out);
while(!myfile.eof()){
myfile>>st[i].firstName;
myfile>>st[i].lastName;
myfile>>st[i].exam1;
myfile>>st[i].exam2;
myfile>>st[i].exam3;
myfile>>st[i].exam4;
myfile>>st[i].finalexam;
st[i].finalGrade=(0.15*st[i].exam1+0.15*st[i].exam2+0.15*st[i].exam3+0.15*st[i].exam4+0.4*st[i].finalexam);
cout<<st[i].finalGrade<<endl;
i++;
if(i==4)
break;
}
for(int i=0;i<4;i++){
ofs<<st[i].finalGrade<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.