Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

dateType.h #include #include dateType.h using namespace std; void dateType::setDate(int month, int day, int year) { if (month >= 1 && month dMonth = month; }

image text in transcribed

dateType.h

#include

#include "dateType.h"

using namespace std;

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

{

if (month >= 1 && month

dMonth = month;

}

if (day >= 1 && day

dDay = day;

}

if (year >= 1900) {

dYear = year;

}

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

// print date in mm-dd-yyyy format

cout

cout

}

//Constructor with parameters

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

{

setDate(month, day, year);

}

// return true if lear is leap year else false

bool dateType::isLeapYear()

{

return (dYear % 400 == 0 || (dYear % 100 != 0 && dYear % 4 == 0));

}

dateTypeImp.cpp

#include

#include "dateType.h"

using namespace std;

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

{

// Checking month is valid

while(month12)

{

cout

cout

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day31)

{

cout

cout

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout

cout

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

cout

}

void dateType::isLeapYear() const

{

if ( dYear%400 == 0)

cout

else if ( dYear%100 == 0)

cout

else if ( dYear%4 == 0 )

cout

else

cout

}

//Constructor with parameters

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

{

// Checking month is valid

while(month12)

{

cout

cout

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day31)

{

cout

cout

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout

cout

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

main.cpp

#include

#include "dateType.h"

#include

using namespace std;

int main()

{

// create an instance of dateType using parameterized constructor

cout

dateType date(9, 2, 2000);

// print the date

date.printDate();

// check if the year is leap year

cout

// create an instance of dateType using setDate method

cout

dateType date2;

date2.setDate(32, 10, 1780);

// print the date

date2.printDate();

// check if the year is leap year

cout

}

Instructions In this chapter, the was designed to implement the date in a program, but the member function 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 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 with each separated by a space. Output should resemble the following: Date \#: month-day-year An example of the program is shown below: Date 1: 3-15-2008 this is a leap 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 has been provided for you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions