Question: In C++ . Implement class Aggregation. MUST be in 3 files .h, .cpp and main. Using Dynamic ARRAY, no struct or other code format. Implement
In C++ . Implement class Aggregation.
MUST be in 3 files .h, .cpp and main. Using Dynamic ARRAY, no struct or other code format.
Implement a class named PersonalBest using this information.Implement the operators as needed. Use the information and code below as reference
Personal Best
Write a program class that asks for the name of a pole vaulter and the dates and vault heights (in meters) of the athletes three best vaults. It should then report, in order of height (best first), the date on which each vault was made and its height.
Input Validation: Only accept values between 2.0 and 5.0 for the heights.
a. Implement an attribute of type MyString that stores the player's name.
b. Implement a dynamic array where you will store the heights and dates in
those that the player jumps were made.
c. Use the Date version class with operators (Deitel) to simulate the dates of
each of the player's jumps.( code below )
d. Order the heights from greatest to least.
2. Implement the PersonalBest class as part of the class composition
PersonalBestArray made up of n number of players.
3. Perform the Sort Algorithm within said class
4. Implement the operators (<<, >>, <,>, []) inside the class PersonalBestArray ( use ostream << and istream >> )
5. Implement a menu of options to perform:
a. Add a player.
b. Eliminate a player.
c. Do a search for a specific player.
6. Include Constructors, Copy Constructors, mutators, accessors, and operators in your
implementation.
class DATE TEXT CODE
#ifndef DATE_H
#define DATE_H
#include
using namespace std;
class Date
{
friend ostream &operator<<( ostream &, const Date & );
public:
Date( int m = 1, int d = 1, int y = 1900 ); // default constructor
void setDate( int, int, int ); // set month, day, year
Date &operator++(); // prefix increment operator
Date operator++( int ); // postfix increment operator
const Date &operator+=( int ); // add days, modify object
static bool leapYear( int ); // is date in a leap year?
bool endOfMonth( int ) const; // is date at the end of month?
private:
int month;
int day;
int year;
static const int days[]; // array of days per month
void helpIncrement(); // utility function for incrementing date
}; // end class Date
#endif
// Date.cpp
// Date class member- and friend-function definitions. #include
#include
#include "Date.h"
using namespace std;
// initialize static member; one classwide copy
const int Date::days[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// Date constructor
Date::Date( int month, int day, int year ) {
setDate( month, day, year );
} // end Date constructor
// set month, day and year
void Date::setDate( int mm, int dd, int yy ) {
if ( mm >= 1 && mm <= 12 ) month = mm;
else
throw invalid_argument( "Month must be 1-12" );
if ( yy >= 1900 && yy <= 2100 ) year = yy;
else
throw invalid_argument( "Year must be >= 1900 and <= 2100" );
//
if
test for a leap year
((month==2&&leapYear(year)&&dd>=1&&dd<=29)|| ( dd >= 1 && dd <= days[ month ] ) )
day = dd;
else
throw invalid_argument(
"Day is out of range for current month and year" ); } // end function setDate
// overloaded prefix increment operator
Date &Date::operator++()
{
helpIncrement(); // increment date
return *this; // reference return to create an lvalue } // end function operator++
// overloaded postfix increment operator; note that the
// dummy integer parameter does not have a parameter name
Date Date::operator++( int ) {
Date temp = *this; // hold current state of object helpIncrement();
// return unincremented, saved, temporary object
return temp; // value return; not a reference return } // end function operator++
// add specified number of days to date
const Date &Date::operator+=( int additionalDays ) {
for ( int i = 0; i < additionalDays; ++i ) helpIncrement();
return *this; // enables cascading } // end function operator+=
// if the year is a leap year, return true; otherwise, return false
bool Date::leapYear( int testYear ) {
if ( testYear % 400 == 0 ||
( testYear % 100 != 0 && testYear % 4 == 0 ) ) return true; // a leap year
else
return false; // not a leap year
} // end function leapYear
// determine whether the day is the last day of the month
bool Date::endOfMonth( int testDay ) const {
if ( month == 2 && leapYear( year ) )
return testDay == 29; // last day of Feb. in leap year
else
return testDay == days[ month ];
} // end function endOfMonth
// function to help increment the date
void Date::helpIncrement() {
// day is not end of month
if ( !endOfMonth( day ) ) ++day; // increment day
else if(month<12)//day {
++month; // increment
day=1; // first day }//endif
else // last day of year {
is end of month and month < 12
month
of new month
++year; // increment year
month = 1; // first month of new year day = 1; // first day of new month
} // end else
} // end function helpIncrement
// overloaded output operator
ostream &operator<<( ostream &output, const Date &d ) {
static string monthName[ 13 ] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
output << monthName[ d.month ] << ' ' << d.day << ", " << d.year;
return output; // enables cascading
} // end function operator<<
// Date class test program.
#include
#include "Date.h" // Date class definition
using namespace std;
int main() {
Date d1( 12, 27, 2010 ); // December 27, 2010
Date d2; // defaults to January 1, 1900
cout << "d1 is " << d1 << " d2 is " << d2;
cout << " d1 += 7 is " << ( d1 += 7 );
d2.setDate( 2, 28, 2008 );
cout<<" d2is"< cout << " ++d2 is " << ++d2 << " (leap year allows 29th)"; Date d3( 7, 13, 2010 ); cout << " Testing the prefix increment operator: " <<" d3is"< cout << "++d3 is " << ++d3 << endl; cout<<" d3is"< cout << " Testing the postfix increment operator: " <<" d3is"< cout << "d3++ is " << d3++ << endl; cout<<" d3is"< }//endmain
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
