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 calculateGrade(double score){
if (score >=90)
return 'A';
else if (score >=80)
return 'B';
else if (score >=70)
return 'C';
else if (score >=60)
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 infile(filename);
if (!infile){//if file not found
cerr "Error: Unable to open file " filename endl;
return 1;
}
//declare vectors to store lastNames,firstNames,midterm1Scores,midterm2Scores,finalScores
vector lastNames, firstNames;
vector midterm1Scores, midterm2Scores, finalScores;
//Declare variables
string lastName, firstName;
double midterm1, midterm2, final;
//Open the tsv file and read the student information.
while (infile >> lastName >> firstName >> midterm1>> midterm2>> final){
lastNames.push_back(lastName);
firstNames.push_back(firstName);
midterm1Scores.push_back(midterm1);
midterm2Scores.push_back(midterm2);
finalScores.push_back(final);
}
infile.close();
ofstream outfile("report.txt");
if (!outfile){
cerr "Error: Unable to create report.txt" endl;
return 1;
}
// Compute the average exam score of each student.
double midterm1Sum =0, midterm2Sum =0, finalSum =0;
for (int i =0; i lastNames.size(); ++i){
double averageScore =(midterm1Scores[i]+ midterm2Scores[i]+ finalScores[i])/3.0;
char grade = calculateGrade(averageScore);
// 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 lastNames[i]"\t" firstNames[i]"\t"
midterm1Scores[i]"\t" midterm2Scores[i]"\t" finalScores[i]"\t"
grade endl;
// Update sums for exam averages
midterm1Sum += midterm1Scores[i];
midterm2Sum += midterm2Scores[i];
finalSum += finalScores[i];
}
// Calculate and output exam averages
double midterm1Avg = midterm1Sum / lastNames.size();
double midterm2Avg = midterm2Sum / 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: midterm1" fixed setprecision(2) midterm1Avg
", midterm2" fixed setprecision(2) midterm2Avg
", final " fixed setprecision(2) finalAvg endl;
outfile.close();
cout "Report generated successfully!" endl;
return 0;
}
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
3: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
What is wrong with my code? Can someone correct

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!