Homework Solution: Design a class called dateType to implement the date in a program as a set of integers (year, month, day). The class w…

    Design a class called dateType to implement the date in a program as a set of integers (year, month, day). The class will include the following operations: Setters and getters for the private instance variables A constructor which takes default parameters. Make the default date January 1, 1500. A print function which outputs the date in the format mm-dd-yyyy. A function to test whether the year is a leap year A function which returns the number of days in the month. A function which returns the number days passed in the year. A function which returns the number of days remaining in the year A function which determines if the date is valid. For example, a date of 2-29-2015 would be invalid because 2015 is not a leap year and there are only 28 days in February. Or, the date 4-31-2016 would be invalid because there are only 30 days in April. Develop the class invariant which verifies that a date is valid.Note that the private instance variables can be set independently which could result in an invalid date. Your class must prevent that from happening. Identify the precondition/postcondition contract and document it in the header file. Write a program to test your class and show that it will not accept an invalid date. Here is the UML diagram for this class: UML Diagram Turn in your dateType.h, dateType.cpp, and test files. Also turn in one or more screen shots showing the results of your testing. Once this project is completed, you will demonstrate that you are able to: Develop a class invariant which takes into account dependencies among the private instance variables Design member functions which will prevent these dependencies from invalidating the invariant. Utilize the invariant to identify the precondition/postcondition contract Develop test cases that evaluate the effectiveness of the precondition/postcondition contract.

    Expert Answer

     
    header file.: dataType.h // declares the variables and functions

    Design a systematize named boundType to appliance the bound in a program as a restraintmal of integers (year, month, day). The systematize earn apprehend the restraintthcoming operations:

    Setters and getters restraint the special request variables

    A perpetrator which takes coercionfeit parameters. Make the coercionfeit bound January 1, 1500.

    A print part which outputs the bound in the restraintmat mm-dd-yyyy.

    A part to ordeal whether the year is a bounce year

    A part which receipts the estimate of days in the month.

    A part which receipts the estimate days passed in the year.

    A part which receipts the estimate of days cherishing in the year

    A part which determines if the bound is available. Restraint issue, a bound of 2-29-2015 would be inavailtalented consequently 2015 is refertalented a bounce year and there are simply 28 days in February. Or, the bound 4-31-2016 would be inavailtalented consequently there are simply 30 days in April.

    Develop the systematize invariant which verifies that a bound is available.Note that the special request variables can be restraintmal unconnectedly which could outcome in an inavailtalented bound. Your systematize must nullify that from happening. Confirm the precondition/postcondition compress and muniment it in the header smooth. Write a program to ordeal your systematize and exhibition that it earn refertalented recognize an inavailtalented bound.

    Here is the UML diagram restraint this systematize:

    UML Diagram

    Deflect in your boundType.h, boundType.cpp, and ordeal smooths. Also deflect in single or further mitigate shots exhibitioning the outcomes of your ordealing.

    Once this plan is completed, you earn evidence that you are talented to:

    Develop a systematize invariant which takes into statement dependencies natant the special request variables

    Design constituent parts which earn nullify these dependencies from weaklyating the invariant.

    Utilize the invariant to confirm the precondition/postcondition compress

    Develop ordeal cases that evaluate the usefulness of the precondition/postcondition compress.

    Expert Repartee

     

    header smooth.: dataType.h

    // declares the variables and parts

    #ifndef DATATYPE_H
    #define DATATYPE_H

    systematize dataType{
    private:
    int year;
    int month;
    int day;
    public:
    // consstructor restraint special variables
    dataType();
    ~dataType();
    dataType(int,int,int);
    void restraintmalyear(int y);
    int getyear();
    void restraintmalmonth(int m);
    int getmonth();
    void restraintmalday(int d);
    int getday();
    // part valibound restraint hindering the bound is availtalented bound
    bool availableate();
    // part restraint hindering bounce year
    void bounceyear();
    // part restraint sagacious the no. of days in the month
    void month_days();
    // part restraint sagacious the estimate of days passed in the year
    void passed_days();
    // part restraint sagacious the estimate of days cherishing in the year
    void remain_days();

    };

    #endif /* DATATYPE_H */

    // exhibition of header smooth parts

    programĀ dataType.cpp

    #apprehend <iostream>
    #apprehend <string>

    #apprehend “dataType.h”

    using namespace std;
    int arr[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    dataType ::dataType(){}
    dataType::~dataType(){}
    //perpetrator assigning the values year, month and bound
    dataType::dataType(int y, int m, int d){
    year = y;
    month = m;
    day = d;
    }
    // restraintmalter year
    void dataType :: restraintmalyear(int y)
    {
    year = y;
    }
    //part restraint restraintmalter month
    void dataType::setmonth(int m)
    {
    month = m;
    }
    // part restraint restraintmalter day
    void dataType ::setday(int d)
    {
    day = d;
    }
    int dataType::getyear()
    {
    return(year);
    }
    int dataType::getmonth()
    {
    return(month);
    }
    int dataType::getday()
    {
    return(day);
    }
    // part restraint hindering bounceyear
    void dataType::leapyear()
    {
    // if year is divided by 4 then its a bounce year
    if(year%4 == 0)
    cout<<“n”<<year<<” is a bounce year”;
    else
    cout<<“n”<<year<<” is refertalented a bounce year”;
    }
    // sagacious entirety estimate of days.
    void dataType::month_days(){
    // if the year is bounce year entirety day should external with 1
    if((year%4==0) && month<2)
    cout<<“nEntirety estimate of days in the month : “<<arr[month];
    else
    cout<<“nEntirety estimate of days in the month : “<<arr[month]+1;
    }
    // to estimate the estimate of days passed
    void dataType::passed_days(){
    int tot=0;
    int i;
    for(i = 0; i<month;i++)
    tot = tot+arr[i];
    tot = tot+day;
    if((year%4==0) && month<3)
    tot = tot+1;
    cout<<“nEntirety no. of days passed is : “<<tot;
    }
    // to estimate the cherishing days
    void dataType::remain_days()
    {
    int tot = 0;
    int i;
    for(i = month+1; i<=12;i++)
    tot = tot+arr[i];
    tot = tot+(arr[month]-day);
    if((year%4==0) && month>2)
    tot = tot+1;
    cout<<“n entirety no. of days cherishing is :”<<tot;

    }
    // to valibound the bound
    bool dataType::validate(){
    bool flag;
    if (day>arr[month])
    flag = false;
    else
    flag = true;
    redeflect flag;
    }

    program ocean.cpp

    #apprehend <cstdlib>
    # apprehend<iostream>
    # apprehend “dataType.h”
    using namespace std;

    /*
    * the program recognizes the bound and prints estimate of days passed and remain
    */
    int ocean(int argc, char** argv) {
    int yr,mn,dy;

    // recognizes the year,month,date
    cout<<“nEnter the year :”;
    cin>>yr;
    cout<<“nEnter the Month :”;
    cin>>mn;
    cout<<“nEnter the day :”;
    cin>>dy;

    // perpetrator
    dataType d(yr, mn, dy);

    // hinder restraint the availableation
    if (d.validate()){
    d.leapyear();
    d.month_days();
    d.passed_days();
    d.remain_days();
    }

    // weaklyate
    else
    cout<<“n Bound is weaklyate”;
    redeflect 0;
    }

    sample output:

    Enter the year :2010

    Enter the Month :4

    Enter the day :34

    Bound is weaklyate
    RUN SUCCESSFUL (entirety time: 8s)

    ouput 2#

    Enter the year :2016

    Enter the Month :3

    Enter the day :20

    2016 is a bounce year
    Entirety estimate of days in the month : 31
    Entirety no. of days passed is : 110
    entirety no. of days cherishing is :256
    RUN SUCCESSFUL (entirety time: 6s)