Running the Race
Write a program that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place. Input Validation: Only accept positive numbers for the times.
Instruction:
Implement:
1. Redefine stream operators.
2. Oveloaded constructors functions.
3. Mutator functions.
4. Accessor functions.
5.class for time
6.class for name
Program must have 2 classes working in composition between each other
show answer in C++
Please Answer using the techniques from the following example
#ifndef _MAGIC_DATE_H #define _MAGIC_DATE_H #include using namespace::std; #include "Date.h"; class MagicDate { private: Date date; public: MagicDate(int month, int day, int year); int getYear() const; bool getMagicDay() const; void display() const; }; #endif ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include #include using namespace::std; #include "MagicDate.h" MagicDate::MagicDate(int month, int day, int yeary) :date(month, day, yeary) {} int MagicDate::getYear() const { //cambio a do digito int twoDigitsYear; string yyyy; yyyy = to_string(date.getYear()); char yyTemp[3]; yyTemp[0] = yyyy[2]; yyTemp[1] = yyyy[3]; yyTemp[2] = '\0'; twoDigitsYear = atoi(yyTemp); return twoDigitsYear; } bool MagicDate::getMagicDay() const { if (date.getMonth() * date.getDay() == getYear()) return true; else return false; } void MagicDate::display() const { if (getMagicDay()) { cout << "The " << date << " is a magic date "; } else { cout << "The " << date << " is not magic date "; } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + #ifndef _DATE_H #define _DATE_H class Date { private: int month, day, year; public: //Constructores Date(); Date(int aMonth, int aDay, int aYear); //Copy Constructor Date(const Date& aDate); //Destructor ~Date(); //Mutators void setMonth(int aMonth); void setDay(int aDay); void setYear(int aYear); //Accessor int getMonth() const; int getDay() const; int getYear() const; //Funcion que imprime la fecha void displayDate() const; void helpIncrement(); bool endOfMonth(int testDay); bool leapYear(int testYear); Date& operator++(); // prefix increment operator Date operator++(int); // postfix increment operator bool operator==(const Date& obj); friend ostream& operator << (ostream& strm, const Date& obj); friend istream& operator >> (istream& strm, Date& obj); static const int days[]; // array of days per month }; #endif ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + #include #include using namespace::std; #include "MagicDate.h" MagicDate::MagicDate(int month, int day, int yeary) :date(month, day, yeary) {} int MagicDate::getYear() const { //cambio a do digito int twoDigitsYear; string yyyy; yyyy = to_string(date.getYear()); char yyTemp[3]; yyTemp[0] = yyyy[2]; yyTemp[1] = yyyy[3]; yyTemp[2] = '\0'; twoDigitsYear = atoi(yyTemp); return twoDigitsYear; } bool MagicDate::getMagicDay() const { if (date.getMonth() * date.getDay() == getYear()) return true; else return false; } void MagicDate::display() const { if (getMagicDay()) { cout << "The " << date << " is a magic date "; } else { cout << "The " << date << " is not magic date "; } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include using namespace::std; #include "MagicDate.h" int main() { MagicDate myBirthday1(2, 10, 1920); myBirthday1.display(); MagicDate myBirthday2(2, 10, 1921); myBirthday2.display(); system("pause"); return 0; }