Write a C program that will ask the user for the name of a d

Write a C++ program that will ask the user for the name of a data file. This data file contains a list of students in some class. The names are listed, one per line, in the following format: lastName firstName middleInitial and each part of the name is separated by a space. Each student in this class has a data file that contains an unknown number of test scores. The name of each student’s data file is formed by concatenating the students first and last name and adding “.dat”, for example: Student Name: Tuel Dennis D Student Data File: DennisTuel.dat Your program should open each student’s data file, read in the scores and calculate the student’s average. In addition to calculating the average for each student you should report the average for the class, and the highest and lowest test score in the class.

Note: All averages should be rounded to the nearest hundredth.

cout << fixed << setprecision(2);

Example:

Data File: Students.dat

Tuel Dennis D Drummond

Ann M Maxwell

Virginia L

DennisTuel.dat

85

88

92

86

AnnDrummond.dat

95

72

88

89

VirginiaMaxwell.dat

68

75

83

98

Sample Program Output:

Enter Name of Data File: Students.dat

Students Average

Dennis D Tuel 87.75

Ann M Drummond 86.00

Virginia L Maxwell 81.00

Class Average: 84.92

Max Score: 98.00

Min Score 68.00

Solution

#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{

   //Declare variables
   string firstName;
   string lastName;
   string middleName;
   string studentNameFile;
   string datFileName;

   vector< double > scoreVector;

   double studentAverage = 0.0;
   double classAverage = 0.0;
   double lowestScore = 0.0;
   double highestScore = 0.0;
   double score = 0.0;

   double studentSum = 0.0;
   double classSum = 0.0;
   int studentScoreCount = 0;
   int classScoreCount = 0;

   //Input file stream
   cout << \"Enter name of the file with student names: \";
   cin >> studentNameFile;

   ifstream inputFile;
   inputFile.open( studentNameFile.c_str() );

   //Begin looping through student names
   while ( inputFile >> lastName   &&
           inputFile >> firstName &&
           inputFile >> middleName    )
   {

      //Open student .dat file
      datFileName = firstName + lastName + \".dat\";
      ifstream newInputFile;
      newInputFile.open( datFileName.c_str() );

      //Sum up the current students scores
      //Also add that sum to the class sum
      while ( newInputFile >> score )
      {
         studentSum += score;
         classSum   += score;

         //Put scores into a vector so that
         //we can find the highest and lowest
         //score later on
         scoreVector.push_back( score );

         studentScoreCount++;
         classScoreCount++;
      }

      //Calculate the average for this student
      studentAverage = studentSum / studentScoreCount;

      //Print the information on the screen
      //You could also write it to a file here if you want
      cout << firstName << \" \" << lastName << \" \"
           << middleName << \" \" << studentAverage << endl;

      //Reset counting information for next loop iteration
      studentSum = 0.0;
      studentAverage = 0.0;
      studentScoreCount = 0;
      datFileName = \"\";

      //Close file stream
      newInputFile.close();

   }//end student name loop

   //Calculate and display class average
   classAverage = classSum / classScoreCount;
   cout << \"Class average is: \" << classAverage << endl;

   //Calculate and display highest/lowest score
   lowestScore = scoreVector[ 0 ];
   highestScore = scoreVector[ 0 ];
   for ( int i = 1; i < scoreVector.size(); i++ )
   {
      if ( scoreVector[ i ] > highestScore )
         highestScore = scoreVector[ i ];

      if ( scoreVector[ i ] < lowestScore )
         lowestScore = scoreVector[ i ];
   }

   cout << \"Highest/Lowest scores are: \"
        << highestScore << \"/\" << lowestScore << endl;

   return 0;

}

Description: Here in the above program you could give the student First name,middle name and last name to create studentname file, there in that program by the values of your program will be the student data.
           With the each student data you could find average score of the class,highest score of the class and lowest score will be calculated easily.

Write a C++ program that will ask the user for the name of a data file. This data file contains a list of students in some class. The names are listed, one per
Write a C++ program that will ask the user for the name of a data file. This data file contains a list of students in some class. The names are listed, one per
Write a C++ program that will ask the user for the name of a data file. This data file contains a list of students in some class. The names are listed, one per

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site