Deliverable: This program will be design to read students first name and last na
ID: 3688355 • Letter: D
Question
Deliverable: 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 road 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 tile 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 Name 1 of 75 80 80 95 87 Student Name 2 78 85 89 85 56 Student Name 3 78 85 85 96 74 Student Name 4 78 85 97 85 89 This lab is due at the end lab on 4/18. For full credit the lab must include the following: Read information from a file called students Output to a file called finalgrades 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 students 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>
#include <string>
using namespace std;
int main () {
string line,first[50],last[50];
char ch;
int exam1[50],exam2[50],exam3[50],exam4[50],final[50],k,i=0,tot[50];
double per=0;
//open inpur and output text files
ifstream myfile ("students.txt");
ofstream file2("finalgrades.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
//store values into arays
//write data to output file
getline (myfile,first[i],' ');
file2 << first[i];
file2 << " ";
getline (myfile,last[i],' ');
file2 << last[i];
file2 << " ";
getline (myfile,exam1[i],' ');
file2 << exam1[i];
file2 << " ";
getline (myfile,exam2[i],' ');
file2 << exam2[i];
file2 << " ";
getline (myfile,exam3[i],' ');
file2 << exam3[i];
file2 << " ";
getline (myfile,exam4[i],' ');
file2 << exam4[i];
file2 << " ";
getline (myfile,final[i],' ');
file2 << final[i];
file2 << " ";
i++;
}
k=i;
//close input file
myfile.close();
}
else cout << "Unable to open file";
//calculate grades and write to file
for(i=0;i<k;i++)
{
tot[i] = 0.15*exam1[i] + 0.15*exam2[i] + 0.15*exam3[i] + 0.15*exam4[i] + 0.4*final[i];
file2 << first[i] << " ";
file2 << tot[i] << " ";
per = tot[i]/100;
if(per>0.9 && per< 1)
file2 << 'A';
else if(per > 0.8 && per< 0.89)
file2 << 'B';
else if(per>0.7 && per < 0.79)
file2 << 'C';
else if(per > 0.6 && per < 0.69)
file2 << 'D';
else
file2 << 'F';
file2<< ' ';
}
//write to file the number of students
file2 << "number of students: " << k;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.