in Object's data. For example, object hold 4/21/2022 as the date and if user of this object calls addDays (10) method, it will add 10 days to 4/21/2022 giving a new date of 5/1/2022. There can be more complicated scenarios if you add a lot of days (for example hundreds of days) due to possible rollover of year and months. You can limit number of days to be added to 100. Just like addDays, subtractDays method will subtract number of days from the current date. Provide implementation of both functions in the class. Also modify your main function as follows:

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

void Date: addDays (int n);

void Date: subtractDays(in n);

The addDays method will add n number of days to the current date that's

stored in Object's data. For example, object hold 4/21/2022 as the date and if

user of this object calls addDays (10) method, it will add 10 days to

4/21/2022 giving a new date of 5/1/2022. There can be more complicated

scenarios if you add a lot of days (for example hundreds of days) due to

possible rollover of year and months. You can limit number of days to be

added to 100.

Just like addDays, subtractDays method will subtract number of days from

the current date.

Provide implementation of both functions in the class. Also modify your

main function as follows:

int main()
{
std::cout << "Hello World!\n";
Date myDate(4, 21, 2022);
myDate.showDate();
myDate.addDays (10);
myDate.showDate();
myDate.subtractDays(9);
myDate.showDate();
myDate.addDays(100);
myDate.showDate();
myDate.subtractDays (100);
myDate.showDate();
return 1;
Transcribed Image Text:int main() { std::cout << "Hello World!\n"; Date myDate(4, 21, 2022); myDate.showDate(); myDate.addDays (10); myDate.showDate(); myDate.subtractDays(9); myDate.showDate(); myDate.addDays(100); myDate.showDate(); myDate.subtractDays (100); myDate.showDate(); return 1;
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage