Professional Documents
Culture Documents
//Standard library.
using namespace std; //Allows the use of cout & endl without "std::" prefix.
//Function Prototypes
void read(string names[], int numOfNames, double scores[][NUMBER_OF_TESTS]);
// This functions purpose is to read/save the data from the input file. It
// passes a string array of student names, an integer of the number of names,
// and a two-dimensional array, including each students indidual test scores.
//Function 'main'
int main(){ //Start of function 'main'
//declaring local variables.
string names[NUMBER_OF_STUDENTS]; //String array labled 'names' which
holds each students name. Its size = 'NUMBER_OF_Students' or '10'
double scores[NUMBER_OF_STUDENTS][NUMBER_OF_TESTS]; //Two-dimensional array of
each students individual test scores. Its size = 'NUMBER_OF_Students' by
'NUMBER_OF_TESTS'
double numGrades[NUMBER_OF_STUDENTS]; //Array which stores an average
test number grade for each student. Its size = 'NUMBER_OF_Students' or '10'
char letterGrades[NUMBER_OF_STUDENTS]; //Character array which stores a letter
grade for each student. Its size = 'NUMBER_OF_Students' or '10'
read(names, 10, scores); //Reads and archives data from input file.
calculate(numGrades, scores, 10, letterGrades); //Calulates the average test scores and
letter grade.
outfile << "Before Sorting: " << endl; //Prints parenthasized text to output file.
print(numGrades, names, 10, letterGrades); //Prints the data stored in the passed
variables in an organized manner to the output file.
outfile << "\nAfter Sorting in Ascending order:" << endl; //Prints parenthasized text to
output file.
print(numGrades, names, 10, letterGrades); //Prints the updated data in an
organized manner to the output file.
//user friendly message that directs the user to observe the manipulated data.
cout << "data processed! Open the output file to the view the results!" << endl;
cout << "-------------------------------------------------------------" << endl;
//function 'read'
void read(string names[], int numOfNames, double scores[][NUMBER_OF_TESTS]){ //start of
function 'read'
//declaring local variables.
int nameCounter = 0; //Initializes integer named 'nameCounter' as 0.
int scoreCounter = 0; //Initializes integer named 'scoreCounter' as 0.
scoreCounter = 0;
nameCounter++;
} //End of while loop.
} //End of function 'read'
//function 'calculate'
void calculate(double numGrades[], double scores[][NUMBER_OF_TESTS], int rowSize, char
letterGrades[]){ //start of function 'calculate'
average = (total/NUMBER_OF_TESTS);
numGrades[counter] = average;
averageInt = average + .5;
total = 0;
average = 0;
averageInt = 0;
num = 0;
counter++;
} //End of while loop.
} //End of function 'calculate'
//Function 'print'
void print(double numGrades[], string names[], int rowSize, char letterGrades[]){ //start of
function 'print'
//output formatting.
outfile << left << setw(10) << "Name";
outfile << right << setw(11) << "Grade";
outfile << right << setw(20) << "Letter Grade" << endl;
outfile << "-----------------------------------------" << endl;
//Function 'bubbleSort'
void bubbleSort(double numGrades[], string names[], int rowSize, char letterGrades[]){
//start of function 'bubbleSort'