Question: https://www.cs.uky.edu/~kwjoiner/cs215/exams/lex2/lex2_review.pdf Coding Standards: - No global variables or objects are allowed (global constants are OK) - All class Data Members must be private. Function Members

https://www.cs.uky.edu/~kwjoiner/cs215/exams/lex2/lex2_review.pdf

Coding Standards: - No global variables or objects are allowed (global constants are OK) - All class Data Members must be private. Function Members (Methods) may be public or private. - Do not use friend classes. Specifications: Write and execute a complete C++ program in MS Visual Studio according to the following specifications. Write all code in one .cpp file (though we would normally make a .h and .cpp for each class). Remember the principle of Define Before Usewrite the class interface before/above any use of the class name. horse: write a class that describes the record of a race horse. A horse has a name, a color, and a partial array of up to 30 race times recorded in seconds (integers). Each race time is the number of seconds it took the horse to finish a race. Use a constant for the MAX. You may assume the name and color have no spaces. Write the following methods: - Constructor: sets strings to empty string and numbers to zero. - Standard get and set methods for name and color. Standard get for number of races. - AddRace method that is given a race time and appends it to the list. It should print an error when unable to add the given race time. - Get method for a single race, that is given the index of the race in the list to retrieve. Return 0 when the given index is invalid, or return the single race time when the given index is valid. - A getAvgTime method that calculates and returns the average of the race times in the array. Return 0 when the number of races is 0. This average should be a double (though it is an average of integers. So race times 100 and 101 average to 100.5) stable: write a class that describes a Stable (a set of horses owned by one person/farm/group). A Stable has a stable name and a home town. (ie. LuckyFarm and Lexington), along with a partial array of up to 20 horse objects (use a constant for the MAX). You may assume there are no spaces in the stable name or hometown. Write the following methods: - Constructor: sets strings to empty string and numbers to zero. - ReadFile: reads data from a text file called indata.txt and loads it into the data members. When the file fails to open, print a message and exit the method. There are no spaces in any names, so you do not need to use getline() at any point. The file has data for one stable, multiple horses, with multiple races for each horse, although the number of races will be the same for all horses. The file format is as follows: Line 1: stable name, hometown, number of horses, number of races for each horse. For each horse: one line that contains the horses name and color, followed by a list of race times. All horses have the same number of races (specified on line 1) and the number of horses in the stable is on line 1. Sample input file: Castlebrook Lexington 4 5 4 horses, 5 races for each horse SummerRain black 149 138 155 166 144 Pokey white 205 222 213 199 228 StarOfLex bay 158 167 189 202 168 FastFrank chestnut 137 142 173 135 153 Hint: o Read stable name, hometown, number of horses, number of races o For each horse: ? Read horse name and color ? Set these in the next available horse object ? For each race time ? Read it ? Add it to races in the next available horse object - WriteReport: writes a report to an output file called report.txt It should print an error message when the file fails to open. Format: Line 1: contains the stable name followed by the hometown in parenthesis For each horse: one line of data formatted as: o Average: 1 digit past the decimal point in a field width of 5, right justified, followed by a space. ( << fixed << right << setprecision(1) << setw(5) ) o Horse name in a field width of 15, left justified, followed by a space o Horse color in parenthesis Sample output file: Castlebrook (Lexington) 150.4 SummerRain (black) 213.4 Pokey (white) 176.8 StarOfLex (bay) 148.0 FastFrank (chestnut) Main: use the following main() to test your program: int main() { stable s; s.readFile(); s.writeReport(); cout << "Done! "; system("pause"); return 0; } Of course, your program should work for any valid number of horses and races. Here is another example: indata.txt Castlebrook Lexington 5 6 5 horses, 6 races per horse SummerRain black 149 138 155 166 144 159 Pokey white 205 222 213 199 228 203 StarOfLex bay 158 167 189 202 168 177 FastFrank chestnut 137 142 173 135 153 157 ManOWar bay 122 133 155 144 111 128 report.txt Castlebrook (Lexington) 151.8 SummerRain (black) 211.7 Pokey (white) 176.8 StarOfLex (bay) 149.5 FastFrank (chestnut) 132.2 ManOWar (bay)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!