Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <fstream> #include <iomanip> #include <string> usin

ID: 3895624 • Letter: #

Question

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

using namespace std;

string lastNames[40];

int scores[40][5];

int students;

double averageScore[40][5];

char letterGrade[40];

void readData(ifstream& infile);

char calGrade(double averageScore);

void outputData (ofstream& outdata);

int main()

{

ifstream infile;

ofstream outdata;

readData(infile);

outputData(outdata);

return 0;

}

void readData(ifstream& infile);

int score;

int i = 0;

char grade;

float avgScore = 0.00, totalScore;

ifstream infile;

inFile.open("scores.txt");

cout << setprecision(2) << avgScore << endl;

if(!infile)

{

cout << "Cannot open the input file." << endl;

return 1;

}

else

{

while(infile)

{

totalScore = 0.0;

infile >> name;

lastNames[i] = name;

for(int j = 0; j < 5; j++)

{

infile >> score;

scores[i][j] = score;

totalScore += score;

}

averageScore = totalScore / 5;

averageScore[i] = avg;

grade = letterGrade(avg);

grades[i] = grade;

i++;

students ++;

}

infile.close();

}

}

char letterGrade(double averageScore);

{

char grade;

if (averageScore >= 90 && averageScore <= 100)

grade = 'A';

else if (averageScore >=80 && averageScore <= 89)

grade = 'B';

else if (averageScore >=70 && averageScore <= 79)

grade = 'C';

else if (averageScore >= 60 && averageScore <= 69)

grade = 'D';

else if (averageScore >= 0 && averageScore <= 59)

grade = 'F';

return grade;

}

void outputData(ofstream& outdata)

outdata.open("grades.txt")

cout << "Last name Score1 Score2 Score3 Score4 Score5 Avg Grade" << endl;

cout << "--------- ------ ------ ------ ------- ------ --- -----" << endl;

outdata << "Last Name Score1 Score2 Score3 Score4 Score5 Avg Grade" << endl;

outdata << "--------- ------ ------ ------ ------ ------ --- -----" << endl;

for (int i = 0; i < students; i++)

{

cout << setw(10) << lastnames[i] << " ";

outdata << setw(10) << lastnames[i] << " ";

for (int j = 0; j < 5; j++)

{

cout << scores[i][j] << " ";

outdata << scores[i][j] << " ";

}

cout << averageScore[i] << " " << grades[i] << endl;

outdata << averageScore << " " << grades[i] << endl;

}

dataOut.close();

}

}

}

exit status 1 main.cpp:28:1: error: 'inFile' does not name a type; did you mean 'infile'? inFile.open("scores.txt"); ^~~~~~ infile main.cpp:29:1: error: 'cout' does not name a type cout << setprecision(2) << avgScore << endl; ^~~~ main.cpp:31:1: error: expected unqualified-id before 'if' if(!infile) ^~ main.cpp:36:1: error: expected unqualified-id before 'else' else ^~~~ main.cpp:58:1: error: expected declaration before '}' token } ^

Explanation / Answer

Hello dude, Please check the logic of our code. because most of your code is unclear and there are many undeclared variables and functions too. I think u need to clearly mention the output of this program. I corrected all the mistakes but once please check the variable types and functions logic.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

string lastNames[40];

int scores[40][5];

int students;

double averageScore[40][5];

char grades[40];

char letterGrade[40];

void readData(ifstream& infile);

char calGrade(double averageScore);

void outputData (ofstream& outdata);

char letterGrades(double averageScore);

int main()
{

ifstream infile;

ofstream outdata;

readData(infile);

outputData(outdata);

return 0;

}

void readData(ifstream& infile){

int score;

int i = 0;

char grade;
string name;

float avgScore = 0.00, totalScore;
std::ifstream ifl;

ifl.open ("scores.txt", std::ifstream::in);
cout << setprecision(2) << avgScore << endl;

if(!ifl)

{

cout << "Cannot open the input file." << endl;
}

else

{

while(ifl)

{

totalScore = 0.0;

ifl >> name;

lastNames[i] = name;

for(int j = 0; j < 5; j++)

{

ifl >> score;

scores[i][j] = score;

totalScore += score;

}

averageScore[i][0] = (double)totalScore / 5;
double avg = 0;
averageScore[i][0] = avg;

grade = letterGrades(avg);

grades[i] = grade;

i++;

students ++;

}

ifl.close();

}

}

char letterGrades(double averageScore)

{

char grade;

if (averageScore >= 90 && averageScore <= 100)

grade = 'A';

else if (averageScore >=80 && averageScore <= 89)

grade = 'B';

else if (averageScore >=70 && averageScore <= 79)

grade = 'C';

else if (averageScore >= 60 && averageScore <= 69)

grade = 'D';

else if (averageScore >= 0 && averageScore <= 59)

grade = 'F';

return grade;

}

void outputData(ofstream& outdata){

outdata.open("grades.txt");

cout << "Last name Score1 Score2 Score3 Score4 Score5 Avg Grade" << endl;

cout << "--------- ------ ------ ------ ------- ------ --- -----" << endl;

outdata << "Last Name Score1 Score2 Score3 Score4 Score5 Avg Grade" << endl;

outdata << "--------- ------ ------ ------ ------ ------ --- -----" << endl;

for (int i = 0; i < students; i++)

{

cout << setw(10) << lastNames[i] << " ";

outdata << setw(10) << lastNames[i] << " ";

for (int j = 0; j < 5; j++)

{

cout << scores[i][j] << " ";

outdata << scores[i][j] << " ";

}

cout << averageScore[i] << " " << grades[i] << endl;

outdata << averageScore << " " << grades[i] << endl;

}

outdata.close();

}

**Comment for any further queries.