Question
PLEASE ANSWER WITH NEW CODE For this week's assignment you are going to add to a modified solution to the Programming Exercise 2 from the
PLEASE ANSWER WITH NEW CODE
For this week's assignment you are going to add to a modified solution to the "Programming Exercise 2" from the book (pg. 648). You are are going to start with the shell of the program Structs_Example_From_Book.cppPreview the document and add the following functions: Add the following functions: void PrintStudentInfoRange(const int iMinScore, const int iMaxScore, Student students[], const int iSize) - To the caller this function will print just like "PrintStudentInfo()" but will take 2 additional parameters that the caller needs to specify to restrict the range of student data to the scores that are in between (and including) "iMinScore" and "iMaxScore". For the implementation the function is finding the Student structures that fall within the range and then handing them off to "PrintStudentInfo()" to do the printing. const float GetAverageGrade(Student students[], const int iSize) - This function returns the average of all of the student grades. Please download the shell of the program Structs_Example_From_Book.cppPreview the document and flesh out the functions defined above. You will notice in this file that the functions are already being called in "main". Here is an executable and the data file:StudentData.zip To run it please make sure both files are in the same folder and pass the data file name on the command line like we did in the past:
***
Contents of StudentData.zip
Mike Noel 88 John Smith 98 Emma Watson 58 Harry Potter 68 Ron Weasley 75 Alex Roark 98 Tom Sawyer 94 Huck Finn 92 Joe Doe 90 Susan Smith 95 Sam Grover 78 Diane Phelps 10 John Franklin 85 Derrick Myers 59 Joel Jones 59 Sonny Bono 39 Tim Allen 34 Alice Cooper 55 Tom Foolery 88 Art Stanton 23
***
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
using namespace std;
const int STUDENTS = 20;
///////////////////////////////////////////////////////////////////////////////
struct Student
{
string sStudentFName;
string sStudentLName;
int iTestScore;
char cGrade;
};
///////////////////////////////////////////////////////////////////////////////
bool ReadStudentData(string sFileName, Student students[], const int iSize)
{
ifstream iFile(sFileName);
if (!iFile)
{
cout << "Please specify a file name." << endl;
system("PAUSE");
return 1;
}
int iCount = 0;
while (!iFile.eof() && iCount < STUDENTS)
{
iFile >> students[iCount].sStudentFName;
iFile >> students[iCount].sStudentLName;
iFile >> students[iCount].iTestScore;
iCount++;
}
iFile.close();
return true;
}
///////////////////////////////////////////////////////////////////////////////
void AssigneGrade(Student students[], const int iSize)
{
for (int i = 0; i < iSize; i++)
{
if (students[i].iTestScore > 89)
{
students[i].cGrade = 'A';
}
else if (students[i].iTestScore > 79)
{
students[i].cGrade = 'B';
}
else if (students[i].iTestScore > 69)
{
students[i].cGrade = 'C';
}
else if (students[i].iTestScore > 59)
{
students[i].cGrade = 'D';
}
else
{
students[i].cGrade = 'E';
}
}
}
///////////////////////////////////////////////////////////////////////////////
Student GetStudentHighestScore(Student students[], const int iSize)
{
int iHighestIndex = 0;
int iHighestScore = 0;
for (int i = 0; i < iSize; i++)
{
if (students[i].iTestScore > iHighestScore)
{
iHighestScore = students[i].iTestScore;
iHighestIndex = i;
}
}
return students[iHighestIndex];
}
///////////////////////////////////////////////////////////////////////////////
void PrintHeading(string sTitle)
{
/// Print header....
cout << endl << endl;
cout << sTitle << endl;
cout << left << setfill(' ') << setw(16);
cout << "Name:";
cout << left << setfill(' ') << setw(9);
cout << "Score:";
cout << "Grade:" << endl;
cout << left << setfill('-') << setw(30) << '-' << endl;
}
///////////////////////////////////////////////////////////////////////////////
void PrintStudentInfo(Student students[], const int iSize)
{
/// Get the longest student name (first and last).
static size_t iLongestFullName = 0;
for (int i = 0; i < iSize; i++)
{
string sFullName = students[i].sStudentFName + ", " + students[i].sStudentLName;
if (iLongestFullName < sFullName.length())
iLongestFullName = sFullName.length();
}
/// Print the scores....
for (int i = 0; i < iSize; i++)
{
string sFullName = students[i].sStudentFName + ", " + students[i].sStudentLName;
cout << left << setfill('.') << setw(16);
cout << sFullName;
cout << students[i].iTestScore;
cout << right << setfill('.') << setw(8);
cout << students[i].cGrade;
cout << endl;
}
}
///////////////////////////////////////////////////////////////////////////////
void PrintStudentInfoRange(const int iMinScore, const int iMaxScore, Student students[], const int iSize)
{
// Happy code goes here....
}
///////////////////////////////////////////////////////////////////////////////
const float GetAverageScore(Student students[], const int iSize)
{
// Happy code goes here....
}
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
if (argc < 2)
{
cout << "Please specify a file name." << endl;
system("PAUSE");
return 1;
}
//////
Student Students[STUDENTS] = {};
if (ReadStudentData(argv[1], Students, STUDENTS) == false)
{
cout << "Error with ReadStudentData." << endl;
system("PAUSE");
return 1;
}
AssigneGrade(Students, STUDENTS);
Student StudentHighestScore = GetStudentHighestScore(Students, STUDENTS);
PrintHeading("All Students");
PrintStudentInfo(Students, STUDENTS);
PrintHeading("High Score Student");
PrintStudentInfo(&StudentHighestScore, 1);
PrintHeading("Range Test \"A's\"");
PrintStudentInfoRange(90, 100, Students, STUDENTS);
PrintHeading("Range Test \"B's\"");
PrintStudentInfoRange(80, 89, Students, STUDENTS);
PrintHeading("Range Test \"C's\"");
PrintStudentInfoRange(70, 79, Students, STUDENTS);
PrintHeading("Range Test \"D's\"");
PrintStudentInfoRange(60, 69, Students, STUDENTS);
PrintHeading("Range Test \"E's\"");
PrintStudentInfoRange(0, 59, Students, STUDENTS);
cout << endl << "The average score is " << fixed << setprecision(2) << GetAverageScore(Students, STUDENTS) << endl;
system("PAUSE");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started