Answer:
The cpp program is given thus:
Step-by-step explanation:
Date.h:
#ifndef DATE_H
#define DATE_H
using namespace std;
class Date
{
public:
string mm,dd,yyyy;
public:
Date();
string getMonth();
string getDay();
string getYear();
void setValues(char*);
friend istream &operator>>(istream &is, Date &D)
{
char str[20];
is>>str;
D.setValues(str);
return is;
}
friend ostream &operator<<( ostream &output, Date &D ) {
output << "Full Format ==> " << D.getMonth() << " " << D.getDay()<< ", " <<D.getYear()<<endl;
return output;
}
};
#endif
yearOverload.cpp:
#include <iostream>
#include<string>
#include<cstring>
#include <sstream>
#include "Date.h"
using namespace std;
Date::Date()
{
}
string Date::getMonth()
{
stringstream s;
s << mm;
return s.str();
}
string Date:: getDay()
{
stringstream s;
s << dd;
return s.str();
}
string Date:: getYear()
{
stringstream s;
s << yyyy;
return s.str();
}
void Date:: setValues(char* str)
{
string months[13]= {" ","January","February","March","April","May","June","July","August","September","October","November","December"};
string s1;
s1 = strtok(str, "/");
dd = strtok(NULL,"/");/*set day*/
yyyy = strtok(NULL,"/");/*set year*/
cout<<"Here the results :"<<endl;
cout<<"Month : "<<s1<<endl;
cout<<"Day : "<<dd<<endl;
cout<<"Year : "<<yyyy<<endl<<endl;
int month;
std::istringstream iss (s1);
iss >> month;
if(month>0&&month<13)
mm = months[month];/*set month*/
else
cout<<"Error invalid date";
}
main.cpp:
#include<iostream>
#include"Date.h"
#include"yearOverload.cpp"
using namespace std;
int main()
{
Date d;
cout<<"Enter a date with this format mm/dd/yyyy ==> ";
cin>>d;
cout<<d;
return 0;
}