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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
class Athlete
{
protected:
int competition_number;
std::string name,discipline;
float BestOfYear, BestOfCareer;
double NumOfCompetitions;
static int numOfAthletes;
public:
std::string GetName() { return name; }
void SetName(std::string name) { this->name = name; }
int GetCompetitionNumber() { return competition_number; }
void SetCompetitionNumber() {
competition_number = rand() % 1000 + 1;
this->competition_number = competition_number;
};
float GetBestOfYear() { return BestOfYear; }
float GetBestOfCareer() { return BestOfCareer; }
std::string GetDiscipline() { return discipline; }
void SetDiscipline(std::string discipline) { this->discipline = discipline;}
void SetAll(std::string, string, float, float, double);
Athlete(std::string, string, float, float, double);
Athlete();
~Athlete();
static int GetNumOfAthletes() { return numOfAthletes; }
void ToString();
void AddSingleAthlete();
void AddMultipleAthletes();
float RandomResultSprint(float, float);
void ShowAll(std::vector<Athlete>athletes);
std::vector<Athlete> athletes;
};
int Athlete::numOfAthletes = 0;
Athlete::Athlete(std::string name, std::string discipline, float BestOfYear,
float BestOfCareer, double NumOfCompetitions) {
this->name = name;
this->discipline = discipline;
this->BestOfYear = BestOfYear;
this->BestOfCareer = BestOfCareer;
this->NumOfCompetitions = NumOfCompetitions;
SetCompetitionNumber();
Athlete::numOfAthletes++;
}
Athlete::Athlete() {
this->name = "";
this->discipline = "";
this->BestOfYear = 0;
this->BestOfCareer = 0;
this->NumOfCompetitions = 0;
SetCompetitionNumber();
Athlete::numOfAthletes++;
}
Athlete::~Athlete()
{
std::cout << "Athlete " << this->name << " deleted\n";
}
void Athlete::ToString() {
std::cout <<"Athlete with competition number "<<this->competition_number<< " has the name " <<
this->name << " .\n"<<this->name<<" is competeing in " <<
this->discipline << " and "<<this->name<<" has participated in " <<
this->NumOfCompetitions << " World Competitions. "<<
"\n"<<this->name<<"'s best result for this year is "<<this->BestOfYear<<
" while the best for his career is "<<this->BestOfCareer<<"\n\n";
}
void Athlete::AddSingleAthlete(){
std::string Name;
std::string Discipline;
float bestOfYear, bestOfCareer;
double NumOfParticipations;
int Answer = 1;
do
{
cout << "Enter the info of the Athlete bellow:\n";
cout << "Athlete's name: ";
cin >> Name;
cout << endl << "Athlete's discipline: ";
cin >> Discipline;
cout << endl << "Athlete's best result for the current season: ";
cin >> bestOfYear;
cout << endl << "Athlete's best result for the whole career: ";
cin >> bestOfCareer;
cout << endl << "Athlete's number of World Competitions: ";
cin >> NumOfParticipations;
cout << endl << "Do you wish to add another athlete?\n1: Yes\n0: No\n";
cin >> Answer;
Athlete nqkoi(Name, Discipline, bestOfYear, bestOfCareer, NumOfParticipations);
athletes.push_back(nqkoi);
} while (Answer != 0);
}
void Athlete::AddMultipleAthletes() {
std::string Name;
std::string Discipline;
float bestOfYear, bestOfCareer;
double NumOfParticipations;
int Answer = 1;
int numOfAthletes = 0;
do
{
cout << "How many athletes would you like to add to each discipline?\n";
cin >> numOfAthletes;
for (int b = 0; b < numOfAthletes; b++)
{
cout << "\nEnter the info of the Athletes bellow (one at a time):\n";
cout << "Athlete's name: ";
cin >> Name;
cout << endl << "Athlete's discipline: ";
cin >> Discipline;
cout << endl << "Athlete's best result for the current season: ";
cin >> bestOfYear;
cout << endl << "Athlete's best result for the whole career: ";
cin >> bestOfCareer;
cout << endl << "Athlete's number of World Competitions: ";
cin >> NumOfParticipations;
Athlete nqkoi(Name, Discipline, bestOfYear, bestOfCareer, NumOfParticipations);
athletes.push_back(nqkoi);
}
cout << endl << "Do you wish to add another athlete?\n1: Yes\n0: No\n";
cin >> Answer;
} while (Answer == 1);
}
float Athlete::RandomResultSprint(float BestOfYear, float BestOfCareer)
{
float RandMax, RandMin, Result;
for (int a = 0; a < athletes.size(); a++)
{
Athlete& nqkoi = athletes.at(a);
RandMin = nqkoi.GetBestOfYear() * 0.8;
RandMax = nqkoi.GetBestOfCareer() * 1.1;
RandMin = RandMin * 100;
RandMax = RandMax * 100;
//cout << RandMax << " " << RandMin << endl;
do
{
Result = rand() % (int)RandMax + RandMin;
} while (Result > RandMax || Result < RandMin);
Result = (float)Result;
Result = Result / 100;
cout << "The randomly generated result for " << nqkoi.name << "is " << Result << endl;
}
return Result;
}
int main()
{
srand(time(NULL));
int choice;
int choiceAdd;
const int Add_choice = 1,
Show_choice = 2,
Run_choice = 3,
Medals_choice = 4,
Check_choice = 5,
Quit_choice = 6;
Athlete edin;
do{
cout << "Please choose an option:" << endl << endl
<< "1. Add an athlete/athletes" << endl
<< "2. Show all athletes" << endl
<< "3. Run a competition" << endl
<< "4. Table with medals (Only choose after you have ran a competition)" << endl
<< "5. Athletes check (Ordered by age or name)" << endl
<< "6. Quit/Exit" << endl;
cin >> choice;
while (choice<Add_choice || choice>Quit_choice)
{
cout << "Please enter a valid menu choice (1 to 6): ";
cin >> choice;
};
if (choice != Quit_choice)
{
switch (choice)
{
case Add_choice:
cout << "Please choose an option:" << endl << endl
<< "1. One athlete for each discipline" << endl
<< "2. List of athletes for each discipline" << endl;
cin >> choiceAdd;
while (choice<1 || choice>2)
{
cout << "Please enter a valid menu choice (1 to 6): ";
cin >> choiceAdd;
};
switch (choiceAdd)
{
case 1:
edin.AddSingleAthlete();
break;
case 2:
edin.AddMultipleAthletes();
break;
}
case Show_choice:
edin.ShowAll(edin.athletes);
break;
case Run_choice:
edin.RandomResultSprint(edin.GetBestOfYear(), edin.GetBestOfCareer());
break;
}
}
}while (choice != Quit_choice);
std::cout << "Number of athletes is " << Athlete::GetNumOfAthletes() << "\n";
return 0;
}
|