C++ I need help with this : I did my home work but i\'m confused and blocked som
ID: 663265 • Letter: C
Question
C++ I need help with this :
I did my home work but i'm confused and blocked somewhere. so i decided to restart with your help.
This the Class designed in the chapter
This is The exercise to do :
Thanks in advance
class dateType: class dateType public: void setDate (int month, int day, int year) //Function to set the date //The member variables dNMonth, dDay, and dYear //according to the paraneters //Postcondition: dMonth = month: dDay = day: are set dVear year int getDay ) const; //Function to return the day //Postcondition: The value of dDay is returned. int getMonth ) const: //Function to return the month. //Postcondition: The value of dMonth is returned. int getYear) const; //Function to return the year //Postcondition: The value of dYear is returned. void printDate ) const; //Function to output the date in the fom m-dd-yyyy dateType (int month= 1, int day= 1, int year 1900); //Constructor to set the date //The member variables dMonth, dDay, and dYear are set //according to the paraneters //Postcondition : dMonth =month ; dDay day: dYear year : If no values are specified, the default values are used to initialize the member variablesExplanation / Answer
// Add new function in your class; replace updated function
boolean isLeapYear(int year){
if (year % 400 == 0) return true;
else if (year % 100 == 0) return false;
else if (year % 4 == 0) return true;
return false;
}
boolean check(int month, int day, int year){
if (month > 0 && month < 13){
if (month == 1 && month == 3 && month == 5 && month == 7 && month == 8 && month == 10 && month == 12){
if (day > 0 && day < 32) return true;
}
else if (month == 2){
if (isLeapYear(year) == true){
if (day > 0 && day < 29) return true;
}
else{
if (day > 0 && day < 28) return true;
}
}
else if {
if (day > 0 && day < 31) return true;
}
return false;
}
return false;
}
void setDate(int month, int day, int year){
if (check(month,day,year) == true){
dMonth = month;
dDay = day;
dYear = year;
}
}
// Constructor
dateType(int month = 1, int day = 1, int year = 1900){
if (check(month,day,year) == true){
setDate(month,day,year);
}
}
// Test your program
int main(){
dateType *d = dateType(month,day,year);
d->printDate();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.