Program that stores information for date-time objects

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

Assignment consists of five tasks. For each task, you have to submit a .cpp file and a documentation file

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 <cstdlib> exit(EXIT_FAILURE) function call and display the following error message:
"Incompatible data!"

- Validation criteria:

 

Name

Validation Criteria

y

1970 <= y <= 2020

m

1 <= m <= 12

d

1 <= d <= 31

h

0 <= h <= 23

min

0 <= min <= 59

s

0 <= s <= 59

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. Note:
• Do not modify the DateTime 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_DT_app.cpp to test your implementation. Expected output:

C:\>a
01/02/15 03:04:05
01/02/15 03:04:00
01/02/15 03:00:00
01/02/15 00:00:00

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

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? https://www.timeanddate.com/date/weekday.html

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.

Note
• You have to include the code for class DateTime in weekday.h and weekday.cpp.
• Do not modify DateTime and WeekDay 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_WD_app.cpp to test your implementation. Expected output:

C:\>a
01/02/15 03:04:05 is Friday
01/02/15 03:04:00 is Friday
01/02/15 03:00:00 is Friday
01/02/15 00:00:00 is Friday

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

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. 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.

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. Note
• You have to include the code for class DateTime and class Age in days2go.h and days2go.cpp.
• Do not modify class DateTime, Age and Days2Go public and protected sections. You may add private members (data/functions) only.
• There is no need to implement error exception.

You may use sample_DTG_app.cpp to test your implementation. Assuming the current date is 15/04/2015, expected output:

C:\>a
Birthday: 04/14/94 00:00:00 Current date: 04/15/15 15:32:15 Days before next birthday: 364

Birthday: 04/15/94 00:00:00 Current date: 04/15/15 15:32:15 Days before next birthday: 0

Birthday: 04/16/94 00:00:00 Current date: 04/15/15 15:32:15 Days before next birthday: 1

Birthday: 05/15/00 00:00:00 Current date: 04/15/15 15:32:15 Days before next birthday: 30

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

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

...
• Expected output: (current date is 15 Apr 2015)

01/07/90 14:15:16
03/14/00 14:15:00
04/15/14 14:00:00
04/10/14 00:00:00
02/16/14 00:00:00
02/16/00 00:00:00
01/07/90 14:15:16 is Sunday 03/14/00 14:15:00 is Tuesday 04/15/14 14:00:00 is Monday 04/10/14 00:00:00 is Wednesday 02/16/14 00:00:00 is Saturday 02/16/00 00:00:00 is Wednesday Birthday: 01/07/90 14:15:16 Current date: 04/15/15 10:21:59 Age is 26 years old.

Birthday: 03/14/00 14:15:00 Current date: 04/15/15 10:21:59 Age is 16 years old.
Birthday: 04/15/15 14:00:00 Current date: 04/15/15 10:21:59 Age is 1 days old.
Birthday: 04/10/15 00:00:00 Current date: 04/15/15 10:21:59 Age is 6 days old.
Birthday: 02/16/15 00:00:00 Current date: 04/15/15 10:21:59 Age is 3 months old.
Birthday: 02/16/00 00:00:00 Current date: 04/15/15 10:21:59 Age is 16 years old.
Birthday: 01/07/90 14:15:16 Current date: 04/15/15 10:21:59 Days before next birthday: 267

Birthday: 03/14/00 14:15:00 Current date: 04/15/15 10:21:59 Days before next birthday: 333

Birthday: 04/15/15 14:00:00 Current date: 04/15/15 10:21:59 Days before next birthday: 0

Birthday: 04/10/15 00:00:00 Current date: 04/15/15 10:21:59 Days before next birthday: 360

Birthday: 02/16/15 00:00:00 Current date: 04/15/15 10:21:59 Days before next birthday: 307

Birthday: 02/16/00 00:00:00 Current date: 04/15/15 10:21:59 Days before next birthday: 307

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

Reference no: EM13908697

Questions Cloud

Why you have drawn your indifference curves as you have them : Draw in your indifference map (set of indifference curves). Explain why you have drawn your indifference curves as you have drawn them.
Draw the opportunity set and your indifference map : Draw the opportunity set and your indifference map. Show the optimum amount of consumption in each period.
Antuan company set the following standard costs : Antuan Company set the following standard costs for one unit of its product.
How you test market is efficient increased supply in stock : How would you test whether the market is efficient with respect to the potential increased supply in stock?
Program that stores information for date-time objects : Derive class WeekDay from class DateTime such that WeekDay::display() will display local date time using values from the parameters and the corresponding weekday.
Identify any ethical issues and legal issues : Identify any ethical issues and legal issues
Under which the use of the zero-beta model might lead : A number of different models can be used to estimate return. Derive the circumstances under which the use of the zero-beta model might lead to the market being considered inefficient when the standard CAPM indicated efficiency.
Implement the network using packet tracer : Implement the network using Packet Tracer - Calculate the EIGRP metric from R1 to network where PC2 is located. Explain and show how you derive at the values used in the calculation. Show detailed steps in arriving your answer.
Write a function uniq that removes duplicate entries : Write the function insertAt :: Int -> a -> [a] -> [a]. insertAt n x xs will insert the element x into the list xs at position n items from the beginning of xs. In other words, skip n items in xs, then insert the new element.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a program that inputs a line of text into char

8.6 (Displaying Strings in Uppercase and Lowercase) Write a program that inputs a line of text into char array s[100]. Output the line in uppercase letters and in lowercase letters.

  Tabulate unadjusted function points

a) List type of Input, output counts, File names, query and interfaces. Tabulate them into simple, medium and complex. b) Tabulate Unadjusted function points giving a total of them You can assume some data points or features as appropriate to drive y..

  Flipflapsthe project is to design and write a c 11fltk game

flipflapsthe project is to design and write a c 11fltk game program with a graphical user interface.the game is based

  You have to develop a basic temperature classnbsp base

you have to develop a basic temperature class.nbsp base skeleton code and a simple driver have been provided for

  Implementation of a priority queue

i) Describe in detail (using pseudocode) the implementation of a priority queue based on a sorted array. Show that your implementation achieves O(1) for operations min and removeMin, and O(n) for insertions.

  Heights of the individual pupils

Make a C++ program that helps the health visitor making the statistics and heights of the individual pupils,

  Create a bar chart showing the average monthly mean temperat

Write a ++ program to create a bar chart showing the average monthly mean temperature for College Station from 2004 to 2013. The point of the exercise is to compute the sie and location of the rectangles rather than explicitely hardcode that informat..

  Write a c program that copies the contents of one file

write a c program that copiest the contents of one file to a destination file. This program works by first prompting the user for the name of the source file and destination file.

  Prepare a businesspartner

Prepare a BusinessPartner class that contains a company name, first name and a telephone number.

  The bubble sort is also define as the ripple sort one

the bubble sort is also define as the ripple sort. one implementation of this sorting methods is to recurrently move

  Write the definition of the member function two of yclass

Write the definition of the member function two of yClass so that the private member variable a is initialized to the value of the first parameter of two, and the private member variable b is initialized to the value of the second parameter of two..

  Takes n number of element from user

Write a C program which takes n number of element from user (where, n is specified by user) and stores data in an array. Then, this program displays the largest element of that array.

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