Homework Solution: In this chapter, the class dateType was designed to implement the date in a program, b…

    Instructions 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. Input should be format month day year with each seperated by a space. Output should:
    Date #: month-day-year
    
    If the year is a leap year, print the date and a message indicating it is a leap year, otherwise print a message indicating that it is not a leap year. The header file for the class dateType has been provided for you. Where is the problem located? Here is my code //dateType.h #ifndef dateType_H #define dateType_H class dateType { private: int dMonth; int dDay; int dYear; public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters. //Postcondition: dMonth = month; dDay = day; //               dYear = year int getDay() const; int getMonth() const; int getYear() const; void printDate() const; //Function to output the date in the form mm-dd-yyyy. bool isLeapYear(int year); dateType(int month = 0, int day = 0, int year = 0); }; #endif //dateTypeImp.cpp #include <iostream> #include "dateType.h" using namespace std; void dateType::setDate(int month, int day, int year) { int noDays; if(year<=2008) { dYear=year; if(month<=12) { dMonth=month; switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: noDays=31; break; case 4: case 6: case 9: case 11: noDays=31; break; case 2: if(isLeapYear(year)) noDays=29; else noDays=28; } if(day<=noDays) { dDay=day; } else { cout<<"Invalid Day"<<endl; dDay=0; } } else { cout<<"Invalid Month"<<endl; dMonth=0; } } else { cout<<"Invalid Year"<<endl; dYear=0; } } bool dateType::isLeapYear(int year) { if(year%4==0) return true; else return false; } void dateType::printDate()const { cout<<dMonth<<"-"<<dDay<<"-"<<dYear; int dateType::getMonth()const; { return dMonth; } int dateType::getDay()const; { return dDay; } int dateType::getYear()const; { return dYear; } int dateType::dateType(int month, int day, int year) { dMonth=month; dDay=day; dYear=year; }; } //main.cpp #include<iostream> #include "dateType.h" using namespace std; int main() { int m,d,y; dateType date(0,0,0); cout<<"Enter Month"; cin>>m; cout<<"Enter day"; cin>>d; cout<<"Enter Year"; cin>>y; date.setDate(m,d,y); bool check =date.isLeapYear(y); if(check) cout<<"Leap Year:"; date.printDate(); system("pause"); }  

    Expert Answer

     
    Made changes only to dateTypeImpl.cpp file PROGRAM CODE:

    Instructions

    In this paragraph, the assort epochType was planned to utensil the epoch in a program, referable attributable attributablewithstanding the component office firmEpoch and the creator do referable attributable attributable attributable stop whether the epoch is weighty antecedently storing the epoch in the component variables. Retranscribe the definitions of the office firmEpoch and the creator so that the values restraint the month, day, and year are stoped antecedently storing the epoch into the component variables. Add a component office, isLeapYear, to stop whether a year is a jump year. Moreover, transcribe a examination program to examination your assort.

    Input should be restraintmat month day year with each seperated by a boundlessness. Output should:

    Epoch #: month-day-year
    

    If the year is a jump year, sculpture the epoch and a communication indicating it is a jump year, otherwise sculpture a communication indicating that it is referable attributable attributable attributable a jump year.

    The header rasp restraint the assort epochType has been supposing restraint you.

    Where is the collection located?

    Here is my code

    //dateType.h

    #ifndef epochType_H
    #define epochType_H

    assort epochType
    {
    private:
    int dMonth;
    int dDay;
    int dYear;
    public:
    void firmDate(int month, int day, int year);
    //Office to firm the epoch.
    //The component variables dMonth, dDay, and dYear are firm
    //according to the parameters.
    //Postcondition: dMonth = month; dDay = day;
    //               dYear = year

    int getDay() const;
    int getMonth() const;

    int getYear() const;

    void sculptureDate() const;
    //Office to output the epoch in the restraintm mm-dd-yyyy.

    bool isLeapYear(int year);

    dateType(int month = 0, int day = 0, int year = 0);

    };

    #endif

    //dateTypeImp.cpp

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

    using nameboundlessness std;

    void epochType::setDate(int month, int day, int year)
    {

    int noDays;
    if(year<=2008)
    {
    dYear=year;
    if(month<=12)
    {
    dMonth=month;
    switch(month)
    {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12: noDays=31;
    break;
    case 4:
    case 6:
    case 9:
    case 11: noDays=31;
    break;
    case 2: if(isLeapYear(year))
    noDays=29;
    else
    noDays=28;
    }
    if(day<=noDays)
    {
    dDay=day;
    }
    else
    {
    cout<<“Inweighty Day”<<endl;
    dDay=0;
    }
    }
    else
    {
    cout<<“Inweighty Month”<<endl;
    dMonth=0;
    }
    }
    else
    {
    cout<<“Inweighty Year”<<endl;
    dYear=0;
    }
    }

    bool epochType::isLeapYear(int year)
    {
    if(year%4==0)
    return true;
    else
    return false;
    }
    void epochType::printDate()const
    {
    cout<<dMonth<<“-“<<dDay<<“-“<<dYear;

    int epochType::getMonth()const;
    {
    return dMonth;
    }

    int epochType::getDay()const;
    {
    return dDay;
    }

    int epochType::getYear()const;
    {
    return dYear;
    }

    int epochType::dateType(int month, int day, int year)
    {
    dMonth=month;
    dDay=day;
    dYear=year;
    };
    }

    //main.cpp

    #include<iostream>
    #include “dateType.h”
    using nameboundlessness std;

    int ocean()
    {
    int m,d,y;
    dateType epoch(0,0,0);

    cout<<“Enter Month”;
    cin>>m;
    cout<<“Enter day”;
    cin>>d;
    cout<<“Enter Year”;
    cin>>y;
    date.setDate(m,d,y);
    bool stop =date.isLeapYear(y);
    if(check)
    cout<<“Jump Year:”;
    date.printDate();
    system(“pause”);
    }

     

    Expert Counter-argument

     

    Made changes merely to epochTypeImpl.cpp rasp

    PROGRAM CODE:

    #include <iostream>

    #include “dateType.h”

    using nameboundlessness std;

    //fixed some syntax issues connected to brackets

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

    {

    int noDays;

    if(year<=2008)

    {

    dYear=year;

    if(month<=12)

    {

    dMonth=month;

    switch(month)

    {

    case 1:

    case 3:

    case 5:

    case 7:

    case 8:

    case 10:

    case 12: noDays=31;

    break;

    case 4:

    case 6:

    case 9:

    case 11: noDays=30; //changed this to 30

    break;

    case 2: if(isLeapYear(year))

    noDays=29;

    else

    noDays=28;

    }

    if(day<=noDays)

    {

    dDay=day;

    }

    else

    {

    cout<<“Inweighty Day”<<endl;

    dDay=0;

    }

    }

    else

    {

    cout<<“Inweighty Month”<<endl;

    dMonth=0;

    }

    }

    else

    {

    cout<<“Inweighty Year”<<endl;

    dYear=0;

    }

    }

    //added logic restraint jump year

    bool epochType::isLeapYear(int year)

    {

    if((year % 400) == 0 || year%4==0)

    return true;

    else

    return false;

    }

    void epochType::printDate()const

    {

    cout<<“Epoch #: “<<dMonth<<“-“<<dDay<<“-“<<dYear;

    }

    int epochType::getMonth()const

    {

    return dMonth;

    }

    int epochType::getDay()const

    {

    return dDay;

    }

    int epochType::getYear()const

    {

    return dYear;

    }

    //calling firmepoch arrangement here to end weightyations

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

    {

    setDate(month, day, year);

    }

    int ocean()

    {

    int m,d,y;

    dateType epoch(0,0,0);

    cout<<“Enter Month: “;

    cin>>m;

    cout<<“Enter day: “;

    cin>>d;

    cout<<“Enter Year: “;

    cin>>y;

    date.setDate(m,d,y);

    bool stop =date.isLeapYear(y);

    date.printDate();

    if(check)

    cout<<” which is a jump Year”;

    else

    cout<<” which is referable attributable attributable attributable a jump year”;

    }

    OUTPUT: