Computers and Technology
Computers and Technology, 01.12.2021 01:50, shamiahG

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-.

bool isLeapYear(int year);

dateType(int month = 0, int day = 0, int year = 0);

};

#endif

//dateTypeImp. cpp

#include
#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"< dDay=0;
}
}
else
{
cout<<"Invalid Month"< dMonth=0;
}
}
else
{
cout<<"Invalid Year"< dYear=0;
}
}

bool dateType::isLeapYear(int year)
{
if(year%4==0)
return true;
else
return false;
}
void dateType::printDate()const
{
cout<
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
#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");
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, deathfire5866
Determine whether the following careers would require training or college.
Answers: 1
image
Computers and Technology, 23.06.2019 00:00, eguzmandpandoracom
How do we use the sumif formula (when dealing with different formats) ?
Answers: 1
image
Computers and Technology, 24.06.2019 01:00, gymnast8900
Me if you do then you get 10 points and brainliest
Answers: 1
image
Computers and Technology, 24.06.2019 17:00, rosepetals2938
Carlos, an algebra teacher, is creating a series of powerpoint presentations to use during class lectures. after writing, formatting, and stylizing the first presentation, he would like to begin writing the next presentation. he plans to insert all-new content, but he wants to have the same formatting and style as in the first one. what would be the most efficient way for carlos to begin creating the new presentation? going under the file tab and opening the first presentation, deleting all content from each page, and adding new content going under the file tab and clicking on new in the left pane, then choosing new from existing going under the design tab and clicking on themes, then selecting the theme that was used for the first template going under the design tab and opening the template that was created for the first presentation
Answers: 2
Do you know the correct answer?
In this chapter, the class dateType was designed to implement the date in a program, but the member...

Questions in other subjects:

Konu
Chemistry, 08.06.2021 14:00
Konu
World Languages, 08.06.2021 14:00