Quiz 1 - Solution
Quiz 1 - Solution
Quiz 1 - Solution
Spring-2020 (CS-Department)
date()
day = 1;
month = 1;
year = 2000;
}
b) Implement a setter function to adjust the date.
c) Implement a private method advance(), which moves date to the next day, ensuring that all data
members are updated appropriately.
void advance()
{
day++;
if(day>daysInMonth[month])
day = 1;
month++;
if(month>12)
month = 1;
year++;
void call()
advance();
int main()
date d1;
d1.call();
To access, set and get the private data members of the class.
b) In the presence of a parameterized constructor, it is not necessary to have a setter function. Do you
agree with this statement? Justify your answer.
No, Parameterized or any other constructor can only be called when the object is created. If we want to
change/update the private data members after the object is created we necessarily need a setter
function.