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

C++ program Exercise 1 : #include // FILL IN DIRECTIVE FOR FILES #include <iostr

ID: 3633041 • Letter: C

Question

C++ program

Exercise 1:

#include // FILL IN DIRECTIVE FOR FILES
#include <iostream>
#include <iomanip>
using namespace std;


// This program reads records from a file. The file contains the
// following: student's name, two test grades and final exam grade.
// It then prints this information to the screen.


const int NAMESIZE = 15;
const int MAXRECORDS = 50;
struct Grades                             // declares a structure
{
char name[NAMESIZE + 1];
int test1;
int test2;
int final;

};

typedef Grades gradeType[MAXRECORDS];   
// This makes gradeType a data type
// that holds MAXRECORDS
// Grades structures.

// FIll IN THE CODE FOR THE PROTOTYPE OF THE FUNCTION ReadIt
// WHERE THE FIRST ARGUMENT IS AN INPUT FILE, THE SECOND IS THE
// ARRAY OF RECORDS, AND THE THIRD WILL HOLD THE NUMBER OF RECORDS
// CURRENTLY IN THE ARRAY.


int main()

{   
ifstream indata;
indata.open("graderoll.dat");
int numRecord;                // number of records read in
gradeType studentRecord;
    
if(!indata)
{
  cout << "Error opening file. ";
  cout << "It may not exist where indicated" << endl;
  return 1;
}

// FILL IN THE CODE TO CALL THE FUNCTION ReadIt.
  
// output the information
    for (int count = 0; count < numRecord; count++)
{
    cout << studentRecord[count].name << setw(10)
      << studentRecord[count].test1
      << setw(10) << studentRecord[count].test2;
    cout << setw(10) << studentRecord[count].final << endl;
}               

return 0;
}

//**************************************************************
//     readIt
//
// task:   This procedure reads records into an array of
//            records from an input file and keeps track of the
//        total number of records
// data in: data file containing information to be placed in
//            the array
// data out: an array of records and the number of records
//
//**************************************************************

void readIt(// FILL IN THE CODE FOR THE FORMAL PARAMETERS AND THEIR
            // DATA TYPES.
     // inData, gradeRec and total are the formal parameters
     // total is passed by reference)

{
   total = 0;

   inData.get(gradeRec[total].name, NAMESIZE);
   while (inData)
   {
     // FILL IN THE CODE TO READ test1
     // FILL IN THE CODE TO READ test2
     // FILL IN THE CODE TO READ final
    
total++;     // add one to total

     // FILL IN THE CODE TO CONSUME THE END OF LINE
     // FILL IN THE CODE TO READ name
    
   
}

}

graderoll.dat file

Dean DeFino     88 98 99
Sally Johnson   78 89 82
Bill Benny      75 79 81
Thomas Billows 78 84 89

Explanation / Answer

please rate - thanks

#include <fstream>// FILL IN DIRECTIVE FOR FILES
#include <iostream>
#include <iomanip>
using namespace std;


// This program reads records from a file. The file contains the
// following: student's name, two test grades and final exam grade.
// It then prints this information to the screen.


const int NAMESIZE = 15;
const int MAXRECORDS = 50;
struct Grades                             // declares a structure
{
char name[NAMESIZE + 1];
int test1;
int test2;
int final;

};

typedef Grades gradeType[MAXRECORDS];  
// This makes gradeType a data type
// that holds MAXRECORDS
// Grades structures.
void readIt(istream&,gradeType,int&);


// FIll IN THE CODE FOR THE PROTOTYPE OF THE FUNCTION ReadIt
// WHERE THE FIRST ARGUMENT IS AN INPUT FILE, THE SECOND IS THE
// ARRAY OF RECORDS, AND THE THIRD WILL HOLD THE NUMBER OF RECORDS
// CURRENTLY IN THE ARRAY.


int main()

{  
ifstream indata;
indata.open("graderoll.dat");
int numRecord;                // number of records read in
gradeType studentRecord;
   
if(!indata)
{
cout << "Error opening file. ";
cout << "It may not exist where indicated" << endl;
return 1;
}

// FILL IN THE CODE TO CALL THE FUNCTION ReadIt.
readIt(indata,studentRecord,numRecord);
// output the information
    for (int count = 0; count < numRecord; count++)
{
    cout << studentRecord[count].name << setw(10)
      << studentRecord[count].test1
      << setw(10) << studentRecord[count].test2;
    cout << setw(10) << studentRecord[count].final << endl;
}              
return 0;
}

//**************************************************************
//     readIt
//
// task:   This procedure reads records into an array of
//            records from an input file and keeps track of the
//        total number of records
// data in: data file containing information to be placed in
//            the array
// data out: an array of records and the number of records
//
//**************************************************************

void readIt(istream& inData,gradeType gradeRec,int& total)
// FILL IN THE CODE FOR THE FORMAL PARAMETERS AND THEIR
            // DATA TYPES.
     // inData, gradeRec and total are the formal parameters
     // total is passed by reference)

{
   total = 0;

   inData.get(gradeRec[total].name, NAMESIZE);
   while (inData)
   {
     // FILL IN THE CODE TO READ test1
     inData>>gradeRec[total].test1;
     // FILL IN THE CODE TO READ test2
     inData>>gradeRec[total].test2;
     // FILL IN THE CODE TO READ final
    inData>>gradeRec[total].final;
     total++;     // add one to total

     // FILL IN THE CODE TO CONSUME THE END OF LINE
     inData.ignore(40,' ');
     // FILL IN THE CODE TO READ name
    inData.get(gradeRec[total].name, NAMESIZE);
  
}

}


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