Design a class called Date. The class should store a date in three integers: mon
ID: 3539231 • Letter: D
Question
Design a class called Date. The class should store a date in three integers: month, day, and year.
Create a member function to display the date in the following format: December 25, 2005
Create both a default constructor and an overloaded constructor. The default one should initialize the date to January 1, 2000, and the overloaded one should take arguments for the month, day, and year.
Create accessors and mutators (gets and sets) for the member variables.
Overload the prefix and postfix ++ operators to increment the date. When a date is set to the last day of the month and incremented, it should become the first day of the following month. If the date is December 31, the incremented date should become January 1 of the following year.
Overload the prefix and postfix -- operators to decrement the date. When a date is set to the first day of the month, and decremented, it should become the last day of the previous month. If the date is January 1, the decremented date should become December 31 of the previous year.
Overload the stream insertion operator (<<) to display the date in the format: December 25, 2005.
Overload the stream extraction operator (>>) to prompt the user for a date to be stored.
Design a class called FutureDate that is derived from the Date class you have created. This class should not allow the user to store a date earlier than today's date. If the user enters a date earlier than today, display a message and let the user re-enter the date.
Create only one constructor, an overloaded constructor that accepts values for the month, day, and year, in that order, and initializes the object to that date. The constructor should prompt the user if the date is before today's date.
The decrement operators (prefix and postfix) should be overridden. Do not allow the date to be decremented so it is before today's date. Just keep the current date if decrementing it would put it in the past.
The following code snippet displays today's date.
Demonstrate the classes by using the chapter13_15.cpp driver program. This file should not need to be modified except where commented. If your classes don't work with the driver, modify your classes to work with it.
---Below is the chapter13_15.cpp driver---
#include"Date.cpp" //Use your file name here
#include"FutureDate.cpp" //Use your file name here
#include<iostream>
#include<cstdlib> //for system command
using namespace std;
void main()
{
int response = 0;
Date myDate;
FutureDate myFutureDate(7, 31, 2100); //month, day, year
cout << "Calling stream extraction operator for the Date object." << endl;
cin >> myDate;
cout << "Calling stream insertion operator for the Date object." << endl;
cout << myDate << endl;
cout<<"Calling stream extraction operator for the FutureDate object." << endl;
cin >> myFutureDate;
cout << "Calling stream insertion operator for the FutureDate object." << endl;
cout << myFutureDate << endl;
do
{
cout << "What would you like to do to date 2?" << endl;
cout << "1 - Prefix increment (++) operator" << endl;
cout << "2 - Postfix increment (++) operator" << endl;
cout << "3 - Prefix decrement (--) operator" << endl;
cout << "4 - Postfix decrement (--) operator" << endl;
cout << "0 - Exit" << endl;
cin >> response;
switch(response)
{
case 1:
cout << "Before increment: " << myFutureDate <<endl;
cout << "After increment: " << ++myFutureDate << endl;
break;
case 2:
cout << "Before increment: " << myFutureDate <<endl;
cout << "After increment: " << myFutureDate++ << endl;
break;
case 3:
cout << "Before decrement: " << myFutureDate <<endl;
cout << "After decrement: " << --myFutureDate << endl;
break;
case 4:
cout << "Before decrement: " << myFutureDate <<endl;
cout << "After decrement: " << myFutureDate-- << endl;
break;
case 0:
break;
default:
cout << "Invalid choice" << endl;
}
}while(response);
system("PAUSE");
}
Explanation / Answer
Date Class C++ I need help with this assignment. I got some done for the input validation but im having problems to understand classes. Ill provide the code below. Design a class called Date that has integer data members to store month, day, and year. The class should have a three-parameter default constructor that allows the date to be set at the time a new Date object is created. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e., January 1, 2001) should be used. The class should have member functions to print the date in the following formats: 3/15/10 March 15, 2010 15 March 2010 Demonstrate the class by writing a program that uses it. Input Validation: Only accept values between 1 and 12 for the month, between 1 and 31 for the day, and between 1950 and 2020 for the year. #include #include using namespace std; class date { private: int day; private: int month; private: int year; }; int main() { int day; int month; int year; cout 31)) { day = 1; } cout 12));{ month = 1; } cout 2020)){ year = 2001; } system("pause"); return 0; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.