Develop a class called Date which will involve a variety of operator overloads. A Date object will store a date in terms of day of month, month and year. You will overload some basic operators for use with these objects, including arithmetic, comparison, and insertion/extraction (I/O) operators. The Date class must allow for storage of a non-negative quantity of date, in terms of day of month, month and year which will be expressed in the normal date format e.g. 18-4-2018 means 18 April 2018. All values should be non-negative. The day of month should be a correct value e.g. 30th in February is not possible. You should create appropriate member data in your class. All member data must be private. Constructors: • The class should have a default constructor (no parameters), which should initialize the Date as 1-1-1900 • The Date class should also have a constructor with 3 parameters representing day of month, month and year e.g. Date d; //creates a date object initialized to 1-1-1900 Date d2(1, 12, 2017)//create a date object corresponding to 1st December 2017 OPERATOR OVERLOADING: Overload the stream insertion operator << for outputting the Date object Overload the stream extraction operator>> for reading Date object from an input stream. Overload the following comparison operators (<, >, ==, !=) which should return true or Write the main function that would create objects of Date and demonstrates use of all the operators discussed above. A sample main function is given below: int main() { Date d1, Date d2(1,2,2017); cin>>d1; if(d1
Develop a class called Date which will involve a variety of operator overloads. A Date object will
store a date in terms of day of month, month and year. You will overload some basic operators for use
with these objects, including arithmetic, comparison, and insertion/extraction (I/O) operators.
The Date class must allow for storage of a non-negative quantity of date, in terms of day of
month, month and year which will be expressed in the normal date format e.g. 18-4-2018
means 18 April 2018. All values should be non-negative. The day of month should be a
correct value e.g. 30th in February is not possible. You should create appropriate member data
in your class. All member data must be private.
Constructors:
• The class should have a default constructor (no parameters), which should initialize
the Date as 1-1-1900
• The Date class should also have a constructor with 3 parameters representing day of
month, month and year
e.g.
Date d; //creates a date object initialized to 1-1-1900
Date d2(1, 12, 2017)//create a date object corresponding to 1st December 2017
OPERATOR OVERLOADING:
- Overload the stream insertion operator << for outputting the Date object
- Overload the stream extraction operator>> for reading Date object from an
input stream. - Overload the following comparison operators (<, >, ==, !=) which should return true or
Write the main function that would create objects of Date and demonstrates use of all the
operators discussed above. A sample main function is given below:
int main()
{ Date d1,
Date d2(1,2,2017);
cin>>d1;
if(d1<d2)
cout<<”date”<<d1<<”is before the date ”<<d2<<endl;
if(d1==d2)
cout<<”both dates are the same” <<endl;
cout<<d2<<endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images