Answered Essay: 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

#ifndef DATATYPE_H
#define DATATYPE_H

class dataType{
int year;
int month;
int day;
// consstructor for private variables
void setyear(int y);
int getyear();
void setmonth(int m);
int getmonth();
void setday(int d);
int getday();
// function validate for checking the date is valid date
bool validate();
// function for checking leap year
void leapyear();
// function for calculating the no. of days in the month
void month_days();
// function for calculating the number of days passed in the year
void passed_days();
// function for calculating the number of days remaining in the year
void remain_days();


#endif /* DATATYPE_H */

// declaration of header file functions

program dataType.cpp

#include <iostream>
#include <string>

#include “dataType.h”

using namespace std;
int arr[] = {31,28,31,30,31,30,31,31,30,31,30,31};
dataType ::dataType(){}
//constructor assigning the values year, month and date
dataType::dataType(int y, int m, int d){
year = y;
month = m;
day = d;
// setter year
void dataType :: setyear(int y)
year = y;
//function for setter month
void dataType::setmonth(int m)
month = m;
// function for setter day
void dataType ::setday(int d)
day = d;
int dataType::getyear()
int dataType::getmonth()
int dataType::getday()
// function for checking leapyear
void dataType::leapyear()
// if year is divided by 4 then its a leap year
if(year%4 == 0)
cout<<“n”<<year<<” is a leap year”;
cout<<“n”<<year<<” is not a leap year”;
// calculating total number of days.
void dataType::month_days(){
// if the year is leap year total day should added with 1
if((year%4==0) && month<2)
cout<<“nTotal number of days in the month : “<<arr[month];
cout<<“nTotal number of days in the month : “<<arr[month]+1;
// to calculate the number 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<<“nTotal no. of days passed is : “<<tot;
// to calculate the remaining 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 total no. of days remaining is :”<<tot;

// to validate the date
bool dataType::validate(){
bool flag;
if (day>arr[month])
flag = false;
flag = true;
return flag;

program main.cpp

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

* the program accepts the date and prints number of days passed and remain
int main(int argc, char** argv) {
int yr,mn,dy;

// accepts the year,month,date
cout<<“nEnter the year :”;
cout<<“nEnter the Month :”;
cout<<“nEnter the day :”;

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

// check for the validation
if (d.validate()){

// invalidate
cout<<“n Date is invalidate”;
return 0;

sample output:

Enter the year :2010

Enter the Month :4

Enter the day :34

Date is invalidate
RUN SUCCESSFUL (total time: 8s)

ouput 2#

Enter the year :2016

Enter the Month :3

Enter the day :20

2016 is a leap year
Total number of days in the month : 31
Total no. of days passed is : 110
total no. of days remaining is :256
RUN SUCCESSFUL (total time: 6s)

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.


Let us write that nagging essay.


Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.


Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.


Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.


Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?