Answer to Question #188723 in C++ for Dunga

Question #188723

Write the class definition for a Date class that contains three integer data members: month, day and year. Include a default constructor that assigns the date 1/1/2000 to any new object that does not receive arguments. Also include a function that displays the Date object. Write a main() function in which you instantiate two Date objects – one that you create using the default constructor values, and one that you create using three arguments – and display its values.


1
Expert's answer
2021-05-03T17:06:01-0400
#include <iostream>

#include <string>



class Date

{

private:

    size_t _day;

    size_t _month;

    size_t _year;




public:

    void displayDate()

    {

        std::cout << _day << "/" << _month << "/" << _year << std::endl;

    }




    Date() : _day(1), _month(1), _year(2000) {};

    Date(size_t day, size_t month, size_t year) : _day(day), _month(month), _year(year) {};

    ~Date() {};

};




int main()

{

    Date dataDefault;

    dataDefault.displayDate();

    Date data(2, 2, 2002);

    data.displayDate();

    return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS