Derive class weekday from class datetime

Assignment Help C/C++ Programming
Reference no: EM13719781

Any 4 TASK need to be done

Task 1

Given:
class DateTime{
public:
DateTime(int y, int m, int d, int h = 0, int min = 0, int s = 0);
void display();
protected:
string get_string_component(char option, tm* dateStruct);
int get_year_days(tm* dateStruct);
struct tm DTstruct;
private:
bool validate_data( int y, int m, int d, int h, int min, int s);
};

string DateTime::get_string_component(char component, tm* dateStruct){
char format[3];
format[0] = '%';
format[1] = component;
format[2] = '\0';

char ans [80];
strftime(ans, 80, format, dateStruct);
string strans(ans);
return strans;
}

int DateTime::get_year_days(tm* DTstruct){
return DTstruct->tm_yday;
}

Implement member functions
- DateTime(int y, int m, int d, int h = 0, int min = 0, int s = 0);

Assign proper values to DTStruct members using the (default) arguments.

y should be a four digit integer and DTstruct.tm_year is a two digit integer.
  E.g. user input 1994, DTstruct.tm_year is 94.
  E.g. user input 2015, DTstruct.tm_year is 15.
m is from 1 to 12, but DTstruct.tm_mon is from 0 to 11.
d and DTstruct.tm_mday have the same value.
h and DTstruct.tm_hour have the same value.
min and DTstruct.tm_min have the same value.
s and DTstruct.tm_sec have the same value.
DTstruct.tm_wday, DTstruct.tm_yday and DTstruct.tm_isdst will be set to 0 initially.
Re-adjust values in DTstruct.

- void display();
Display the local date and time of DTstruct.

- bool validate_data( int y, int m, int d, int h, int min, int s);
return true if all parameter values are all valid;
return false when one or more data are invalid;
a false return will invoke the exit(EXIT_FAILURE) function call and display
the following error message:
"Incompatible data!"
Validation criteria:

We can retrieve any one of the date-time structure member using strftime(). Refer to Assignment 1 for options available.

You have to provide:
- a header file datetime.h with code to prevent multiple inclusion.
- an class implementation file datetime.cpp.
- a text file task_2_1.txt containing compilation messages and sample runs.

Task 2

Derive class WeekDay from class DateTime such that WeekDay::display() will display local date time using values from the parameters and the corresponding weekday. For a handy online weekday calculator: What Day is this Date?

class WeekDay : public DateTime {

public:
WeekDay(int y, int m, int d, int h = 0, int min = 0, int s = 0);
void display();
};

Implement

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

Validate the parameter values the same ways as in DateTime().
- void display();
display the local date time and the corresponding weekday.

You have to provide:
- a header file weekday.h with code to prevent multiple inclusion.
- an class implementation file weekday.cpp.
- a text file task_2_2.txt containing compilation messages and sample runs.

Task 3

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.

Task 4
Derive class Days2Go from class DateTime such that Days2GoAge::display() will display birthdate in local date time format using values from the parameters and the number of days before your next birthday. The current date used in the sample run is assumed to be 15/04/2015.

class Days2Go : public Age {
public:
Days2Go(int y, int m, int d, int h = 0, int min = 0, int s = 0);
void display();
private:
int days;
};

Implement
- Days2Go(int y, int m, int d, int h = 0, int min = 0, int s = 0); 2016 is a leap year.
Birth year may be a leap year. You have to consider 29 Feb.
- 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 days2go.h with code to prevent multiple inclusion.
- an class implementation file days2go.cpp.
- a text file task_2_4.txt containing compilation messages and sample runs.

Task 5

Write a C++ program that stores information for date-time objects including DateTime, WeekDay, Age, and Days2Go objects. The program will display all the object information using the display() function provided by the objects.

Note
- Use a single vector to store information for all objects. Arrays, and other data structures are not allowed.
- When displaying information, the corresponding display() function of the object should be used.
E.g. DateTime object will display local date time and Age object will display birthdate, current date and age.
- You may have to modify the class interface(s) to enable polymorphism.
- There is no need to implement error exception.
- Adjust current date to 15 Apr 2015.
- You have to submit date.h, date.cpp, task_2_5.cpp and task_2_5.txt containing compilation messages and sample runs.
- Dates to be stored:
DateTime: 1990, Jan, 7, 14:15:16
DateTime: 2000, Mar, 14, 14:15
DateTime: 2015, Apr, 15, 14 hour
DateTime: 2015, Apr, 10
DateTime: 2015, Feb, 16
DateTime: 2000, Feb, 16

WeekDay: 1990, Jan, 7, 14:15:16
WeekDay: 2000, Mar, 14, 14:15
WeekDay: 2015, Apr, 15, 14 hour
WeekDay: 2015, Apr, 10
WeekDay: 2015, Feb, 16
WeekDay: 2000, Feb, 16

Age: 1990, Jan, 7, 14:15:16
Age: 2000, Mar, 14, 14:15
Age: 2015, Apr, 15, 14 hour
Age: 2015, Apr, 10
Age: 2015, Feb, 16
Age: 2000, Feb, 16

Days2Go: 1990, Jan, 7, 14:15:16
Days2Go: 2000, Mar, 14, 14:15
Days2Go: 2015, Apr, 15, 14 hour
Days2Go: 2015, Apr, 10
Days2Go: 2015, Feb, 16
Days2Go: 2000, Feb, 16

Verified Expert

The solution file is prepared in c++ language which implemented date time , weak days, age and day2 go classes. The date.h header file contain the all classes of declaration of the methods. And also implement the array to store the all classes of the objects and print the date and time with age. The solution file contains the three files are date.h,datetime.cpp and task_2.5.txt.

Reference no: EM13719781

Questions Cloud

Explore the effectives of the federal air marshalls program : The Federal Air Marshalls Program. In your opinion, how effective is it? Give one example of how this layer of security would work successfully.
Estimate time required to provide a laboratory procedure : estimate the time required to provide a given laboratory procedure, suppose that we measured the amount of time required when the service was provided on 60 occasions.
Explain the ethical dilemma and how to resolves it : What is the ethical dilemma here and how would YOU resolves it? Use the 4 wise men approach. Give an example of conflict between two of the 7 ethical duties of an engineer.
Derive class weekday from class datetime : We can retrieve any one of the date-time structure member using strftime - Derive class WeekDay from class DateTime such that WeekDay::display() will display local date time using values from the parameters and the corresponding weekday.
Explain the development of digital technologies : Has the development of digital technologies democratized the art of photography? How has this affected our appreciation of the photographer as artist and photography as an art form?
Explain the ethical theories described by baase : Define and compare at least two of the ethical theories described by Baase. What are their strengths? In what areas do they lack? Do these theories hold up within our modern, technological society?
Mental disorders : Analyze the factors (both genetic and environmental) contributing to the development of a specific mental disorder (of your choice). Discuss steps that could be taken to reduce the incidence of the disorder that you had identified above. Be sur..

Reviews

inf719781

5/30/2017 5:39:11 AM

Hi any word on when I will receive task 5. It has been 20hrs. Please read what it asks for. I have been supplied one file Ide.cpp. The task states. You have to submit date.h, date.cpp, task_2_5.cpp and task_2_5.txt containing compilation messages and sample runs. When displaying information, the corresponding display() function of the object should be used. E.g. DateTime object will display local date time and Age object will display birthdate, current date and age. The following is the marking criteria. Use of vector Use of iterator Storing data Retrieving data Polymorphic form of display() Compilation messages and sample run outputs (if the program runs correctly). Thanks for separating full code into header file date.h , date.cpp and task-2_5_.cpp file. I have found included array (vector ) to store all classes of objects. Thanks for your work.

Write a Review

C/C++ Programming Questions & Answers

  Prepare a program for a company named retail-martbullprompt

prepare a program for a company named retail-mart.bullprompt the user to enter an item name one word only a quantity

  Describe the process replace a do...while loop with an equiv

Describe the process you would use to replace a do...while loop with an equivalent while loop. What problem occurs when you try to replace a while loop with an equivalent do...while loop? Suppose you have been told that you must remove a while loop a..

  The "continue" and "break" statements

How are the "continue" and "break" statements different from the "exit" and "return" statements?

  Program that prompts the user to enter the weight of person

The program should output the desired result. However, the program contains logic errors. Find and correct the logic errors so that the program works properly.

  Print out the sum of all numbers, the average

Write a program that reads in a list of integer numbers and print out the sum of all numbers, the average, the lowest and the highest value entered. The first input number indicates how many numbers the program is attempting to read

  Give a recursive definition of s.

Let S be the set of positive integers that can be written as a sum of one or more 4's and/or 7's. For example, 7 ? S and 18 ? S (because 18 = 4 + 7 + 7)

  Set of nested for loops

Use a set of nested for loops to display the letters "R" and "B" in patterns as they might appear on a checkerboard.

  Rationalnumber class a rational number is a number that can

rationalnumber class a rational number is a number that can be represented as the quotient of two nbspintegers. for

  Design a simple game of blackjack

Prepare a simple game of blackjack using object oriented programming.

  Write equivalent compound statements

What action must be taken before a variable can be used in a program?

  Prints the row sums and the column sums

Write a program that reads a 5 x 5 array of integers and then prints the row sums and the column sums

  Explain one 1 scenario not mentioned in the textbook in

q1. describe one 1 scenario not mentioned in the textbook in which it would be advantageous for you to use a definite

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd