In: Computer Science
C++ Visual Studio 2019
Part A :
Program Description:
Write a program to generate a report based on input received from a text file. Suppose the input text file student_grades.txt contains the student’s Last name , First name, SSN, Test1, Test2, Test3 and Test4. (25%)
i.e.
Alfalfa Aloysius 123-45-6789 40.0 90.0 100.0 83.0
Generate the output Report File student_final.txt in the following format :
LastName FirstName SSN Test1 Test2 Test3 Test4 Average FinalGrade
i.e.
Alfalfa Aloysius 123-45-6789 40.0 90.0 100.0 83.0 78.25 .0 C+
The program must be written to use the enum letterGrade :
enum letterGrade {A_PLUS,A, A_MINUS,B_PLUS,B, B_MINUS, C_PLUS,C, C_MINUS,D_PLUS,D, D_MINUS,F } ;
Use the following function prototype for deriving letter grade :
letterGrade deriveGrade(double average) ;
The average is calculated as follows : (test1 + test2 + test3 + test4)/4.0
The function deriveGrade should derive the letterGrade of the student based on the following grading scale :
Letter Grade |
Percentage |
GPA |
A+ |
97%+ |
4.33/4.00 or 4.00/4.00 |
A |
93%-96% |
4.00/4.00 |
A- |
90%-92% |
3.67/4.00 |
B+ |
87%-89% |
3.33/4.00 |
B |
83%-86% |
3.00/4.00 |
B- |
80%-82% |
2.67/4.00 |
C+ |
77%-79% |
2.33/4.00 |
C |
73%-76% |
2.00/4.00 |
C- |
70%-72% |
1.67/4.00 |
D+ |
67%-69% |
1.33/4.00 |
D |
63%-66% |
1.00/4.00 |
D- |
60%-62% |
0.67/4.00 |
F |
0%-59% |
0.00/4.00 |
Also provide the following function :
string convertToText(letterGrade grade) ; //This function converts a letterGrade type to a string type.
Requirement :
Input text file student_grades.txt
Alfalfa Aloysius 123-45-6789 90.0 100.0 83.0 49.0 Alfred Francis 123-12-1234 97.0 96.0 97.0 48.0 Gerty Gramma 567-89-0123 80.0 60.0 40.0 44.0 Android Alexis 087-65-4321 23.0 36.0 45.0 47.0 Bumpkin Fred 456-78-9012 78.0 88.0 77.0 45.0 Rubble Betty 234-56-7890 90.0 80.0 90.0 46.0 Noshow Cecil 345-67-8901 81.0 65.0 49.0 43.0 Buff Bif 632-79-9939 20.0 30.0 40.0 50.0 Airpump Andrew 223-45-6789 75.0 90.0 100.0 83.0 Backus Jim 143-12-1234 85.0 97.0 96.0 97.0 Carnivore Art 565-89-0123 71.0 80.0 60.0 40.0 Dandy Jim 087-75-4321 92.0 23.0 36.0 45.0 Elephant Ima 456-71-9012 19.0 78.0 88.0 77.0 Franklin Benny 234-56-2890 50.0 90.0 80.0 90.0 George Boy 345-67-3901 40.0 11.0 91.0 84.0 Heffalump Harvey 632-79-9439 30.0 91.0 20.0 30.0
C++ Code:-
grade.hpp
namespace stdGrade{
enum letter_grade {A, A_PLUS, A_MINUS, B,B_PLUS, B_MINUS, C, C_PLUS, C_MINUS,D,D_PLUS,D_MINUS,F } ;
letter_grade deriveGrade(double average)
{
if(average>=97)
{
return A_PLUS;
}
else if(average>=93)
{
return A;
}
else if(average>=90)
{
return A_MINUS;
}
else if(average>=87)
{
return B_PLUS;
}
else if(average>=83)
{
return B;
}
else if(average>=80)
{
return B_MINUS;
}
else if(average>=77)
{
return C_PLUS;
}
else if(average>=73)
{
return C;
}
else if(average>=70)
{
return C_MINUS;
}
else if(average>=67)
{
return D_PLUS;
}
else if(average>=63)
{
return D;
}
else if(average>=60)
{
return D_MINUS;
}
else{
return F;
}
}
}
studentGrade.cpp
#include<iostream>
#include<fstream>
using namespace std;
#include "grade.hpp"
using namespace stdGrade;
string convertToText(letter_grade grade)
{
if(grade==A_PLUS)
return "A+";
else if(grade==A)
return "A";
else if(grade==A_MINUS)
return "A-";
else if(grade==B_PLUS)
return "B+";
else if(grade==B)
return "B";
else if(grade==B_MINUS)
return "B-";
else if(grade==C_PLUS)
return "C+";
else if(grade==C)
return "C";
else if(grade==C_MINUS)
return "C-";
else if(grade==D_PLUS)
return "D+";
else if(grade==D)
return "D";
else if(grade==D_MINUS)
return "D-";
else
return "F";
}
int main()
{
ifstream input;
input.open("student_grades.txt");
ofstream output;
output.open("student_final.txt");
string lname, fname, ssn, grd;
double t1, t2, t3, t4;
double average;
while(!input.eof())
{
input>>lname>>fname>>ssn;
input>>t1>>t2>>t3>>t4;
average=(t1+t2+t3+t4)/4;
letter_grade grade=deriveGrade(average);
grd=convertToText(grade);
//output to file
output<<lname<<" "<<fname<<" "<<ssn<<" "<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<" "<<average<<" "<<grd<<endl;
}
//print a success message
cout<<"Successfully written to output file!"<<endl;
cin.get();
return 0;
}
ScreenShot:-
studentGrade.cpp
grade.hpp (please save this file as grade.hpp)
Output:-
Input File:-
Thank You....!!!!
For any query, please comment.
If you are satisfied with the above answer, then please thumbs up
or upvote the answer.