Define , implement and test a class Date using C++ with following specifications

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 8PE
icon
Related questions
Question
100%

Define , implement and test a class Date using C++ with following specifications

The Date class consists of three private member variables:
No. Member Variable
1 year
Description
An int variable that holds the value of a year.
An int variable that holds the value of a month.
An int variable that holds the value of a day.
2
month
3
day
The Date class has the following public member functions:
Description
No. Member Function
Constructor with Initializes year, month, and day with three int arguments. The default
default
1
values for the year, month, and day are 2001, 1, and 1, respectively.
Data validation must be provided as in setDate.
Initializes year, month, and day of a new Date object with an
existing Date object.
Returns the value in year.
Returns the value in month.
Returns the value in day.
Sets the year, month and day with three int arguments. Data validation
should be provided as follows.
1) A valid year should be between 1900 and 2020, otherwise use 2001
for the year.
| 2) A valid month should be between 1 and 12, otherwise use 1 for the
parameters
2 Copy Constructor
getYear
getMonth
getDay
month.
3) A valid day should be between
• 1 and 31 if the month is 1, 3, 5, 7, 8, 10, or 12, (which means there
are 31 days in January, March, May, July, August, October, and
December.)
• 1 and 30 if the month is 4, 6, 9, or 11.
• 1 and 28 if the month is 2, i.e., simply assume there are 28 days in
February.
Use 1 for any invalid value.
Outputs the year, month, and day in the format of MM-DD-YYYY.
Compares two Date objects' values and returns true if they are the
same, otherwise returns false.
setDate
7
print
8
equals
m
Transcribed Image Text:The Date class consists of three private member variables: No. Member Variable 1 year Description An int variable that holds the value of a year. An int variable that holds the value of a month. An int variable that holds the value of a day. 2 month 3 day The Date class has the following public member functions: Description No. Member Function Constructor with Initializes year, month, and day with three int arguments. The default default 1 values for the year, month, and day are 2001, 1, and 1, respectively. Data validation must be provided as in setDate. Initializes year, month, and day of a new Date object with an existing Date object. Returns the value in year. Returns the value in month. Returns the value in day. Sets the year, month and day with three int arguments. Data validation should be provided as follows. 1) A valid year should be between 1900 and 2020, otherwise use 2001 for the year. | 2) A valid month should be between 1 and 12, otherwise use 1 for the parameters 2 Copy Constructor getYear getMonth getDay month. 3) A valid day should be between • 1 and 31 if the month is 1, 3, 5, 7, 8, 10, or 12, (which means there are 31 days in January, March, May, July, August, October, and December.) • 1 and 30 if the month is 4, 6, 9, or 11. • 1 and 28 if the month is 2, i.e., simply assume there are 28 days in February. Use 1 for any invalid value. Outputs the year, month, and day in the format of MM-DD-YYYY. Compares two Date objects' values and returns true if they are the same, otherwise returns false. setDate 7 print 8 equals m
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning