For the following code, I received a very low score. I can't get more specific answers from the teachers assistant, and the instructor has never seen or graded my code this term. It works, but are there shortcuts/conventions I am missing? This is for an introductory C++ class.
#include<iostream> //allows input and output
#include<iomanip> //allows use of set width, which I originally used for spacing
using std::setw; //saves some typing
using namespace std; //saves some typing
void sortGrades(double *grades, int size) //improved form of bubble sort
{
bool flag = true;
int length=size-1;
double temp = 0;
while(flag)
{
flag = false;
for (int i=0; i<(size-1); i++)
{
if (*(grades+i)<*(grades+1+i))
{
temp=*(grades+i); //switches elements based on value, the meat of bubble sort
*(grades+i)=*(grades+1+i);
*(grades+1+i)=temp;
flag = true;
}
}
length--; //decrements length after element is sorted to save time
}
} //function prototypes
void evaluateGrades(double *grades, int size, double *average, double *min) //function stores average of array as a variable
{ //and stores the lowest grade as variable min
int i =0;
double temp = 0;
while(i<size)
{
temp = temp + *(grades+i);
i++;
}
*average= temp/size;
*min = *(grades + 9);
}
int main() //begin function main
{
double grades[10]; //declare and initialize variables
double average = 0;
int size = 10;
double min = 0;
for(int i=0; i<10; i++) // loop to fill array with grades
{
cout << "Please enter grade" << endl;
cin >> grades[i];
}
sortGrades(grades, size); //improved form of bubble sort
evaluateGrades(grades, size, &average, &min); //function stores average of array as a variable
//outputs results
cout << "The grade average is " << average << endl;
cout << "The top 3 grades are: " << *grades << ", " << *(grades+1) << ", " << "and " << *(grades+2) << endl;
cout << "The lowest grade is: " << min << endl;
cout << "The contents of the array, sorted in descending order, is: " << endl;
cout << *grades << ", " << *(grades+1) << ", " << *(grades+2) << ", " << *(grades+3) << ", " << *(grades+4) << ", " << *(grades+5) << ", " << *(grades+6) << ", " << *(grades+7) << ", " << *(grades+8) << ", " << *(grades+9) << endl;
cout << " " << endl;
system("pause"); //pause to see results
return 0; //indicate successful program execution
}