Question

Write a Date class that contains 3 integer data members (month, day, year) along with the...

Write a Date class that contains 3 integer data members (month, day, year) along with the appropriate methods (functions) that would allow you to write a main function that does the following:

Declare a date called today, that contains today’s date: 9, 25, 2019

Declare a date called tomorrow but don’t send it any data values.

Call the setValues() method on tomorrow to set tomorrow’s date.

Write a C++ print statement to print the following to the screen:

                today’s day is 25

    tomorrow’s day is 26

Declare a date called yesterday but don’t send it any data values.

Call the setDay() method on yesterday to set yesterday’s day to 24.

Write a C++ print statement to print the following to the screen:

                yesterday’s day was 24

    

Add a C++ print statement to the destructor that simply says “inside destructor”.

Add a C++ print statement to your constructor(s) that says which constructor is being invoked.

Your final output should look like the following:

inside overloaded constructor
inside default constructor
today's day is: 25
tomorrow's day is: 26
inside default constructor
yesterday's day was: 24
inside destructor
inside destructor
inside destructor

Homework Answers

Answer #1

Thanks for the question.


Here is the completed code for this problem.

Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please rate the answer. Thanks


===========================================================================

#include<iostream>
using namespace std;


class Date{
   public:
   Date();
   Date(int,int,int);
   int getMonth();
   int getDay();
   int getYear();
   void setMonth(int);
   void setDay(int);
   void setYear(int);
   ~Date();
   private:
       int month;
       int day;
       int year;
};


   Date::Date() {
       month=1;
       day=1;year=1900;
       cout<<"Inside default constructor\n";
   }
   Date::Date(int m,int d,int yr){
       month=m;
       day=d;
       year=yr;
       cout<<"Inside overloaded constructor\n";
   }
   int Date::getMonth(){
       return month;
   }
   int Date::getDay(){
       return day;
   }
   int Date::getYear(){
       return year;
   }
   void Date::setMonth(int m){
       month=m;
   }
   void Date::setDay(int d){
       day=d;
   }
   void Date::setYear(int yr){
       year=yr;
   }
   Date::~Date(){
       cout<<"Inside destructor\n";
   }
  
  
int main(){
   //Declare a date called today, that contains today’s date: 9, 25, 2019
   Date today = Date(9,25,2019);
   //Declare a date called tomorrow but don’t send it any data values.
   Date tomorrow = Date();
   //Call the setValues() method on tomorrow to set tomorrow’s date.
   tomorrow.setDay(26);
   tomorrow.setMonth(9);
   tomorrow.setYear(2019);
   //Write a C++ print statement to print the following to the screen:
   cout<<"today\s day is "<<today.getDay()<<endl;
   cout<<"tomorrow\s day is "<<tomorrow.getDay()<<endl;
  
   //Declare a date called yesterday but don’t send it any data values.
   Date yesterday = Date();
   //Call the setDay() method on yesterday to set yesterday’s day to 24.
   yesterday.setDay(24);
   //Write a C++ print statement to print the following to the screen:
   cout<<"yesterday\s day is "<<yesterday.getDay()<<endl;
  
  
  
}

thank U !

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions