// FILENAME: dogracer.cpp // Written by Darin Gillis // gillisd@colorado.edu // This program will utilize file input/output so that it // will take a greyhound racing program and handicap the dogs // as directed by a book i read. // ** NOTE in order for file to be "readable", // the racing program is cut down to one race, & all of the // 2-digit nums in one-eigth & stretch must be truncated // and the race header is also removed. #include // Provides EXIT_FAILURE, EXIT_SUCCESS, atoi #include // Provides external file streams #include // Provides cin, cout, cerr #include // Provides isspace #include // Provides floor, ceil #include "dogclass.h" // Provides Dog Class // PROTOTYPES int round(float num); // GLOBAL DECLARATIONS //************************* Main **************************** int main() { char in_file[40]; // arrays to hold in/out file names ifstream ins; // Input file stream containing a dog race int dognum,topgrade=15; int topspeed=25, topscore=0,difference=0; float topclose = -3.0, rec; int addpts = 50,runpts = 0; Dog *dog[8]; int score[8]; char tempch; // Open input and output file, exit on any error cout << "Please type the encoded file name: "; cin >> in_file; ins.open(in_file); if (ins.fail()) { cerr << "<<< - ERROR: Cannot open " << in_file << " for input. - >>>" << endl; return EXIT_FAILURE; } cout << "Please enter the course record: "; cin >> rec; // Fill the dogs with information for (dognum=0;dognum < 8;dognum++) { dog[dognum] = new Dog(rec); dog[dognum]->getinfo(ins); score[dognum] = 0; // init score array } // Points for grade for (dognum=0;dognum < 8;dognum++) if (dog[dognum]->grade() < topgrade) topgrade = dog[dognum]->grade(); while (topgrade < 16) { for (dognum=0;dognum < 8;dognum++) if (topgrade == dog[dognum]->grade()) score[dognum] += addpts; topgrade++; addpts-=10; } // Points for form for (dognum=0;dognum < 8;dognum++) { tempch = dog[dognum]->curform(); if ((tempch == 'g') || (tempch == 'G')) score[dognum] += 10; else if ((tempch == 'o') || (tempch == 'O')) score[dognum] -= 10; else if ((tempch == 'i') || (tempch == 'I')) score[dognum] += 5; } // Points for speed for (dognum=0;dognum < 8;dognum++) if (round(dog[dognum]->speed()) < topspeed) topspeed = round(dog[dognum]->speed()); for (dognum=0;dognum < 8;dognum++) score[dognum]+= 30 - (3*(round(dog[dognum]->speed()) - round(topspeed))); // Points for run style for (dognum=0;dognum < 8;dognum++) if ((dog[dognum]->runstyle() == 'f')||(dog[dognum]->runstyle() == 'F')) { if ((dog[dognum]->runpref() == 'i')||(dog[dognum]->runpref() == 'I')) { if ((dognum==0)||(dognum==1)) runpts= 10; else if (dognum==2) runpts= 5; else if (dognum==5) runpts= -5; else if ((dognum==6)||(dognum==7)) runpts= -10; } else if ((dog[dognum]->runpref()=='o')||(dog[dognum]->runpref()=='O')) { if ((dognum==0)||(dognum==1)) runpts= -10; else if (dognum==2) runpts= -5; else if (dognum==5) runpts= 5; else if ((dognum==6)||(dognum==7)) runpts= 10; } score[dognum]+= runpts; // STEP 2 ADJUSTMENTS if ((runpts < 0) && (dog[dognum]->earlyspeed() <= 6)) { if ((runpts == -10) && (dog[dognum]->earlyspeed() == 3)) score[dognum]-=5; else if ((runpts == -10) && (dog[dognum]->earlyspeed() >= 4)) score[dognum]-=10; else if ((runpts == -5) && (dog[dognum]->earlyspeed() >= 4)) score[dognum]-=5; } runpts = 0; } // BACK RUNNERS.... else if((dog[dognum]->runstyle() == 'b')||(dog[dognum]->runstyle() == 'B')) { score[dognum]+= (10 - round(dog[dognum]->oneeigth()) ); if (dog[dognum]->closingspeed() > topclose) topclose = dog[dognum]->closingspeed(); } for (dognum=0;dognum < 8;dognum++) if ((dog[dognum]->runstyle() == 'b')||(dog[dognum]->runstyle() == 'B')) score[dognum] += 20-round(10*(topclose - dog[dognum]->closingspeed())); // Points for Kennel??? // Adj Total for (dognum=0;dognum < 8;dognum++) if (score[dognum] > topscore) topscore = score[dognum]; difference = 100 - topscore; for (dognum=0;dognum < 8;dognum++) score[dognum]+= difference; for (dognum=0;dognum < 8;dognum++) cout << " Number " << (dognum+1) << " dog gets a " << score[dognum] << endl; // CLEANUP ins.close(); for(dognum=0;dognum < 8;dognum++) delete dog[dognum]; // pause program cin.ignore(); cin.ignore(); return EXIT_SUCCESS; } //---------------------------------------------------------- int round(float num) { if ((num - (float)(floor(num))) < .5) return floor(num); else return ceil(num); }