#include #include #include #include using namespace std; // Constant and Type declarations const int MAXSIZE = 80; struct Roster { string LName; string FName; char Cheesecake; }; // Function Prototypes char * returnfilename(char * ); int recordcount(const char * ); void readsurvey(const int, const char *, struct Roster *); void sortrecord(struct Roster * , const int); void printsummary(const int, struct Roster * ); // Main Routine int main (void) { char * filename = new char [MAXSIZE]; int numberofrecords = 0; struct Roster * MyRoster; filename = returnfilename(filename); numberofrecords = recordcount(filename); MyRoster = new struct Roster[numberofrecords]; readsurvey(numberofrecords, filename, MyRoster); sortrecord(MyRoster, numberofrecords); printsummary(numberofrecords, MyRoster); system("pause"); return 0; } char * returnfilename (char * fn) { ifstream myfile; cout << "Please enter a valid file name: "; cin >> fn; myfile.open(fn); while(!myfile.is_open()) { cout << "invalid file name, please re-enter: "; cin >> fn; myfile.open(fn); } myfile.close(); return fn; } int recordcount (const char * filename) { ifstream myfile; int count = 0; char inputline[MAXSIZE]; myfile.open(filename); myfile.getline(inputline, MAXSIZE); while(!myfile.eof()) { count ++; myfile.getline(inputline,MAXSIZE); } myfile.close(); return count; } void readsurvey (const int rc, const char * fn, struct Roster * ms) { ifstream myfile; myfile.open(fn); for (int index = 0; index < rc; index++) { myfile >> ms[index].LName; myfile >> ms[index].FName; myfile >> ms[index].Cheesecake; } myfile.close(); } void sortrecord (struct Roster * mr, const int rc) { bool swapped = true; while(swapped) { swapped = false; for(int i = 0; i < rc - 1; i++) if (mr[i].LName > mr[i+1].LName) { Roster temp = mr[i]; mr[i] = mr[i+1]; mr[i+1] = temp; swapped = true; } } } void printsummary (const int rc, struct Roster * mr) { int cake = 0; int pie = 0; cout << setw(15) << left << "THE CHEESECAKE REPORT" << endl; cout << setw(15) << left << "LAST NAME" ; cout << setw(15) << left << "FIRST NAME" ; cout << setw(15) << left << "CAKE OR PIE" << endl; cout << "-----------------------------------------" << endl; for (int index = 0; index < rc; index ++) { cout << setw(15) << left << mr[index].LName; cout << setw(15) << left << mr[index].FName; if (mr[index].Cheesecake=='P' || mr[index].Cheesecake =='p') { pie++; cout << "Pie" <