In: Computer Science
Write a program that will calculate numerical and letter grades for a student and output a report:
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
const int SIZE=4;
int i;
const int maxCount = 9;
struct Records {
string firstname;
string secondname;
int homework_grades;
int homework_value[maxCount];
float homework_total_grade;
int program_grades;
int program_values[maxCount];
float program_total_grade;
int exa_ms_grades;
int exa_ms_values[maxCount];
float exa_ms_total_grades;
}record[SIZE];
/* string filename;
ofstream fileC;
cout << "which file do you want to open?";
cin >> filename;
fileC.open(filename.c_str());
*/
ifstream in("STUDENT.txt");
if (!in){
cerr << "File can't be opened! " << endl;
system("PAUSE");
exit(1);
}
for (int i=0; i < SIZE; i++){
in >> record[i].firstname >> record[i].secondname >>record[i].homework_grades;
for(int j=0;j<record[i].homework_grades;j++){
in >> record[i].homework_value[j];
}
in >> record[i].homework_total_grade >> record[i].program_grades;
for(int j=0;j<record[i].program_grades;j++){
in >> record[i].program_values[j];
}
in >> record[i].program_total_grade >> record[i].exa_ms_grades;
for(int j=0;j<record[i].exa_ms_grades;j++){
in >> record[i].exa_ms_values[j];
}
in >> record[i].exa_ms_total_grades ;
}
for (int i=0; i < SIZE; i++){
float homework_earned= 0 ;
float total_homework_point = 0;
float program_earned= 0;
float total_program_point = 0;
float exa_ms_earned = 0;
float total_exa_ms_point = 0;
for(int j=0;j<record[i].homework_grades;j++){
homework_earned += record[i].homework_value[j];
total_homework_point +=100;
}
for(int j=0;j<record[i].program_grades;j++){
program_earned += record[i].program_values[j];
total_program_point +=100;
}
for(int j=0;j<record[i].exa_ms_grades;j++){
exa_ms_earned += record[i].exa_ms_values[j];
total_exa_ms_point +=100;
}
/* cout<<"((total HOMEWORK Points earned/maximum HOMEWORK points) * percent of total grade): "<<homework_earned<<"/"<<total_homework_point<<"*"<<record[i].homework_grades<<"+";
cout<<" (total PROGRAM Points earned/maximum PROGRAM points) * percent of total grade)"<<program_earned<<"/"<<total_program_point<<"*"<<record[i].program_grades<<"+";
cout<<"((exa_ms_earned/total_exa_ms_point)*record[i].exa_ms_grades)"<<exa_ms_earned<<"/"<<total_exa_ms_point<<"*"<<record[i].exa_ms_grades;
*/
float final_grade= (((homework_earned/total_homework_point)*record[i].homework_total_grade)+((program_earned/total_program_point)*record[i].program_total_grade)+((exa_ms_earned/total_exa_ms_point)*record[i].exa_ms_total_grades));
final_grade=final_grade*100;
char letter_grade;
//cout <<"final grades= " << final_grade<<"\n";
if (final_grade>=90 or final_grade<=100){
letter_grade ='A';
}else if (final_grade>=80 or final_grade<=89){
letter_grade='B';
}else if (final_grade>=70 or final_grade<=79){
letter_grade='C';
}else if (final_grade>=60 or final_grade<=69){
letter_grade='D';
}else{
letter_grade='F';
}
switch (letter_grade) {
case 'A':cout <<"Most excellent work"<<"\n";
break;
case 'B':cout<<"good work"<<"\n";
break;
case 'C':cout<<"Average Work"<<"\n";
break;
case 'D' :cout<<"Pass"<<"\n";
break;
default:cout<<"Failed"<<"\n";
break;
}
}
/* for (int i=0;i< SIZE;i++) {
cout << record[i].firstname<<" ";
cout << record[i].secondname<<" ";
cout << record[i].homework_grades<<" ";
for(int j=0;j<record[i].homework_grades;j++){
cout << record[i].homework_value[j] <<" ";
}
cout << record[i].homework_total_grade << " ";
cout << record[i].program_grades << " ";
for(int j=0;j<record[i].program_grades;j++){
cout << record[i].program_values[j]<<" ";
}
cout << record[i].program_total_grade << " ";
cout << record[i].exa_ms_grades << " ";
for(int j=0;j<record[i].exa_ms_grades;j++){
cout << record[i].exa_ms_values[j]<<" ";
}
cout << record[i].exa_ms_total_grades << " "<<"\n";
} */
return 0;
}