1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
Daryian Johnson
Horses.cpp
This program should output the data of ten different horses saved into an array created in a single class.
It should then display the best, worst, and average times of all of the horses.
*/
//////////////////////////////////////
#include <iostream>
#include <cstdlib>
using namespace std;
//////////////////////////////////////
class Horse
{
private:
string name;
int lane;
double Time;
public:
Horse()
{
name = "";
lane = 0;
Time = 0.0;
}
Horse(string n, int l, double t)
{
name = n;
lane = l;
Time = t;
}
/////////////////////GET FUNCTIONS//////////////////////////////////
string getName()
{
return name;
}
int getLane()
{
return lane;
}
double getTime()
{
return Time;
}
////////////////////SET FUNCTIONS////////////////////////////////////
void setName(string n)
{
name = n;
}
void setLane(int l)
{
lane = l;
}
void setTime(double t)
{
Time = t;
}
//////////////////////PRINT FUNCTION///////////////////////////////////
void printHorse()
{
cout << "Horse " << name << " is in lane " << lane;
cout << " with a time of " << Time << "." << endl;
cout << "--------------------------------------------------------------\n";
}
};
//////////////////////BEST TIME FUNCTION///////////////////////////////////
double leBest(Horse horse[])
{
double best = 50.0;
for(int x=0;x<10;x++)
{
if(best >= horse[x].getTime())
best = horse[x].getTime();
}
return best;
}
//////////////////WORST TIME FUNCTION/////////////////////////////////////
double leWorst(Horse horse[])
{
double worst = 40;
for(int x=0;x<10;x++)
{
if(worst <= horse[x].getTime())
worst = horse[x].getTime();
}
return worst;
}
///////////////////AVERAGE FUNCTION////////////////////////////////////
double leAverage(Horse horse[])
{
double ave = 0;
for(int x=0; x<10; x++)
{
ave += horse[x].getTime();
}
ave /= 10;
return ave;
}
///////////////////MAIN FUNCTION////////////////////////////////////
int main()
{
Horse horse[10];
horse[0] = Horse("American", 1, 45.41);
horse[1] = Horse("Bababooey", 2, 42.42);
horse[2] = Horse("Charlie", 3, 40.94);
horse[3] = Horse("Dog", 4, 43.55);
horse[4] = Horse("Echo", 5, 41.41);
horse[5] = Horse("Firefox", 6, 42.58);
horse[6] = Horse("Google", 7, 41.98);
horse[7] = Horse("Hoof", 8, 44.57);
horse[8] = Horse("Ima", 9, 41.57);
horse[9] = Horse("Just", 10, 45.88);
double aveTime = leAverage(horse);
double bestTime = leBest(horse);
double worstTime = leWorst(horse);
cout << "Welcome to the Horse Track! Place your bets and take your seats!\n" << endl;
system("PAUSE");
cout << endl;
for(int x=0;x<10;x++)
{
horse[x].printHorse();
}
cout << "Average Time = " << aveTime << endl;
cout << "Best Time = " << bestTime << endl;
cout << "Worst Time = " << worstTime << endl;
cin.get();
return EXIT_SUCCESS;
}
|