DO NOT MODIFY DATETIME AND AGE CLASS PUBLIC AND PROTECTED SECTIONS
The primary theme of the paper is DO NOT MODIFY DATETIME AND AGE CLASS PUBLIC AND PROTECTED SECTIONS in which you are required to emphasize its aspects in detail. The cost of the paper starts from $109 and it has been purchased and rated 4.9 points on the scale of 5 points by the students. To gain deeper insights into the paper and achieve fresh information, kindly contact our support.
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
|
100% Plagiarism Free & Custom Written
Tailored to your instructions