How to modify this code to read the grades from a local file called "mygrades.txt"
#include
#include
using namespace std;
class Grade{
public:
void getExercises();
void getClickers();
void getLabs();
void getTraces();
void getAssignments();
void getTests();
void getPrefinal();
void getFinal();
void displayTotals();
private:
int total = 0;
int Recieve =0;
};
void Grade::getExercises(){
int grade = 0;
int counter = 1;
int adder = 0;
int total = 0;
cout <<"GRADE CALCULATION"<< endl;
do{
cout <<"Enter textbook exercise #"<< counter << " (out of 10 points): ";
cin >> grade;
counter++;
if(grade == -1){
break;
}
else{
adder += grade;
total += 10;
}
}while(counter != 13);
cout << adder <<" out of " << total <<" points for textbook grade" << endl << endl;
Recieve += adder;
this -> total += total;
}
void Grade::getClickers(){
int grade =0;
int i = 0;
string months[4]= {"January", "February", "March", "April"};
int adder = 0;
int total = 0;
do{
cout <<"Enter clicker grade for "<< months[i] << " (out of 30 points): ";
cin >> grade;
i++;
if(grade == -1){
break;
}
else{
adder += grade;
total += 30;
}
}while(i != 5);
cout << adder <<" out of " << total <<" points for clicker grade" << endl << endl;
Recieve += adder;
this -> total += total;
}
void Grade::getLabs(){
int grade = 0;
int counter = 1;
int adder = 0;
int total = 0;
int points = 25;
do{
if (counter == 5){
cout <<"Enter Lab " << counter <<" grade (out of 20 points extra credit): ";
}
else{
cout <<"Enter Lab "<< counter << " grade (out of "<
}
cin >> grade;
counter++;
if(grade == -1){
break;
}
else{
adder += grade;
if(counter == 5){
}
else{
total += points;
}
}
points += 10;
if ( counter >= 4){
points = 45;
}
}while((counter != 8) && (grade !=-1));
cout << adder <<" out of " << total <<" points for lab grade" << endl << endl;
Recieve += adder;
this -> total += total;
}
void Grade::getTraces(){
int grade = 0;
int counter = 1;
int adder = 0;
int total = 0;
do{
cout <<"Enter Trace "<< counter<<" grade (out of 2 points): ";
cin >> grade;
counter++;
if(grade == -1){
break;
}
else{
adder += grade;
total += 2;
}
}while(counter != 13);
cout << adder <<" out of " << total <<" points for trace grade" << endl << endl;
Recieve += adder;
this -> total += total;
}
void Grade::getAssignments(){
int grade = 0;
int counter = 1;
int adder = 0;
int total = 0;
do{
cout <<"Enter assignment #"<< counter << " (out of 10 points): ";
cin >> grade;
counter++;
if(grade == -1){
break;
}
else{
adder += grade;
total += 10;
}
}while(counter != 15);
cout << adder <<" out of " << total <<" points for assignment grade" << endl << endl;
Recieve += adder;
this -> total += total;
}
void Grade::getTests(){
int grade = 0;
int counter = 1;
int adder = 0;
int total = 0;
int points = 30;
do{
cout <<"Enter Test #"<< counter << " (out of "<< points <<" points): ";
cin >> grade;
counter++;
if(grade == -1){
break;
}
else{
adder += grade;
total += points;
}
points += 30;
}while(counter != 4);
cout << adder <<" out of " << total <<" points for test grade" << endl << endl;
Recieve += adder;
this -> total += total;
}
void Grade::getPrefinal(){
int grade = 0;
int add = 26;
cout << "Enter pre-final (out of "<< add <<" points): ";
cin >> grade;
if ( grade == -1 ){
grade = 0;
add = 0;
}
cout << grade <<" out of " << add <<" points for pre final" << endl << endl;
Recieve += grade;
this -> total += add;
}
void Grade::getFinal(){
int grade = 0;
int Add = 90;
for (int i = 0; i < 1; ++i)
cout << "Enter Final (out of "<< Add <<" points): ";
cin >> grade;
if ( grade == -1 ){
grade = 0;
Add = 0;
}
cout << grade <<" out of " << Add <<" points for final" << endl << endl;
Recieve += grade;
this -> total += Add;
}
void Grade::displayTotals(){
int percentage= 0;
string grade;
percentage = (static_cast(Recieve)/total) * 100;
if (percentage >= 94)
grade ="A";
if ((percentage >= 90)&&(percentage <= 93))
grade ="A-";
if ((percentage >= 88)&&(percentage <= 89))
grade ="B+";
if ((percentage >= 84)&&(percentage <= 87))
grade ="B";
if ((percentage >= 80)&&(percentage <= 83))
grade ="B-";
if ((percentage >= 78)&&(percentage <= 79))
grade ="C+";
if ((percentage >= 70)&&(percentage <= 77))
grade ="C";
if ((percentage >= 60)&&(percentage <= 69))
grade ="D";
if (percentage < 60)
grade ="F";
cout <<"TOTAL: "<
}
int main() {
Grade gradeMe;
gradeMe.getExercises();
gradeMe.getClickers();
gradeMe.getLabs();
gradeMe.getTraces();
gradeMe.getAssignments();
gradeMe.getTests();
gradeMe.getPrefinal();
gradeMe.getFinal();
gradeMe.displayTotals();
}
Check ifsream/ofstream libraries they responsible for reading and writing to files