/* Game Show (Contestant Database) - Separate Declarations and Implementations for each Class */ /* Constructors in all Classes - Illustrating Overloading Constructors */ #include #include #include #include //needed to use system() function #include "Quizshow.h" using namespace std; // Function Prototypes void readdata(Quizshow &); void printdata(const Quizshow &); void printmenu(void); void findage(const Quizshow &); void findgender(const Quizshow &); void findhair(const Quizshow &); void findtitle(const Quizshow &); void findsalary(const Quizshow &); //void pause(void); void pause2(void); int main() { Quizshow jeopardy("Jeopardy Game Show", Name("Alex", "Trebek")); //the Quizshow object char choice; //user menu selection bool not_done = true; //loop control flag /* first part */ /* fill and print database */ readdata(jeopardy); printdata(jeopardy); /* 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(jeopardy); break; case 'g': case 'G': findgender(jeopardy); break; case 'h': case 'H': findhair(jeopardy); break; case 't': case 'T': findtitle(jeopardy); break; case 's': case 'S': findsalary(jeopardy); break; default: cout << "Invalid choice - try again\n\n"; break; } } while (not_done); return 0; } /* Function readdata() * Input: * show - reference to the Quizshow objecct * Process: * Reads in the initial contestant database and counts the number of contestants * Uses method addContestant() to set an object's data members * Output: * Fills in the initial contestant database * Returns the count of the number of contestants in the initial database */ void readdata(Quizshow &show) { string lastname,firstname,haircolor,jobtitle; char gender; int age; double salary; Contestant contestant; Name name; Personal_info personal; Job_info job; // open input file ifstream cfile("myinput.txt"); //comment-out for debugging // ifstream cfile("/users3/ziegler/pgm5/myinput.txt"); //comment-out for debugging // ifstream cfile("/dev/stdin"); //un-comment for debugging while (cfile >> lastname) { cfile >> firstname; cfile >> gender; cfile >> haircolor; cfile >> age; cfile >> jobtitle; cfile >> salary; name = Name(firstname,lastname); job = Job_info(jobtitle,salary); personal = Personal_info(gender,haircolor,age,job); contestant = Contestant(name,personal); show.addContestant(contestant); } cfile.close(); return; } /* Function printdata(): * Input: * contestant - the contestant database * num - the number of contestants * Process: * Prints the contestant database * Uses accessors (getter functions) to get an object's data members * Output: * Prints the contestant database */ void printdata(const Quizshow &show) { // open output file // ofstream dbfile("/users3/ziegler/pgm5/myoutput.txt"); //comment-out for debugging ofstream dbfile("/dev/stdout"); //un-comment for debugging Contestant contestant; Name name; Personal_info personal; Job_info job; dbfile << "\t\tShow: " << show.getShowtitle() << endl; dbfile << "\t\tHost: " << show.getHost().getFirstname() << " " << show.getHost().getLastname() << endl << endl; dbfile << "\t\tContestants in the Database\n\n"; dbfile << "Name\t\tGender\tHair\tAge\tTitle\tSalary\n\n"; for (int count = 0; count < show.getNumcontestants(); count++) { contestant = show.getContestant(count); name = contestant.getName(); personal = contestant.getPersonal_info(); job = personal.getJob_info(); dbfile << name.getFirstname(); dbfile << " " << name.getLastname(); dbfile << "\t" << personal.getGender(); dbfile << "\t" << personal.getHaircolor(); dbfile << "\t" << personal.getAge(); dbfile << "\t" << job.getJobtitle(); dbfile << "\t" << job.getJobsalary(); dbfile << endl; } dbfile.close(); return; } /* Function printmenu() * Input: * none * Process: * Prints the menu of query choices * Output: * Prints the menu of query choices */ 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() * Input: * contestant - the contestant database * num - the number of contestants * Process: * Searches the database and compares each contestant's age to agewanted * Uses method compareAge() to compare an object's age to agewanted * Output: * Prints the names of all contestants whose age equals agewanted */ void findage(const Quizshow &show) { int agewanted,found=0; Contestant contestant; Name name; cout << "\n\nEnter the age you want: "; cin >> agewanted; cout << "\nContestants whose age is " << agewanted<<"\n\n"; for (int count = 0; count < show.getNumcontestants(); count++) { contestant = show.getContestant(count); if (contestant.compareAge(agewanted)) { name = contestant.getName(); cout << name.getFirstname() << " " << name.getLastname() << endl; found++; } } if (!found) cout << "No contestants of this age\n\n"; else cout << endl << found << " contestants found\n"; // give user a chance to look at output before printing menu pause2(); // pause(); return; } /* Function pause2() */ void pause2(void) { char j; cout << "pause to view - enter any character and hit return" << endl; cin >> j; return; } /* Function pause() * Input: * none * Process: * Pauses the program until a key is pressed * Output: * none */ /* void pause(void) { system("pause"); return; } */ void findgender(const Quizshow &show) { } void findhair(const Quizshow &show) { } void findtitle(const Quizshow &show) { } void findsalary(const Quizshow &show) { }