Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. A class definition for a Date class that contains three integer data members:

ID: 3627412 • Letter: 1

Question

1. A class definition for a Date class that contains three integer data members: month, day, and year.

2. One constructor that assigns the date 1/1/2000 to any new object that does not receive any arguments.

3. One constructor that accepts month and day arguments and uses a default year of 2004.

4. One constructor that accepts month, day, and year arguments.

5. Each constructor should also output a message to the user stating which constructor is currently being used.

6. A method that displays the values in the Date object.

7. A Main() program in which you:

Instantiate three Date objects - create one for each type of constructor (no argument, 2-argument, 3-argument).

For the 2-argument and 3-argument constructor prompt the user for console input of the month, day or month, day, year.

Display output for each of the three constructor types.

8. Internal Documentation



Your output should look something like this:

Implementing overloaded constructors program
************************************
Using no-argument constructor, assigning date 1/1/2000
The date in this object is 1/1/2000
************************************
Enter a month eg: 10 for October: 10
Enter a day eg: 24: 24
Using 2-argument constructor, assigning year 2004
The date in this object is 10/24/2004
************************************
Enter a month eg: 10 for October: 8
Enter a day eg: 24: 25
Enter a year eg: 1950: 1951
Using 3-argument constructor, for mo/da/yr
The date in this object is 8/25/1951
************************************
Press any key to continue . . .

Explanation / Answer

Please rate!

#include <iostream> using namespace std; // define the classes class date { // 1. A class definition for a Date class that contains three integer data members: month, day, and year. private: int month, day, year; public: void print() const; date(); date(int, int); date(int, int, int); //5. Each constructor should also output a message to the user stating which constructor is currently being used. }; //2. One constructor that assigns the date 1/1/2000 to any new object that does not receive any arguments. date::date() { month = 1; day = 1; year = 2000; cout << "Using no-argument constructor, assigning date 1/1/2000"; } //3. One constructor that accepts month and day arguments and uses a default year of 2004. date::date(int m, int d) { month = m; day = d; year = 2004; cout << "Using 2-argument constructor, assigning year 2004"; } //4. One constructor that accepts month, day, and year arguments. date::date(int m, int d, int y) { month = m; day = d; year = y; cout << "Using 3-argument constructor, for mo/da/yr"; } //6. A method that displays the values in the Date object. void date::print() const { cout << " The date in this object is " << month << "/" << day << "/" << year; } /* 7. A Main() program in which you: Instantiate three Date objects - create one for each type of constructor (no argument, 2-argument, 3-argument). For the 2-argument and 3-argument constructor prompt the user for console input of the month, day or month, day, year. Display output for each of the three constructor types. */ int main() { cout << "Implementing overloaded constructors program"; cout << " ************************************ "; date d1; d1.print(); cout << " ************************************ "; int mo, da, yr; cout << "Enter a month eg: 10 for October: "; cin >> mo; cout << "Enter a day eg: 24: "; cin >> da; date d2(mo, da); d2.print(); cout << " ************************************ "; cout << "Enter a month eg: 10 for October: "; cin >> mo; cout << "Enter a day eg: 24: "; cin >> da; cout << "Enter a year eg: 1950: "; cin >> yr; date d3(mo, da, yr); d3.print(); cout << " ************************************" << endl; system("pause"); return 0; }