#include #include using namespace std; int main(); void sortScores(int*, int); double getAverage(int *, int); char grade(int); int main() { int numScores, i; cout << "How many scores will you enter? "; cin >> numScores; if (numScores < 1) { cerr << "Invalid number of scores" << endl; return 1; } int *scores; if ((scores = (int*) malloc(sizeof(int) * numScores)) == NULL) { cerr << "Error allocating memory for your scores" << endl; return 1; } for (i = 0; i < numScores; i++) { cout << "Score (" << (i+1) << "/" << numScores << ") "; cin >> i[scores]; // Input validation; ask them for this one again if it's at least 0 if (*(scores+i) < 1) i--; } sortScores(scores, numScores); cout.setf(ios::fixed,ios::floatfield); cout.precision(2); cout << "Average score: " << getAverage(scores, numScores) << endl; cout << "Student Scores" << endl; cout << "--------------" << endl; for (i = 0; i < numScores; i++) cout << "(" << grade(*(scores+i)) << ") " << *(scores+i) << endl; return 0; } void sortScores(int *scores, int n) { int smallest, i, j; for (i = 0; i < n - 1; i++) { smallest = i; for (j = i; j < n; j++) if (*(scores + smallest) > *(scores + j)) smallest = j; swap(*(scores+i), *(scores + smallest)); } } double getAverage(int *scores, int n) { double total = 0; for (int i = 0; i < n; i++) total += *(scores+i); return total / n; } char grade(int score) { if (score >= 90) return 'A'; if (score >= 80) return 'B'; if (score >= 70) return 'C'; if (score >= 60) return 'D'; return 'F'; }