/* Contestant Database */ #include #include #include #include "Contestant.h" using namespace std; //constant definitions const int MAX_NUM_CONTESTANTS = 50; // Function Prototypes void readdata(Contestant[], int &); void printdata(Contestant[], int); void printmenu(void); void findage(Contestant[], int); void findgender(Contestant[], int); void findhair(Contestant[], int); void findtitle(Contestant[], int); void findsalary(Contestant[], int); void pause(void); int main() { Contestant contestant[MAX_NUM_CONTESTANTS]; int num; char choice; bool not_done = true; /* first part */ /* fill and print database */ readdata(contestant,num); printdata(contestant,num); /* second part */ /* call functions to read and process requests */ do { printmenu(); cin >> choice; switch(choice) { case 'q': case 'Q': not_done = false; break; case 'a': case 'A': findage(contestant,num); break; case 'g': case 'G': findgender(contestant,num); break; case 'h': case 'H': findhair(contestant,num); break; case 't': case 'T': findtitle(contestant,num); break; case 's': case 'S': findsalary(contestant,num); break; default: cout << "Invalid choice - try again\n\n"; break; } } while (not_done); //system("pause"); //un-comment if using devC++ return 0; } /* Function readdata() */ void readdata(Contestant contestant[], int &count) { string lastname,firstname,haircolor,jobtitle; char gender; int age; double salary; // open input file ifstream cfile("c:\\bc\\cis1_5\\newpgms\\chapter10\\myinput.txt"); //comment-out for debugging // ifstream cfile("con"); //un-comment for debugging count = 0; //initialize count while (cfile >> lastname) { contestant[count].setLastname(lastname); cfile >> firstname; contestant[count].setFirstname(firstname); cfile >> gender; contestant[count].setGender(gender); cfile >> haircolor; contestant[count].setHaircolor(haircolor);; cfile >> age; contestant[count].setAge(age); cfile >> jobtitle; contestant[count].setJobtitle(jobtitle); cfile >> salary; contestant[count].setJobsalary(salary); count++; } cfile.close(); return; } /* Function printdata: */ void printdata(Contestant contestant[], int num) { // open output file // ofstream dbfile("c:\\bc\\cis1_5\\newpgms\\chapter10\\myoutput.txt"); //comment-out for debugging ofstream dbfile("con"); //un-comment for debugging dbfile << "\t\tContestants in the Database\n\n"; dbfile << "Name\t\tGender\tHair\tAge\tTitle\tSalary\n\n"; for (int count = 0; count < num; count++) { dbfile << contestant[count].getFirstname(); dbfile << " " << contestant[count].getLastname(); dbfile << "\t" << contestant[count].getGender(); dbfile << "\t" << contestant[count].getHaircolor(); dbfile << "\t" << contestant[count].getAge(); dbfile << "\t" << contestant[count].getJobtitle(); dbfile << "\t" << contestant[count].getJobsalary(); dbfile << endl; } dbfile.close(); return; } /* Function printmenu() */ void printmenu(void) { cout << endl << endl; cout << "To obtain a list of contestants with a given\n"; cout << "trait, select a trait from the list and type in\n"; cout << "the letter corresponding to that trait.\n\n"; cout << "To quit, select Q.\n\n"; cout << "\t****************************\n"; cout << "\t List of Choices \n"; cout << "\t****************************\n"; cout << "\t Q -- quit\n"; cout << "\t A -- age\n"; cout << "\t G -- gender\n"; cout << "\t H -- hair color\n"; cout << "\t T -- title\n"; cout << "\t S -- salary\n"; cout << endl << endl <<"\tEnter your selection: "; return; } /* Function findage() */ void findage(Contestant contestant[], int num) // add to main { int agewanted,found=0; cout << "\n\nEnter the age you want: "; cin >> agewanted; cout << "\nContestants whose age is " <