Question: What is wrong with my code? Can someone correct it ? If the input is: StudentInfo.tsv main.cpp #include #include #include #include #include using namespace std;
What is wrong with my code? Can someone correct it
If the input is: StudentInfo.tsv
main.cpp
#include
#include
#include
#include
#include
using namespace std;
Function to calculate letter grade based on score
char calculateGradedouble score
if score
return A;
else if score
return B;
else if score
return C;
else if score
return D;
else
return F;
int main
string filename;
Read the file name of the tsv file from the user.
cout "Enter the filename of the TSV file: ;
cin filename;
ifstream infilefilename;
if infileif file not found
cerr "Error: Unable to open file filename endl;
return ;
declare vectors to store lastNames,firstNames,midtermScores,midtermScores,finalScores
vector lastNames, firstNames;
vector midtermScores, midtermScores, finalScores;
Declare variables
string lastName, firstName;
double midterm midterm final;
Open the tsv file and read the student information.
while infile lastName firstName midterm midterm final
lastNames.pushbacklastName;
firstNames.pushbackfirstName;
midtermScores.pushbackmidterm;
midtermScores.pushbackmidterm;
finalScores.pushbackfinal;
infile.close;
ofstream outfilereporttxt;
if outfile
cerr "Error: Unable to create report.txt endl;
return ;
Compute the average exam score of each student.
double midtermSum midtermSum finalSum ;
for int i ; i lastNames.size; i
double averageScore midtermScoresi midtermScoresi finalScoresi;
char grade calculateGradeaverageScore;
Output the last names, first names, exam scores, and letter grades of the students into a text file named report.txt
Output one student per row and separate the values with a tab character.
outfile lastNamesit firstNamesit
midtermScoresit midtermScoresit finalScoresit
grade endl;
Update sums for exam averages
midtermSum midtermScoresi;
midtermSum midtermScoresi;
finalSum finalScoresi;
Calculate and output exam averages
double midtermAvg midtermSum lastNames.size;
double midtermAvg midtermSum lastNames.size;
double finalAvg finalSum lastNames.size;
Output the average of each exam, with two digits after the decimal point, at the end of report.txt
Hint: Use the setprecision manipulator to format the output.
outfile "Averages: midterm fixed setprecision midtermAvg
midterm fixed setprecision midtermAvg
final fixed setprecision finalAvg endl;
outfile.close;
cout "Report generated successfully!" endl;
return ;
Enter the filename of the TSV file: Report generated successfully!
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
Input
Your file content
Expected file content
Enter the filename of the TSV file: Report generated successfully!
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
Input
StudentInfol.tsv
Expected file content
:Compare output
Enter the filename of the TSV file: Report generated successfully!
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
