- 1
Help me understand this Question
Could you please explain this Q?? (Date Class Modification) Modify class Date in Fig. 18.10 to have the following capabilities: a) Output the date in multiple formats such as DDD YYYY MM/DD/YY June 14, 1992 b) Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). c) Create a Date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members. Fig 18.10 link in comment
3 Answers
+ 5
you need the constructors 
f.e. like this:
Date(string,int,int)
0
#include<iostream>
#include<ctime>
using namespace std;
class Date {
	int d,m,y;
 public:
 Date();
 Date( int*, int*);
 Date( int*, int*, int*);
 Date( string , int*, int*);
  
};
Date::Date( int *dd, int *yy ):d(*dd),y(*yy)
{
	cout<<d<<""<<y+1900;
}
Date::Date( int *dd, int *mm, int *yy):d(*dd),m(*mm),y(*yy)
{
	cout<<m<<"/"<<d<<"/"<<y-100;
}
Date::Date(string mo , int *dd ,int *yy):d(*dd),y(*yy)
{
	
	cout<<mo<<"/"<<d<<"/"<<y-100;
}
int main()
{
	
	int date,month,year;string mo;
	time_t now;
	struct tm nowLocal;
	now = time(NULL);
	nowLocal = *localtime(&now);
	date = nowLocal.tm_mday;
	month = nowLocal.tm_mon+1;
	year = nowLocal.tm_year;
	if(month == 1)mo="Jan";
	else if(month == 2)mo="Feb";
	else if(month == 3)mo="Mar";
	else if(month == 4)mo="April";
	else if(month == 5)mo="May";
	else if(month == 6)mo="Jun";
	else if(month == 7)mo="July";
	else if(month == 8)mo="Aug";
	else if(month == 9)mo="Sep";
	else if(month == 10)mo="Oct";
	else if(month == 11)mo="Nov";
	else if(month == 12)mo="Dec";
	Date d;		
	d(date,year);	
	d(date,month,year);		
	d(mo,date,year);
	//cout<<"Today is"<<nowLocal.tm_mday<<"/"<<nowLocal.tm_mon+1<<"/"<<nowLocal.tm_year-100;
	
}






