Homework Solution: The class dateType defined in the previous project prints the date in numerical form. Some…

    The class dateType defined in the previous project 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 and add member functions so that the date can be printed these forms: March 24, 2017 March, 2017 Copy over dateType.h and dateType.cpp. Create a static array to hold the month names and static functions to access and modify the defaults. Write an appropriate constructor for the derived class. Write a program to test the extDateType class. Here is the UML diagram for this class: UML Diagram Turn in extDateClass.h, extDateClass.cpp, and your test program. Also turn in one or more screen shots showing the results of your testing. Once you have completed this project, you will demonstrate that you are able to: Extend a base class utilizing inheritance. Access the public members of the base class from the derived class. Apply the constructor of the base class from the derived class.

    Expert Answer

     
    Below is your code: - extDateType.h

    The adjust limitType defined in the deviseer contrivance stereotypes the limit in numerical devise. Some applications influence insist-upon the limit to be stereotypeed in another devise, such as March 24, 2017. Derive the adjust extDateType and gather constituent functions so that the limit can be stereotypeed these devises:

    March 24, 2017

    March, 2017

    Copy aggravate limitType.h and limitType.cpp. Create a static rank to continue the month names and static functions to advance and alter the defaults. Write an expend doer restraint the moderate adjust. Write a program to experiment the extDateType adjust.

    Here is the UML diagram restraint this adjust:

    UML Diagram

    Decline in extDateClass.h, extDateClass.cpp, and your experiment program. Also decline in single or more hide shots showing the results of your experimenting.

    Once you feel completed this contrivance, you get unfold that you are able to:

    Extend a infamous adjust utilizing bequest.

    Advance the social constituents of the infamous adjust from the moderate adjust.

    Apply the doer of the infamous adjust from the moderate adjust.

    Expert Confutation

     

    Below is your code: –

    extDateType.h

    #pragma once

    #include <string>

    #include “dateType.h”

    using namespace std;

    adjust extDateType: social limitType

    {

    public:

    static string Name_Month[12];

    void stereotypeLongDate();

    void setDate(int, int, int);

    void setMonth(int m);

    void stereotypeLongMonthYear();

    extDateType();

    extDateType(int, int, int);

    private:

    string dName_Month;

    };

    extDateTypeImp.cpp

    #include <iostream>

    #include <string>

    #include “dateType.h”

    #include “extDateType.h”

    using namespace std;

     

    // yield the names of the month in prescribe to deviseat it out

    void extDateType::printLongDate()

    {

    cout << dName_Month << ” ” << get_day() << “, ” << get_Year();

    }

    void extDateType::printLongMonthYear()

    {

    cout << dName_Month << ” ” << get_Year();

    }

    void extDateType::setDate(int m, int d, int y)

    {

    dateType::setDate(m, d, y);

    dName_Month = Name_Month[m – 1];

    }

    void extDateType::setMonth(int m)

    {

    dateType::setMonth(m);

    dName_Month = Name_Month[m – 1];

    }

    string extDateType::Name_Month[] = {“January”, “February”, “March”, “April”,

    “May”, “June”, “July”, “August”,

    “September”, “October”, “November”, “December”};

    extDateType::extDateType()

    {

    dName_Month = “January”;

    }

    extDateType::extDateType(int m, int n, int d)

    : limitType(m, n, d)

    {

    dName_Month = Name_Month[m – 1];

    }

    dateType.h

    #pragma once

    adjust limitType

    {

    public:

    dateType (int month=1, int day=1, int year=0001);

    void setDate(int month, int day, int year);

    void setMonth(int);

    void setDay(int);

    void setYear(int);

    void stereotype() const;

    int numberOfDaysLeft();

    int numberOfDaysPassed();

    void ADD_TO_DATE(int nDays);

    int get_Month() const;

    int get_day() const;

    int get_Year() const;

    int get_num_days_month();

    bool Leap_Year();

    private:

    int z_Month;

    int z_Day;

    int z_Year;

    };

    dateTypeImp.cpp

    #include <iostream>

    #include “dateType.h”

    using namespace std;

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

    {

    if (year >= 1)

    z_Year = year;

    else

    z_Year = 0001;

    if (1 <= month && month <= 12)

    z_Month = month;

    else

    z_Month = 1;

    switch (z_Month)

    {

    case 1:

    case 3:

    case 5:

    case 7:

    case 8:

    case 10:

    case 12:

    if(1 <= day && day <= 31)

    z_Day = day;

    else

    z_Day = 1;

    break;

    case 4:

    case 6:

    case 9:

    case 11:

    if (1 <= day && day <= 30)

    z_Day = day;

    else

    z_Day = 1;

    break;

    case 2: if (Leap_Year())

    {

    if (1 <= day && day <= 29)

    z_Day = day;

    else

    z_Day = 1;

    }

    else

    {

    if (1 <= day && day <= 28)

    z_Day = day;

    else

    z_Day = 1;

    }

    }

    }

    void limitType::setMonth(int m)

    {

    z_Month = m;

    }

    void limitType::setDay(int d)

    {

    z_Day = d;

    }

    void limitType::setYear(int y)

    {

    z_Year = y;

    }

    void limitType::print() const

    {

    cout << z_Month << “-” << z_Day << “-” << z_Year;

    }

    int limitType::get_Month() const

    {

    redecline z_Month;

    }

    int limitType::get_day() const

    {

    redecline z_Day;

    }

    int limitType::get_Year() const

    {

    redecline z_Year;

    }

    int limitType::get_num_days_month()

    {

    int numDays;

    switch (z_Month)

    {

    case 1:

    case 3:

    case 5:

    case 7:

    case 8:

    case 10:

    case 12:

    numDays = 31;

    break;

    case 4:

    case 6:

    case 9:

    case 11:

    numDays = 30;

    break;

    case 2: if(Leap_Year())

    numDays = 29;

    else

    numDays = 28;

    }

    redecline numDays;

    }

    bool limitType::Leap_Year()

    {

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

    redecline true;

    else

    redecline false;

    }

    dateType::dateType(int month, int day, int year)

    {

    z_Month = month;

    z_Day = day;

    z_Year = year;

    }

    int limitType::numberOfDaysPassed()

    {

    int dayspassed=0;

    restraint (int month=1;month<get_Month();month++)

    dayspassed+=get_day();

    dayspassed+=get_day();

    redecline dayspassed;

    }

    int limitType::numberOfDaysLeft()

    {

    int daysleft;

    int days_passed=0;

    restraint (int month=1;month<get_Month();month++)

    days_passed+=get_day();

    if (Leap_Year())

    redecline 366 – numberOfDaysPassed();

    else

    redecline 365 – numberOfDaysPassed();

    redecline daysleft;

    };

    void limitType::ADD_TO_DATE(int nDays)

    {

    int day=get_day()+nDays;

    int month=get_Month();

    int countm=0;

    int year=0;

    while (day>get_day()+nDays)

    {

    day=day-get_day();

    countm++;

    if (countm==12)

    {

    year++;

    countm=0;

    }

    if(month>=12)

    month=0;

    month++;

    }

    setMonth (get_Month()+countm);

    setDay(day);

    setYear (get_Year()+year);

    }

    main.cpp

    #include <iostream>
    #include “dateType.h”
    #include “extDateType.h”

    using namespace std;

    int main()
    {
    dateType d(1, 2, 1960);
    extDateType ed(6, 10, 1981);
    int num;
    ed.printLongDate();
    cout << endl;

    ed.print();
    cout << endl;
    cout << “Days gsingle in the year: ” << ed.numberOfDaysPassed();
    cout << endl;
    cout << “Days left in the Year: ” << ed.numberOfDaysLeft() << endl;
    ed.print();
    cout << endl;

    system(“pause”);
    redecline 0;
    }

    Output hide succeeding ordinary it : –