We're Open
support@instaresearch.co.uk
+44 7340 9595 39
+44 20 3239 6980

DO NOT MODIFY DATETIME AND AGE CLASS PUBLIC AND PROTECTED SECTIONS

Information



  • Post Date 2020-04-04T09:56:58+00:00
  • Post Category Assignment Queries

No Plagiarism Guarantee - 100% Custom Written

Order Details

DO NOT MODIFY DATETIME AND AGE CLASS PUBLIC AND PROTECTED SECTIONS

In this paper, you are required to provide a header file age.h with code to prevent multiple inclusion and an class implementation file age.cpp. You are asked not to modify DateTime and Age class public and protected sections. You may add private members (data/functions) only. Furthermore, You have to include the code for class DateTime in age.h and age.cpp.

 

Derive class Age from class DateTime such that Age::display() will display birthdate in local date time format using values from the parameters, the current time and the age.

class Age : public DateTime {

public:

// Date supplied is birth date, should be earlier than current date

Age(int y, int m, int d, int h = 0, int min = 0, int s = 0);

void display();

protected:

struct tm Astruct;   // tm for current time private:

string int_2_string(int);

void error_action();

string age;

};

string Age::int_2_string(int n){

ostringstream outstr;

if (n > 100000){

outstr << (n - 100000);

return outstr.str() + " days old.";

} else if (n > 1000){

outstr << (n - 1000);

return outstr.str() + " months old.";

} else {

outstr << n;

return outstr.str() + " years old.";

}

}

 

void Age::error_action(){

cout << "Birthday must be in the past!n";

exit(EXIT_FAILURE);

}

 

Implement

    Age(int y, int m, int d, int h = 0, int min = 0, int s = 0);

    Validate parameter values the same way as in class DateTime.

      When calculating age, the unit can be day, month or year. To differentiate the units, add 1,000 to age in months, add 100,000 to age in days. When passed to int_2_string, we can convert the age to proper values and units.

    void display();

      Display the local date time created as birthdate; the current date and the age calculated using the birthdate and the current date.

You have to provide:

    a header file age.h with code to prevent multiple inclusion.

    an class implementation file age.cpp.

    a text file task_2_3.txt containing compilation messages and sample runs. Note

    You have to include the code for class DateTime in age.h and age.cpp.

    You may include the code for class WeekDay in age.h and age.cpp.

 

      Do not modify DateTime and Age class public and protected sections. You may add private members (data/functions) only.

    There is no need to implement error exception.

 

You may use sample_AGE_app.cpp to test your implementation. Expected output:

 

C:>a

Birthday: 12/25/94 03:04:05

Current date: 04/15/15 15:17:15

Age is 22 years old.

 

Birthday: 12/25/94 03:04:00

Current date: 04/15/15 15:17:15

Age is 22 years old.

 

Birthday: 12/25/94 03:00:00

Current date: 04/15/15 15:17:15

Age is 22 years old.

 

Birthday: 12/25/94 00:00:00

Current date: 04/15/15 15:17:15

Age is 22 years old.

 

Birthday: 04/15/15 00:00:00

Current date: 04/15/15 15:17:15

Age is 1 days old.

 

Birthday: 04/01/15 00:00:00

Current date: 04/15/15 15:17:15

Age is 15 days old.

 

Birthday: 03/15/15 00:00:00

Current date: 04/15/15 15:17:15

Age is 2 months old.

 

Birthday: 12/25/14 00:00:00

Current date: 04/15/15 15:17:15

Age is 2 years old.

 

Birthday: 01/25/14 00:00:00

Current date: 04/15/15 15:17:15

Age is 2 years old.

 

You should also use your own test cases to test for error inputs.

 

Marking Criteria

Marks

Age() and display()

12

age.h with code to prevent multiple inclusion.

2

age.cpp

4

Compilation messages and sample run outputs (if the program runs correctly)

2

 

 

 


Price: £ 109

100% Plagiarism Free & Custom Written, Tailored to your instructions