#include <fstream> #include <iostream> using namespace std; // Erik Donovan cons
ID: 3602442 • Letter: #
Question
#include <fstream>
#include <iostream>
using namespace std;
// Erik Donovan
const int MAXNAME = 20;
int main()
{
ifstream inData;
inData.open("grades.txt");
char name[MAXNAME + 1]; // holds student name
float average; // holds student average
char studentName;
inData.get(name, MAXNAME + 1);
while (inData)
{
inData >> average;
inData >> studentName;
cout << studentName << " has a(n) average of" << average << endl;
// FILL IN THE CODE to print out name and
// student average
// FILL IN THE CODE to complete the while
// loop so that the rest of the student
// names and average are read in properly
inData.ignore(100, ' ');
if (inData)
{
inData.get(name, MAXNAME + 1);
cout << studentName << " has an average of" << average << endl;
}
cin.get();
system("pause");
return 0;
}
}
Explanation / Answer
he following code is reading the file and printing the details on the screen
#include <fstream>
#include <iostream>
using namespace std;
const int MAXNAME = 20;
int main()
{
ifstream inData;
inData.open("grades.txt");
char name[MAXNAME + 1]; // holds student name
float average; // holds student average
char studentName;
inData.get(name, MAXNAME + 1);
while (inData)
{
inData >> average;
inData >> studentName;
cout << studentName << " has a(n) average of" << average << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.