Problem: Write a C++ program that will compute the final average and assign a le
ID: 3665506 • Letter: P
Question
Problem: Write a C++ program that will compute the final average and assign a letter grade for the students in a class. Input: The input file named "class_scores.bxt" will have the following format: one line for each student containing the following, separated by at least one space: student ID 5 exam scores 1 participation score 4 assignment scores example: A00123456 95 88 84 77 0 50 10 7 8 10 Assume the following (you do not need to validate these things): The student ID wll not contain any spaces. Each score is an integer. There is no missing data. The data follows the format described above There will be no more than 50 students (but at least 1). See the website for a sample input data file. Note: the input file may have blank lines at the end. Your program should ignore them. Output: Write the output to an output file named "final grades.bxt" The program should output the student ID, the total points (computed according to the instructions below), the percent grade formatted to 1 decimal place and the letter grade (computed according to the grading scale below) for each student.Explanation / Answer
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void calcAvg(ifstream& in_file, ofstream& out_file, float& avg);
char calc_grade(float avg);
int main() {
ifstream inp;
ofstream outp;
inp.open("Ch07_Ex09Date.txt");
outp.open("Ch07_Ex09OUT.txt");
outp << "Student Test1 Test2 Test3 Test4 Test5 Average Grade";
string name;
float classAvg = 0;
char grade;
int k;
float avg;
for (k=1; k<=10; k++)
{
inp >> name;
outp << setw(10) << name;
calcAvg(inp, outp, avg);
outp << setw(6) << avg;
classAvg = classAvg + avg;
grade = calc_grade(avg);
outp << setw(5) << " " << grade << endl;
}
classAvg = classAvg / 10;
outp << endl << "Class Average = " << classAvg;
return 0;
}
void calcAvg(ifstream& inp, ofstream& outp, float& avg)
{
int score, k;
float sum = 0.0;
for (k=1; k<=5; k++)
{
inp >> score;
outp << setw(4) << score << " ";
sum = sum + score;
}
avg = sum / 5;
}
char calc_grade(float total)
{
char grade;
if (total >= 0)
if (total >= 60)
if (total >= 70)
if (total >= 80)
if (total >= 90)
if (total > 100)
cout << "Grade can not exceed 100" << endl;
else
grade = 'A';
else
grade = 'B';
else
grade = 'C';
else
grade = 'D';
else
grade = 'E';
else
grade = 'F';
return grade;
}
// it might be usefull to you chek it out
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.