Question
Hi! If I can get some help with this c++ program, that would be much appreciated. Thank you! Incorperate: void PrintStudentInfoRange(const int iMinScore, const int
Hi! If I can get some help with this c++ program, that would be much appreciated. Thank you!
Incorperate:
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.
Into:
#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