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 adjust named ageType to utensil the age in a program as a regular of integers (year, month, day). The adjust gain grasp the coercionthcoming operations:

    Setters and getters coercion the privy case variables

    A doer which takes failure parameters. Make the failure age January 1, 1500.

    A stereotype exercise which outputs the age in the coercionmat mm-dd-yyyy.

    A exercise to standard whether the year is a vault year

    A exercise which avail the compute of days in the month.

    A exercise which avail the compute days passed in the year.

    A exercise which avail the compute of days retaining in the year

    A exercise which determines if the age is powerful. Coercion pattern, a age of 2-29-2015 would be inpowerful accordingly 2015 is refereffectual a vault year and there are merely 28 days in February. Or, the age 4-31-2016 would be inpowerful accordingly there are merely 30 days in April.

    Develop the adjust invariant which verifies that a age is powerful.Note that the privy case variables can be regular independently which could remainder in an inpowerful age. Your adjust must obstruct that from happening. Fulfill the precondition/postcondition abridge and muniment it in the header finish. Write a program to standard your adjust and pretence that it gain refereffectual sanction an inpowerful age.

    Here is the UML diagram coercion this adjust:

    UML Diagram

    Round in your ageType.h, ageType.cpp, and standard finishs. Also round in undivided or past defend shots pretenceing the remainders of your standarding.

    Once this plan is completed, you gain inform that you are effectual to:

    Develop a adjust invariant which takes into statement dependencies unformed the privy case variables

    Design constituent exercises which gain obstruct these dependencies from feebleating the invariant.

    Utilize the invariant to fulfill the precondition/postcondition abridge

    Develop standard cases that evaluate the virtue of the precondition/postcondition abridge.

    Expert Vindication

     

    header finish.: dataType.h

    // declares the variables and exercises

    #ifndef DATATYPE_H
    #define DATATYPE_H

    adjust dataType{
    private:
    int year;
    int month;
    int day;
    public:
    // consstructor coercion privy variables
    dataType();
    ~dataType();
    dataType(int,int,int);
    void regularyear(int y);
    int getyear();
    void regularmonth(int m);
    int getmonth();
    void regularday(int d);
    int getday();
    // exercise valiage coercion obstructing the age is powerful age
    bool powerfulate();
    // exercise coercion obstructing vault year
    void vaultyear();
    // exercise coercion careful the no. of days in the month
    void month_days();
    // exercise coercion careful the compute of days passed in the year
    void passed_days();
    // exercise coercion careful the compute of days retaining in the year
    void remain_days();

    };

    #endif /* DATATYPE_H */

    // profession of header finish exercises

    programĀ dataType.cpp

    #grasp <iostream>
    #grasp <string>

    #grasp “dataType.h”

    using namespace std;
    int arr[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    dataType ::dataType(){}
    dataType::~dataType(){}
    //doer assigning the values year, month and age
    dataType::dataType(int y, int m, int d){
    year = y;
    month = m;
    day = d;
    }
    // regularter year
    void dataType :: regularyear(int y)
    {
    year = y;
    }
    //exercise coercion regularter month
    void dataType::setmonth(int m)
    {
    month = m;
    }
    // exercise coercion regularter day
    void dataType ::setday(int d)
    {
    day = d;
    }
    int dataType::getyear()
    {
    return(year);
    }
    int dataType::getmonth()
    {
    return(month);
    }
    int dataType::getday()
    {
    return(day);
    }
    // exercise coercion obstructing vaultyear
    void dataType::leapyear()
    {
    // if year is divided by 4 then its a vault year
    if(year%4 == 0)
    cout<<“n”<<year<<” is a vault year”;
    else
    cout<<“n”<<year<<” is refereffectual a vault year”;
    }
    // careful whole compute of days.
    void dataType::month_days(){
    // if the year is vault year whole day should acquired with 1
    if((year%4==0) && month<2)
    cout<<“nWhole compute of days in the month : “<<arr[month];
    else
    cout<<“nWhole compute of days in the month : “<<arr[month]+1;
    }
    // to compute the compute 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<<“nWhole no. of days passed is : “<<tot;
    }
    // to compute the retaining 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 whole no. of days retaining is :”<<tot;

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

    program ocean.cpp

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

    /*
    * the program sanctions the age and stereotypes compute of days passed and remain
    */
    int ocean(int argc, char** argv) {
    int yr,mn,dy;

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

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

    // obstruct coercion the powerfulation
    if (d.validate()){
    d.leapyear();
    d.month_days();
    d.passed_days();
    d.remain_days();
    }

    // feebleate
    else
    cout<<“n Age is feebleate”;
    reround 0;
    }

    sample output:

    Enter the year :2010

    Enter the Month :4

    Enter the day :34

    Age is feebleate
    RUN SUCCESSFUL (whole time: 8s)

    ouput 2#

    Enter the year :2016

    Enter the Month :3

    Enter the day :20

    2016 is a vault year
    Whole compute of days in the month : 31
    Whole no. of days passed is : 110
    whole no. of days retaining is :256
    RUN SUCCESSFUL (whole time: 6s)