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

PROGRAMMING QUESTION (10 points) A) Write Date, Time, and DateTime classes, as 1

ID: 3605196 • Letter: P

Question

PROGRAMMING QUESTION (10 points) A) Write Date, Time, and DateTime classes, as 1. Date has year, month, and day member variables. 2. Time has hour, minute, and second member variables. 3. DateTime is an aggregate of Date and Time. 4. DateTime has redefin two Date Time objects. sa redefined operator, which computes the number of seconds between Assu clock (no AM and PM). me all months have 30 days, all years have 360 days, and Time objects are on a 24-hour B) Write a main program that creates two Date Time objects and displays the number of seconds between them, using the redefined operator.

Explanation / Answer

#include <iostream>

using namespace std;

int first_date_month;

int first_date_days;

int first_date_year;

int second_date_month;

int second_date_days;

int second_date_year;

int days;

int month_days[] = {31,28,31,30,31,30,31,31,30,31,30,31};

int main()

{

    cout << "Enter first date: ";

    cin >> first_date_year >> first_date_month >> first_date_days;

    cout << "Enter second date: ";

    cin >> second_date_year >> second_date_month >> second_date_days;

    if(first_date_year == second_date_year)

    {

        if(first_date_month == second_date_month)

            days = second_date_days - first_date_days;

        else

        {

            for(int i = first_date_month; i < second_date_month-1;i++)

                days += month_days[i];

            days += month_days[first_date_month-1] - first_date_days + second_date_days;

        }

    }

    else

    {

        for(int i = 0; i < second_date_month-1; i++)

            days += month_days[i];

        for(int i = first_date_month; i < 12; i++)

            days += month_days[i];

        if(second_date_year - first_date_year >= 0)

        days += (second_date_year - first_date_year - 1)*365 +

            month_days[first_date_month-1] - first_date_days + second_date_days;

    }

    cout << "Days between the two dates: " << days;

    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