// Paul Brown - Program 8#include <iostream>#include <fstream>#include <string>using namespace std;typedef char Str[10];// Print Functionvoid Print (Str names[], int grades[], int count){ for (int i = 0; i < count; i++) cout << names[i] << '\t' << grades[i] << endl;}// Function to count grades and find lowest and highestvoid Count (Str names[], int grades[], int count){ int a = 0, b = 0, c = 0, d = 0, f = 0, max = grades[0], min = grades[0]; // find min and max grades for (int i = 1; i < count; i++) { if (grades[i] > max) max = grades[i]; if (grades[i] < min) min = grades[i]; } for (int i = 0; i < count; i++) // count letter grades { if (grades[i] <= 100 && grades[i] >= 90) a++; else if (grades[i] < 90 && grades[i] >= 80) b++; else if (grades[i] < 80 && grades[i] >= 70) c++; else if (grades[i] < 70 && grades[i] >= 60) d++; else if (grades[i] < 60 && grades[i] >= 0) f++; } // letter grade verbage if (a == 1) cout << "There was " << a << " A.\n"; else if (a > 1) cout << "There were " << a << " A's.\n"; if (b == 1) cout << "There was " << b << " B.\n"; else if (b > 1) cout << "There were " << b << " B's.\n"; if (c == 1) cout << "There was " << c << " C.\n"; else if (c > 1) cout << "There were " << c << " C's.\n"; if (d == 1) cout << "There was " << d << " D.\n"; else if (d > 1) cout << "There were " << d << " D's.\n"; if (f == 1) cout << "There was " << f << " F.\n"; else if (f > 1) cout << "There were " << f << " F's.\n"; cout << "The highest grade was " << max << '.' << endl << "The lowest grade was " << min << '.' << endl;}// sort by grade functionvoid SelectionSort (Str name[], int grades[], int count){ for (int i = 0; i < count - 1; i++) { int largest = i; Str tmpname; for (int j = i + 1; j < count; j++) if (grades[j] > grades[largest]) largest = j; int tmp = grades[i]; grades[i] = grades[largest]; grades[largest] = tmp; strcpy (tmpname, name[i]); strcpy (name[i], name[largest]); strcpy (name[largest], tmpname); }}// sort by name functionvoid NameSort (Str name[], int grades[], int count){ for (int i = 0; i < count - 1; i++) { int largest = i; Str tmpname; for (int j = i + 1; j < count; j++) if (strcmp (name[j], name[largest]) < 0) largest = j; int tmp = grades[i]; grades[i] = grades[largest]; grades[largest] = tmp; strcpy (tmpname, name[i]); strcpy (name[i], name[largest]); strcpy (name[largest], tmpname); }}// mainint main (void){ Str names[20]; int grades[20], i = 0; char fn[60]; // request input file cout << " Enter a file name:\n\t"; cin >> fn; ifstream infile (fn); // perfrom requested action on text file if (infile) { for (; infile >> names[i] >> grades[i]; i++); NameSort (names, grades, i); Print (names, grades, i); Count (names, grades, i); SelectionSort (names, grades, i); Print (names, grades, i); Count (names, grades, i); infile.close (); } else cout << "Invalid File"; return 0;}