logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Write a C++ class named Date having three data members day , month , year You class must have default and parameterized constructor

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Write a C++ class named Date having three data members:

  • day

  • month

  • year

 

Your class must have:

  1. A default and parameterized constructor. (use the following default date 2000-01-01)

  2. A function called setDate which takes 3 valid values for day, month, and year (Display an error message to the user when the given values are invalid).

  3. 3 functions getDay(), getMonth(), and getYear() .

    4.Overloaded << operator to display the date in the following format (YYYY-MM-DD)

  1. Overloaded >> operator to read three values for date, month, and

  2. Overloaded ++ operator to add a day to the current date

  3. Overloaded - - operator to subtract a day from the current date

    8. Overloaded logical operators: ( = = , != , > , and < ) Notes:

·        While adding and subtracting a day (Auto-increment and auto-decrement) keep in mind to adjust the date (e.g. adding one day to 2019-12-31 will give 2020-01-01).

  • The result of a logical operation is bool (true or false).

Use the following main function to test your code:

#include "Date.h" #include using namespace std; int main()

{

Date date1(31 , 1, 2019);

Date date2(1 , 3 , 2019);

Date date3(15 , 4 , 2019);

Date date4(15, 4, 2019); Date date5;

cout << "date1 :";

cout << "Day =" << date1.getDay();

cout << " , Month = " << date1.getMonth();

cout << " , Year = " << date1.getYear() << endl; cout << "date1 : " << date1 << endl;

cout << "date2 : " << date2 << endl; cout << "date3 : " << date3 << endl; cout << "date4 : " << date4 << endl; if (date1 == date2)

cout << "date1 is equal to date2" << endl; if (date1 != date2)

cout << "date1 is not equal to date2" << endl; if (date3 == date4)

cout << "date3 is equal to date4" << endl; if (date3 != date4)

cout << "date3 is not equal to date4" << endl; if (date1 < date2)

cout << "date1 is before date2" << endl; if (date3 > date1)

cout << "date3 is after date1" << endl;

 

cout << "date1 before auto-increment:" << date1 << endl; date1++;

cout << "date1 after auto-increment:" << date1 << endl; cout << "date2 before auto-decrement:" << date2 << endl; date2--;

cout << "date2 after auto-decrement:" << date2 << endl;

 

cin >> date5;

cout << "date5 :" << date5 << endl;

 

date1.setDate(1, 12, 2020);

cout << "date1 : " << date1 << endl; date1.setDate(29, 2, 2019); //invalid day cout << "date1 : " << date1 << endl; return 0;

}

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

565 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

903 Answers

Hire Me
expert
Husnain SaeedComputer science

598 Answers

Hire Me
expert
Atharva PatilComputer science

549 Answers

Hire Me

Get Free Quote!

417 Experts Online