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

The Questionis below a) Create an operator function for the Date class in Class

ID: 3688298 • Letter: T

Question

The Questionis below a) Create an operator function for the Date class in Class 11.1 that compares two Date objects and returns a Boolean value of true if the first date is larger than the second; otherwise, it should return a false value. The "larger than" algorithm for this comparison operator function is the following: Accept one date as the current object being evaluated and a second date as an argument Determine the later date with the following procedure: Convert each date to a long integer value in the form yyyymmdd, using the algorithm in Exercise 2 Compare the corresponding integers for each date if the first date's long integer value is larger than the second dates's long integer vlaue. return true Else return false the question is aboce and below is my code i have so far is below the only thing i can't figure out is what to do in the main and what to to about comparing the dates to see which is larger please help as soon as possible because it is due today for homewor before midnight pleasek

#include //std io stream library, keyboard and terminal window #include //file stream library, i/o of files #include //needed for exit function #include //needed for strings #include //needed for formatting #include //needed for vectors #include //needed for stl #include #include using namespace std; //declaration section class Date { private: int month; int day; int year; public: Date(int mm = 1, int dd = 1, int yyyy = 2014) //inline constructor {month = mm; day = dd; year = yyyy;} void setDate(int mm, int dd, int yy) //inline mutator {month = mm; day = dd; year = yy;} void showDate(); //accessor bool isLeapYear(); bool operator==(const Date&); bool checkDate(); long int convert(); }; //implementation section void Date::showDate() { cout << "The Date is " << setfill('0') << setw(2) << month << ' / ' << setw(2) << day << ' / ' << setw(2) << year % 100; cout << endl; } bool Date::isLeapYear() { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return true; } else { return false; } } bool Date::operator==(const Date& date2) { if (day == date2.day && month == date2.month && year == date2.year) { return true; } else { return false; } } long int Date::convert() { long int yyyymmdd = year * 10000 + month * 100 + day; return yyyymmdd; } bool Date::checkDate() { long int yyyymmdd1 = isLeapYear(); long int yyyymmdd2 = isLeapYear(); if (yyyymmdd1 > yyyymmdd2) { return true; } else { return false; } } int main() { Date a(2, 2, 2015); Date b(2, 2, 2016); cout << "The date is: " << a.showDate << endl; b.isLeapYear(); cout << "The leap year date is: " << b.showDate << endl; system("pause"); return 0; }

Explanation / Answer

I have removed the unnecessary functions and minimized the code, Pasted my code below.Please do check and let me know.

#include <iostream>
#include <time.h>
#include <string>
#include <iomanip>

using namespace std;
//declaration section
class Date
{
    private:
    int month;
    int day;
    int year;
    public:
    Date(int mm = 1, int dd = 1, int yyyy = 2014)
    //inline constructor
    {
        month = mm;
        day = dd;
        year = yyyy;
    }
    void setDate(int mm, int dd, int yy)
    //inline mutator
    {
        month = mm; day = dd; year = yy;
    }
    bool checkDate(Date&);
    long int convert();
};
    long int Date::convert()
    {
        long int yyyymmdd = this->year * 10000 + this->month * 100 + this->day;
        return yyyymmdd;
    }
    bool Date::checkDate(Date& d2)
    {
        long int date2= d2.convert();
        if (convert()>date2)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
int main()
{
    Date a(2, 2, 2015);
    Date b(2, 2, 2016);
    bool flag=a.checkDate(b);
    if(flag)
    cout<<"greater";
    else
    cout<<"lesser";
    cout<< endl;
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote