Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2 Date Class 10 points Design a class called Date. The class should stor

ID: 3912866 • Letter: P

Question

Problem 2 Date Class 10 points Design a class called Date. The class should store a date in three integers month, day, and year Declare all member variables private and all member functions public. Each instance variable should have getter and setter functions to get and set each value. There should be three member functions to print the date in the following forms: 12/25/2018 December 25, 2018 25. December 2018 Implement a program that lets the user enter a date using your Date class. The user enters a day month and year. You will then create an object of the Date class passing in the three values to the constructor. Call each function to print the three different date forms as shown above

Explanation / Answer

code :

#include<iostream>

using namespace std;

void setDay(int d)

{

day1=d;

}

void setMonth(int m)

{

month1=m;

}

void setYear(int y)

{

year1=y;

}

int getDay()

{

return day1;

}

int getMonth()

{

return month1;

}

int getYear()

{

return year1;

}

int main()

{

int day1,month1,year1;

string s=Date();

day1=(int)s.substr(s,0,1);

month1=(int)s.substr(s,3,4);

year1=(int)s.substr(s,6,7);

setDay(day1);

setMonth(month1);

setYear(year1);

cout<<getDay()<<"/"<<getMonth()<<"/"<<getYear();

return 0;

}

Explanation :

For day, month & year setter and getter methods are defined, and called in main function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote