logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

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

expert
rajat mehtaFinance
(/5)

697 Answers

Hire Me
expert
Riya ChopraComputer science
(5/5)

778 Answers

Hire Me
expert
Nawaaj KhanEducation
(5/5)

561 Answers

Hire Me
expert
Samantha JiNursing
(5/5)

868 Answers

Hire Me
Data structures & Algorithms

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;

}

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme