(it is a C++ progrm no java thanks) Write a C++ program that determines the lett
ID: 3764837 • Letter: #
Question
(it is a C++ progrm no java thanks) Write a C++ program that determines the letter grade each student in a class receives. The program should read the list of student names, first exam scores, midterm exam scores, and final exam scores from a file. The final grade is determined by taking 20% of the first exam, 30% of the midterm exam, and 50% of the final exam. The program should print to the screen the student’s name and the letter grade they should receive for the course. Use a value-returning function to determine the letter grade. Letter Grades should be determined according to the following: Grading Scale: 100 – 90%……….A 89 - 80%……….B 79 - 70%……….C
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main () {
string name,grd;
int var1,var2,var3;
double fe,me,fie;
ifstream myfile ("marks.txt");
if (myfile.is_open())
{
while ( !myfile.eof() )
{
getline (myfile,name,' ');
getline (myfile,var1,' ');
getline (myfile,var2,' ');
getline (myfile,var3,' ');
fe=var1*20/100;
me=var2*30/100;
fie=var3*50/100;
tot=fe+me+fie;
if(tot>=90 && tot<=100)
{
cout<<name<<" "<<"A";
}
else if(tot>=89 && tot <=80)
{
cout<<name<<" "<<"B";
}
else if(tot>=79 && tot <=70)
{
cout<<name<<" "<<"C";
}
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.