MarianaA
11-20-2007, 09:40 PM
Hi, I am doing a program using overloaded methods.
The program needs to find out how many days have been pass between two dates. But the user can enter the dates in two formats (11/20/2007 or November 20, 2007), so I was thinking on using isAlpha so check if the user enters the date in the second format, but I dont how to do it.
Can some one help me please.
Here is what I have.
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
class Date
{
friend istream& operator>>(istream&, Date&);
friend ostream& operator<<(ostream&, const Date&);
private:
int mon;
int day;
int year;
string m;
public:
int difference(Date);
int operator-(Date);
bool operator>(Date);
bool isAlpha()
{
/* whatever */
return (true);
}
bool isAlnum()
{
/* whatever */
return (true);
}
};
istream& operator >>( istream& in, Date& dayz )
{
if(dayz.isAlpha()==true)
{
in>>dayz.mon;
in>>dayz.day;
in.ignore(1); //skip the ","
in>>dayz.year;
}
if(dayz.isAlnum()==true)
{
in>>dayz.mon;
in.ignore(1); //skip the "/"
in>>dayz.day;
in.ignore(1); //skip the "/"
in>>dayz.year;
}
return in;
}
Thanks :)
The program needs to find out how many days have been pass between two dates. But the user can enter the dates in two formats (11/20/2007 or November 20, 2007), so I was thinking on using isAlpha so check if the user enters the date in the second format, but I dont how to do it.
Can some one help me please.
Here is what I have.
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
class Date
{
friend istream& operator>>(istream&, Date&);
friend ostream& operator<<(ostream&, const Date&);
private:
int mon;
int day;
int year;
string m;
public:
int difference(Date);
int operator-(Date);
bool operator>(Date);
bool isAlpha()
{
/* whatever */
return (true);
}
bool isAlnum()
{
/* whatever */
return (true);
}
};
istream& operator >>( istream& in, Date& dayz )
{
if(dayz.isAlpha()==true)
{
in>>dayz.mon;
in>>dayz.day;
in.ignore(1); //skip the ","
in>>dayz.year;
}
if(dayz.isAlnum()==true)
{
in>>dayz.mon;
in.ignore(1); //skip the "/"
in>>dayz.day;
in.ignore(1); //skip the "/"
in>>dayz.year;
}
return in;
}
Thanks :)