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

It is a C+ question : Fill in the code in bold so that the data is properly read

ID: 664881 • Letter: I

Question

It is a C+ question :

Fill in the code in bold so that the data is properly read from grades.txt. and the desired output to the screen is as follows(image attached):

Code:

#include <fstream>
#include <iostream>
using namespace std;
// PLACE YOUR NAME HERE
const int MAXNAME = 20;
int main()
{
   ifstream inData;
   inData.open("grades.txt");

   //if file unable to load then prints the error
   if (inData.fail())
   {
       cout << "input file did not open please check it ";

   }
   char name[MAXNAME + 1]; // holds student name
   float average; // holds student average
  
       inData.get(name, MAXNAME + 1);
   while (inData)
   {
       inData >> average;
       cout << name;


       // 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
   }
   cin.get();

   return 0;
}

Grade.txt file is:

Adara Starr 94
David Starr 91
Sophia Starr 94
Maria Starr 91
Danielle DeFino 94
Dominic DeFino 98
McKenna DeFino 92
Taylor McIntire 99
Torrie McIntire 91
Emily Garrett 97
Lauren Garrett 92
Marlene Starr 83
Donald DeFino 73

Output will be like:

OUTPUT TO SCREEN Adara Starr David Starr Sophia Starr Maria Starr Danielle DeFino has a(n) 94 average Dominic DeFino has a(n) 98 average McKenna DeFino has a(n) 92 average Taylor McIntire Torrie McIntire Emily Garrett Lauren Garrett has a(n) 92 average Marlene Starr Donald DeFino has a(n) 73 average has a(n) 94 average has a(n) 91 average has a(n) 94 average has a(n) 91 average has a(n) 99 average has a(n) 91 average has a(n) 97 average has a(n) 83 average

Explanation / Answer

#include <fstream>
#include <iostream>
#include<iomanip>
using namespace std;
// PLACE YOUR NAME HERE
const int MAXNAME = 20;
int main()
{
ifstream inData;
inData.open("grades.txt");
//if file unable to load then prints the error
if (inData.fail())
{
cout << "input file did not open please check it ";
}
char name[MAXNAME + 1]; // holds student name
float average; // holds student average
char studentName;
inData.get(name, MAXNAME + 1);

while (inData)
{
inData >> setprecision(2);
inData >> studName;
inData >> average;
cout << studName << " has a(n) average of" << average << endl;
inData.ignore(100,' '); // Ignore up to 100 characters or until first space is found.
if(inData)
{inData.get(name,MAXNAME+1);
cout << studName << " has a(n) average of" << average << endl;

}
cin.get();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote