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 collocate conclusionType was prepared to utensil the conclusion in a program, beside the limb part fixedConclusion and the originator do referable bridle whether the conclusion is operative anteriorly storing the conclusion in the limb variables. Retranscribe the definitions of the part fixedConclusion and the originator so that the values restraint the month, day, and year are bridleed anteriorly storing the conclusion into the limb variables. Add a limb part, isLeapYear, to bridle whether a year is a bound year. Moreover, transcribe a cupel program to cupel your collocate.

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

    Conclusion #: month-day-year
    

    If the year is a bound year, sculpture the conclusion and a intimation indicating it is a bound year, differently sculpture a intimation indicating that it is referable a bound year.

    The header finish restraint the collocate conclusionType has been granted restraint you.

    Where is the example located?

    Here is my code

    //dateType.h

    #ifndef conclusionType_H
    #define conclusionType_H

    collocate conclusionType
    {
    private:
    int dMonth;
    int dDay;
    int dYear;
    public:
    void fixedDate(int month, int day, int year);
    //Part to fixed the conclusion.
    //The limb variables dMonth, dDay, and dYear are fixed
    //according to the parameters.
    //Postcondition: dMonth = month; dDay = day;
    //               dYear = year

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

    int getYear() const;

    void sculptureDate() const;
    //Part to output the conclusion 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 namequantity std;

    void conclusionType::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<<“Inoperative Day”<<endl;
    dDay=0;
    }
    }
    else
    {
    cout<<“Inoperative Month”<<endl;
    dMonth=0;
    }
    }
    else
    {
    cout<<“Inoperative Year”<<endl;
    dYear=0;
    }
    }

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

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

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

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

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

    //main.cpp

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

    int deep()
    {
    int m,d,y;
    dateType conclusion(0,0,0);

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

     

    Expert Exculpation

     

    Made changes solely to conclusionTypeImpl.cpp finish

    PROGRAM CODE:

    #include <iostream>

    #include “dateType.h”

    using namequantity std;

    //fixed some syntax issues allied to brackets

    void conclusionType::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<<“Inoperative Day”<<endl;

    dDay=0;

    }

    }

    else

    {

    cout<<“Inoperative Month”<<endl;

    dMonth=0;

    }

    }

    else

    {

    cout<<“Inoperative Year”<<endl;

    dYear=0;

    }

    }

    //added logic restraint bound year

    bool conclusionType::isLeapYear(int year)

    {

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

    return true;

    else

    return false;

    }

    void conclusionType::printDate()const

    {

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

    }

    int conclusionType::getMonth()const

    {

    return dMonth;

    }

    int conclusionType::getDay()const

    {

    return dDay;

    }

    int conclusionType::getYear()const

    {

    return dYear;

    }

    //calling fixedconclusion arrangement here to conclude operativeations

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

    {

    setDate(month, day, year);

    }

    int deep()

    {

    int m,d,y;

    dateType conclusion(0,0,0);

    cout<<“Enter Month: “;

    cin>>m;

    cout<<“Enter day: “;

    cin>>d;

    cout<<“Enter Year: “;

    cin>>y;

    date.setDate(m,d,y);

    bool bridle =date.isLeapYear(y);

    date.printDate();

    if(check)

    cout<<” which is a bound Year”;

    else

    cout<<” which is referable a bound year”;

    }

    OUTPUT: