In: Computer Science
Sherlock Holmes 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70 0.45
The student, Sherlock Holmes, has three homework grades, each with a value of 100. Homework is 15% of total grade. He has three program grades with values of 75, 80, 90. Program is 40% of grade. He has three exa-ms grades of 60, 70, 70. Exa-ms are 45% of grade.
((total HOMEWORK Points earned/maximum HOMEWORK points) * percent of total grade) + (total PROGRAM Points earned/maximum PROGRAM points) * percent of total grade) + (total EX-AM Points earned/maximum EX-AM points) * percent of total grade)) * 100
90 - 100 = A
80 - 89 = B
70 - 79 = C
60 - 69 = D
< 60 = F
A = "Most excellent work”
B = "IMHO You Passed"
etc.
Student Name, Total Points (numerical grade): NN. Letter Grade: X. Depending on letter grade, The witty comment.
The name of your C++ file
Your name
Some kind of date, either the due date or the date you finished
The type of input
The type of output
A brief description of the algorithm/program
Watch for 1-off errors; truncated grade values; infinite loops
Turn in file code *.cpp; README file; input file (even though provided) and ALL output files. You DO NOT need to submit the executable (*.exe). You MAY zip all the files and submit if you choose. You MUST include all the files indicated or points will be deducted.
README must contain instructions for location of input/output files
STUDENT .TXT
Sherlock Holmes 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70
0.45
Constant Success 4 100 88 100 92 0.15 3 75 80 90 0.40 2 100 89
0.45
Happy Grant 3 79 82 77 0.15 3 80 82 93 0.40 3 86 90 76 0.45
Reach Further 3 100 99 98 0.15 3 98 97 93 0.40 3 88 90 99 0.45
// C++ program to read student grades from input file and
calculate and output the numerical and letter grade to console and
output file
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string in_filename, out_filename;
ifstream fin;
ofstream fout;
// read input filename
cout<<"Enter the input filename: ";
cin>>in_filename;
fin.open(in_filename); // open input file
// check if input file opened successfully
if(fin.fail())
{
cout<<"Unable to open input file:
"<<in_filename<<". Exiting
application"<<endl;
return 1;
}
// read output filename
cout<<"Enter the output filename: ";
cin>>out_filename;
fout.open(out_filename); // create and open output file
// check if output file opened successfully
if(fout.fail())
{
cout<<"Unable to open output file:
"<<out_filename<<". Exiting
application"<<endl;
return 1;
}
string fName, lName;
int numHW, numProgram, numExam;
double totalHW = 0, totalProgram = 0, totalExam = 0;
double weightHw, weightProgram, weightExam;
double grade;
double avgGrade;
char letterGrade;
string comment;
// loop to read till the end of input file
while(!fin.eof())
{
// reset total grades for homework, program and totalExam to
0
totalHW = totalProgram = totalExam = 0;
// read first name and last name and number of homework
grades
fin>>fName>>lName>>numHW;
// loop to homework grades and calculate total homework
grades
for(int i=0;i<numHW;i++)
{
fin>>grade;
totalHW += grade;
}
// read the homework percent and number of program grades
fin>>weightHw>>numProgram;
// loop to program grades and calculate total program
grades
for(int i=0;i<numProgram;i++)
{
fin>>grade;
totalProgram += grade;
}
// read the program percent and number of exam_grades
fin>>weightProgram>>numExam;
// loop to _exam grades and calculate totalExam grades
for(int i=0;i<numExam;i++)
{
fin>>grade;
totalExam += grade;
}
fin>>weightExam; // read the examPercent
// calculate the average grade
avgGrade = (((totalHW/(100*numHW))*weightHw) +
((totalProgram/(100*numProgram))*weightProgram) +
((totalExam/(numExam*100))*weightExam))*100;
// based on average grade determine letter grade and
comment
if(avgGrade >= 90){
letterGrade = 'A';
comment = "Most excellent work";
}
else if(avgGrade >= 80){
letterGrade = 'B';
comment = "IMHO You Passed";
}
else if(avgGrade >= 70){
letterGrade = 'C';
comment = "Work hard";
}
else if(avgGrade >= 60){
letterGrade = 'D';
comment = "Just passed";
}
else{
letterGrade = 'F';
comment = "Failed";
}
// output the result to console and output file
cout<<fixed<<setprecision(2);
fout<<fixed<<setprecision(2);
cout<<endl<<fName<<" "<<lName<<"
Total Points (numerical grade): "<<avgGrade<<" Letter
Grade: "<<letterGrade<<" "<<comment;
fout<<fName<<" "<<lName<<" Total Points
(numerical grade): "<<avgGrade<<" Letter Grade:
"<<letterGrade<<" "<<comment<<endl;
}
cout<<endl;
// close the input and output files
fin.close();
fout.close();
return 0;
}
//end of program
Output:
Input file: studentGrades.txt
Console:
Output file: