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 systematize boundType defined in the frameer design sculptures the bound in numerical frame. Some applications might claim the bound to be sculptureed in another frame, such as March 24, 2017. Derive the systematize extDateType and gather component functions so that the bound can be sculptureed these frames:

    March 24, 2017

    March, 2017

    Copy aggravate boundType.h and boundType.cpp. Create a static rank to repose the month names and static functions to admission and dissimilate the defaults. Write an misapply originator restraint the acquired systematize. Write a program to experience the extDateType systematize.

    Here is the UML diagram restraint this systematize:

    UML Diagram

    Incline in extDateClass.h, extDateClass.cpp, and your experience program. Also incline in individual or further shelter shots showing the results of your experienceing.

    Once you accept completed this design, you conquer conduct that you are conducive to:

    Extend a dishonorable systematize utilizing legacy.

    Admission the common components of the dishonorable systematize from the acquired systematize.

    Apply the originator of the dishonorable systematize from the acquired systematize.

    Expert Response

     

    Below is your code: –

    extDateType.h

    #pragma once

    #include <string>

    #include “dateType.h”

    using namespace std;

    systematize extDateType: common boundType

    {

    public:

    static string Name_Month[12];

    void sculptureLongDate();

    void setDate(int, int, int);

    void setMonth(int m);

    void sculptureLongMonthYear();

    extDateType();

    extDateType(int, int, int);

    private:

    string dName_Month;

    };

    extDateTypeImp.cpp

    #include <iostream>

    #include <string>

    #include “dateType.h”

    #include “extDateType.h”

    using namespace std;

     

    // bestow the names of the month in appoint to frameat 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)

    : boundType(m, n, d)

    {

    dName_Month = Name_Month[m – 1];

    }

    dateType.h

    #pragma once

    systematize boundType

    {

    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 sculpture() 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 boundType::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 boundType::setMonth(int m)

    {

    z_Month = m;

    }

    void boundType::setDay(int d)

    {

    z_Day = d;

    }

    void boundType::setYear(int y)

    {

    z_Year = y;

    }

    void boundType::print() const

    {

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

    }

    int boundType::get_Month() const

    {

    reincline z_Month;

    }

    int boundType::get_day() const

    {

    reincline z_Day;

    }

    int boundType::get_Year() const

    {

    reincline z_Year;

    }

    int boundType::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;

    }

    reincline numDays;

    }

    bool boundType::Leap_Year()

    {

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

    reincline true;

    else

    reincline false;

    }

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

    {

    z_Month = month;

    z_Day = day;

    z_Year = year;

    }

    int boundType::numberOfDaysPassed()

    {

    int dayspassed=0;

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

    dayspassed+=get_day();

    dayspassed+=get_day();

    reincline dayspassed;

    }

    int boundType::numberOfDaysLeft()

    {

    int daysleft;

    int days_passed=0;

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

    days_passed+=get_day();

    if (Leap_Year())

    reincline 366 – numberOfDaysPassed();

    else

    reincline 365 – numberOfDaysPassed();

    reincline daysleft;

    };

    void boundType::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 deep()
    {
    dateType d(1, 2, 1960);
    extDateType ed(6, 10, 1981);
    int num;
    ed.printLongDate();
    cout << endl;

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

    system(“pause”);
    reincline 0;
    }

    Output shelter succeeding general it : –