I have this base program that I created and need to add in a sorter, apply letter grades to the sorted scores, put everything into function format, and output everything to a .doc file. I would greatly appreciate help with this. Thank you.
Also, It does not look formatted properly when providing the code. Sorry about that.
// =============================================================================
// Input Required: The input required is the grades from the user when
// they are prompted. File containing input has been made for
// convenience.
// Output Desired: The output desired is the User Grades.doc, where all of the
// grades will be recorded.
// =============================================================================
#include <conio.h>
#include <fstream.h>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <math.h>
ofstream fout; // This is the output textfile.
usingnamespace std;
// =============================================================================
int main ()
{
// Variable Declaration
double a [100];
int ScoreReplace;
int i;
int count;
constint sentinel = -1;
char reply;
double sum, sumsqr, average, stddev;
/*
============================================================================
Alphabetized Variable Dictionary
average: This will show the average of all of the scores entered by
the user.
It uses the sum and count variables to calculate this.
a [count]: This is a placeholder for each score that is input by the
user.
count: This is used to record the number of inputs from the user
fout: output textfile
reply: This is used to determine whether the input by the user is
correct.
It forces the user to answer Y, y, N, or n. If the user
enters an invalid response, the process will not continue.
ScoreReplace: This is the variable that will be used when a user is
replacing a score within the array.
sentinel: This is the number used to end the data stream when the input
is equal to it.
stddev: This is the variable for standard deviation from the average
of the scores. It uses the sum and sumsqr variables.
sum: This is used to combine all scores for the average
calculation
sumsqr: This variable is used within the stddev, or Standard
Deviation, calculations.
============================================================================
*/
fout.open ("User Grades.doc");
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << setw (64) << "GGGG RRRRR AAAA DDDDD EEEEEE RRRRR ";
cout << endl;
cout << setw (63) << "GG GG RR RR AA AA DD DD EE RR RR";
cout << endl;
cout << setw (63) << "GG GG RR RR AA AA DD DD EE RR RR";
cout << endl;
cout << setw (63) << "GG RRRRR AAAAAA DD DD EEEEEE RRRRR ";
cout << endl;
cout << setw (63) << "GG RRRR AAAAAA DD DD EEEEEE RRRR ";
cout << endl;
cout << setw (63) << "GG GGG RRRRR AA AA DD DD EE RRRRR ";
cout << endl;
cout << setw (63) << "GG GG RR RR AA AA DD DD EE RR RR";
cout << endl;
cout << setw (63) << "GGGGGG RR RR AA AA DDDDDD EEEEEE RR RR";
cout << endl;
cout << endl << endl << endl;
cout << setw (53) << "Press Enter to Continue...";
cin.get ();
system ("cls"); // This is used to open a new console window.
do // This is to be used when there is a set, or another set of grades.
{
count = 0;
do // This is to prompt the user for a set of grades.
{
count ++;
cout << endl << endl;
cout << setw (40) << "Please enter the user's scores. ";
cout << setw (5) << "Entering -1 will end score input." << endl;
cout << endl;
cout << setw (50) << "Enter score number " << count << ": ";
cin >> a [count];
}
while ( a [count] != -1);
count --;
// echo print scores
do
{
system ("cls");
for ( i = 1; i <= count; i++)
{
if (( i - 1) % 6 == 0)
{
cout << endl << endl;
}
cout << setw (5) << "[";
cout << setw (2) << i << "]";
cout << setw (4) << a [i];
}
cout << endl << endl << endl;
cout << setw (40) << "Enter the index you ";
cout << "would like to correct." << endl;
cout << setw (50) << "Enter 0 to continue.";
cout << endl;
cout << setw (46) << "Enter index: ";
cin >> ScoreReplace;
if (ScoreReplace != 0)
{
cout << setw (46) << "Enter replacement grade";
cout << " for score #" << ScoreReplace << ": ";
cin >> a [ScoreReplace];
}
cin.get ();
}
while (ScoreReplace != 0);
for (i = 1; i <= count; i++)
{
if (( i - 1) % 25 == 0)
{
if ((i - 1) != 0)
{
fout << "\f";
}
fout << setw (45) << "User Grades" << endl << endl;
}
fout << setw (35) << "[";
fout << setw (2) << i << "]";
fout << setw (4) << a [i];
fout << endl << endl;
}
system ("cls");
cout << setw (55) << "These are the finalized scores.";
for (i = 1; i <= count; i++)
{
if (( i - 1) % 6 == 0)
{
cout << endl << endl;
}
cout << setw (5) << "[";
cout << setw (2) << i << "]";
cout << setw (4) << a [i];
}
cout << endl << endl;
cout << setw (50) << "Please press enter.";
cin.get();
sum = 0.0;
sumsqr = 0.0;
for ( i = 1; i <= count; i++)
{
sum = sum + a [i];
sumsqr = sumsqr + (a [i] * a [i] );
}
average = sum / count;
stddev = sqrt ((count * sumsqr - (sum * sum) ) / (count * (count - 1)));
system ("cls");
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << setw (40) << "The average of this ";
cout << "set of scores is: " << setprecision (4) << average;
cout << endl << endl << endl;
cout << setw (40) << "The standard deviation ";
cout << "of the scores is: " << setprecision (4) << stddev;
cout << endl << endl << endl;
cout << setw (51) << "Press Enter to close.";
cin.get ();
do // This is to prompt another set of grades to be entered by the user.
{
system ("cls");
cout << endl << endl << endl << endl << endl << endl << endl << endl;
cout << setw (56) << "Is there another set of grades?" << endl << endl;
cout << setw (49) << "y = yes or n = no: ";
cin >> reply;
}
while ((reply != 'n') && (reply != 'N') &&
(reply != 'y') && (reply != 'Y'));
}
while ((reply != 'N') && (reply != 'n'));
fout.close();
return 0;
}
// =============================================================================