#include #include #include #include "Contestant.h" using namespace std; /* Member Function readData() */ /* Contestant member function readData(): * Input: * cfile - a reference to the input file * Process: * read the input file and load the object's data members * Output: * return true if file is read and object fields loaded * else return false if EOF reached. */ bool Contestant::readData(ifstream &cfile) { if (cfile >> name.last) { cfile >> name.first; cfile >> personal.gender; cfile >> personal.haircolor; cfile >> personal.age; cfile >> personal.job.title; cfile >> personal.job.salary; return true; } return false; } /* Member Function printData: */ /* Contestant member function printData(): * Input: * dbfile - a reference to the output file * Process: * write the object's data members to the output file * Output: * the written data members of the object */ void Contestant::printData(ofstream &dbfile) { dbfile.setf(ios::fixed,ios::floatfield); dbfile.precision(2); //set decimal precision dbfile << name.first; dbfile << "\t" << name.last; dbfile << "\t" << personal.gender; dbfile << "\t" << personal.haircolor; dbfile << "\t" << personal.age; dbfile << "\t" << personal.job.title; dbfile << "\t"; dbfile.width(9); dbfile << personal.job.salary; dbfile << endl; return; } /* Member Function compareAge() */ /* Contestant member function compareAge(): * Input: * agewanted - age wanted * Process: * compare agewanted to the object's age * Output: * if ages are the same, print the object's name and return true * else return false */ bool Contestant::compareAge(int agewanted) { if (personal.age == agewanted) { cout << name.first << " " << name.last << endl; return true; } return false; }