Design a class called Date that has integer data members to store month, day, an
ID: 3566260 • Letter: D
Question
Design a class called Date that has integer data members to store month, day, and year. The class should have a three-parameter default constructor that allows the date to be set at the time a new Date object is created. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e., January 1, 2001) should be used. The class should have member functions to print the date in the following formats:
3/15/13
March 15, 2013
15 March 2013
Demonstrate the class by writing a program that uses it. Be sure your program only accepts reasonable values for month and day. The month should be between 1 and 12. The day should be between 1 and the number of days in the selected month.
(MUST CREATE Date.h and Date.cpp).
== ABSOLUTELY NO GLOBAL VARIABLES ALLOWED == (constants are fine as global)
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include"date.h"
using namespace std;
class mydate
{private:
int day,month,year;
public:
calendar()
{
day=1;
month=1;
year=2001;
}
calendar(int da,int mo,int ye)
{
if(mo==1 || mo==3 || m==5 || m==7 || m==8 || m==10 || m==12)
{
if(da>=1 && da<=31)
{d=da;
}
}
}
else if(mo==4 || mo==6 || m==9 || m==11)
{
if(da>=1 && da<=30)
{d=da;
}
}
else if(m==2)
{if(y== ye)
{
if(d>1 && d<29)
{
d=da;
}
}
else if(d>1 && d<28)
{
d=da;
}
}
}
else
{
d=1;
m=1;
y=2001;
}
void showshortdate()
{
cout<<day<<"/"<<month<<"/"<<year;
}
void showlongdate()
{
char m[12][50]={"jan","feb","mar","apr","may","jun","july","aug","sep","oct","nov","dec"};
cout<<day<<","<<m[month-1]<<","<<year;
}
void showeurodate()
{charm[12][50]={"jan,"feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
cout<<m[month-1]<<","<<day<<" "<<year;
}};
int main()
{
mydate a(2,2,2002),b;
b.showshotdate();
b.showlongdate();
b.showeurodate();
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.