create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name i.e. jSmith). Next it will need to read three integer values that will represent the 3 e xam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student.
Below is an example of what the calculation would be for the program.
score1 * .3 + score2 * .3 + score3 * .4
The program will then determine the letter grade for that student and write the user ID and the letter grade to a file "studentGrade.txt"
The standard grading scale will be used:
A --> 90 – 100
B --> 80 - 89.99
C --> 70 - 79.99
D --> 60 - 69.99
F --> below 60
PLEASE NOTE : FEEL FREE TO ASK ANY DOUBTS by COMMENTING
Language : C++ Programming
IDE : Dev C++
Input File : studentInfo.txt
NName1 57 69 59
NName2 80 71 61
NName3 57 61 85
NName4 77 63 58
NName5 77 65 84
NName6 64 55 88
NName7 95 89 95
NName8 92 60 93
NName9 91 87 97
NName10 53 87 89
:::::::::::::::::::::::::::::::::::::::::::: CODE ::::::::::::::::::::::::::::::::::::::::
#include <iostream>
#include <fstream>
using namespace std;
int main(){
string userID;
int score1,score2,score3;
// open file to read
ifstream reader;
reader.open("studentInfo.txt");
// open file to write
ofstream writer;
writer.open("studentGrade.txt");
// check file is opened or not
if(!reader || !writer){
cout << "Unable to
open/create file.";
// exit program if file not
opened
return -1;
}
// loop until end of file
while(reader >> userID){
// read scores
reader >> score1 >>
score2 >> score3;
// calculate weighted course
average
float wca =
score1*0.3+score2*0.3+score3*0.4;
// calculate grade
char grade;
if(wca>=90){
grade =
'A';
}
else if(wca>=80 &&
wca<90){
grade =
'B';
}
else if(wca>=70 &&
wca<80){
grade =
'C';
}
else if(wca>=60 &&
wca<70){
grade =
'D';
}
else{
grade =
'F';
}
// write userID and grad to
file
writer << userID << " "
<< grade << endl;
}
// close file reader and writer
reader.close();
writer.close();
return 0;
}
:::::::::::::::::::::::::::::::::::::::::::: OUTPUT ::::::::::::::::::::::::::::::::::::::::
studentGrade.txt
:::::::::::::::::::::::::::::::::::::: CODE in EDITOR ::::::::::::::::::::::::::::::::::
_________________________________________________________________
Dear Friend, Feel Free to Ask Any Doubts by Commenting. ASAP i'll respond when i'm available.
I'm on a critical Situation. Please Do Not Forget To Give A Thumbs UP +1. It will Helps me A Lot.
Thank YOU :-)
Get Answers For Free
Most questions answered within 1 hours.