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

The class dateType defined in Programming Exercise 6 prints the date in numerica

ID: 3858023 • Letter: T

Question

The class dateType defined in Programming Exercise 6 prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2017. Derive the class extDateType so that the date can be printed in either form. Add a member variable to the class extDateType so that the month can also be stored in string form. Add a member function to output the month in the string format, followed by the year—for example, in the form March 2017. Write the definitions of the functions to implement the operations for the class extDateType.

Programming Exercise 6 is this:

In Programming Exercise 2, the class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined:
a. Set the month. b. Set the day. c. Set the year. d. Return the month. e. Return the day. f. Return the year.

Programming exercise 2 is this :

In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class!!!!

It would be great if I could have the answer for question number 8!!!The first one!! The other questions are for reference!!! It's in C++

Explanation / Answer

Header file (Date.h)

#ifndef Date_H

#define Date_H

#include <iostream>

class Date

{

private:

            int month;

            int day;

            int year;          

public:

            Date();

            Date(int m, int d, int y);

            void setDate(int m, int d, int y);

            void getDate(int &m, int &d, int &y) const;

            void showDate() const;

            bool isLeap(int y) const;

            bool CheckDate(int m, int d, int y) const;

};

#endif  

Implementation file (Date.cpp)

#include <iostream>

#include "Date.h"

using namespace std;

void Date::setDate(int month, int day, int year)

{

            cout << "Enter Month: ";

                        cin >> month;

                        cout << endl;

                        cout << "Enter Day: ";

                        cin >> day;

                        cout << endl;

                        cout << "Enter Year: ";

                        cin >> year;

                        cout << endl;              

}

Date::Date(int m, int d, int y)

{

if(CheckDate(month, day, year))

{

   month = m;

   day = d;

   year = y;

}

else

{

   cout << "error" << endl;

   month = 1;

   day = 1;

   year = 2000;

}

}

void Date::getDate(int &m, int &d, int &y) const

{

            m = month;

            d = day;

            y = year;

}

void Date::showDate() const

{

   cout << month << '/' << day << '/' << year;

}

bool Date::CheckDate(int month, int day, int year) const

{

    bool result = true;

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

    if(year<1850||year>2100)

                        result = false;

            if (isLeap(year))

    {

        daysInMonths[1] = 29;  

    }

    if (month < 1 || month > 12)

    {

        result = false;

    }

    else if (day < 1 || day > daysInMonths[month-1])

    {

        result = false;

    }

    return result;

}

bool Date::isLeap(int year) const

    {

    if (year%4==0 && year%100!=0 || year%400==0)

        return true;

    else

        return false;

            }

Main fiel (DateDriver.cpp)

#include <iostream>

using namespace std;

#include "Date.h"

int main()

{

            char choice;

            do

            {

                        int month, day, year;

                        Date userInput(month =1, day =1, year =2003);

                        userInput.getDate(month, day, year);

            cout <<"The date you entered is: ";

            userInput.showDate();

            cout << " Would you like to enter another date?(Y/N)" << endl;

      cin >> choice;

            }

      while(choice != 'n' && choice != 'N');

}

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