473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

isAlpaha

Hi, I am doing a program that deals with dates, so the program needs
to check if the user enters the date with numbers or letters.
I try isAlpha() and isAlnum() but it is given me an error message.
Can some one help me please.

Error:
'class Date' has no member named 'isAlpha'
'class Date' has no member named 'isAlnum'

Here is my code:

class Date
{
friend istream &operator>>(istream&, Date &);
friend ostream &operator<<(ostream&, const Date &);
private:
int mon,day,year;
public:
Date(){mon=day=year=0;}

int operator-(const Date&)const;
void print();
};

istream& operator>>(istream &in, Date &d)
{
if(d.isAlpha())
{
in>>d.mon;
in>>d.day;
in.ignore(1); //skip the ","
in>>d.year;
}
if(d.isAlnum())
{
in>>d.mon;
in.ignore(1); //skip the "/"
in>>d.day;
in.ignore(1); //skip the "/"
in>>d.year;
}
return in;
}

Thanks
Nov 17 '07 #1
3 1221
On Nov 17, 4:50 pm, Latina <sdl...@gmail.comwrote:
Hi, I am doing a program that deals with dates, so the program needs
to check if the user enters the date with numbers or letters.
I try isAlpha() and isAlnum() but it is given me an error message.
Can some one help me please.

Error:
'class Date' has no member named 'isAlpha'
'class Date' has no member named 'isAlnum'
Self explanatory if you ask me. Your class contains no member
functions isAlpha and IsAlnum.

// Untested.

class Date
{
friend istream &operator>>(istream&, Date &);
friend ostream &operator<<(ostream&, const Date &);
private:
int mon,day,year;
public:
Date(){mon=day=year=0;}
int operator-(const Date&)const;
void print();
bool isAlpha () { /* whatever */ return ( true ); }
bool IsAlnum () { /* whatever */ return ( true ); }

};
Nov 17 '07 #2
On Nov 18, 5:50 am, Latina <sdl...@gmail.comwrote:
Hi, I am doing a program that deals with dates, so the program needs
to check if the user enters the date with numbers or letters.
I try isAlpha() and isAlnum() but it is given me an error message.
Can some one help me please.

Error:
'class Date' has no member named 'isAlpha'
'class Date' has no member named 'isAlnum'

Here is my code:

class Date
{
friend istream &operator>>(istream&, Date &);
friend ostream &operator<<(ostream&, const Date &);
private:
int mon,day,year;
public:
Date(){mon=day=year=0;}

int operator-(const Date&)const;
void print();

};

istream& operator>>(istream &in, Date &d)
{
if(d.isAlpha())
{
in>>d.mon;
Perhaps you should be putting these into a string first, then
checking, say, the first character of that string with, maybe...
isalpha()? What is it you want to check, anyway? The Date object
that was given to you, or the user's input? Which should you be
applying isalpha() on?
in>>d.day;
in.ignore(1); //skip the ","
in>>d.year;
}
if(d.isAlnum())
{
in>>d.mon;
in.ignore(1); //skip the "/"
in>>d.day;
in.ignore(1); //skip the "/"
in>>d.year;
}
return in;

}

Thanks
Nov 18 '07 #3
Latina <sd****@gmail.comwrote:
Hi, I am doing a program that deals with dates, so the program needs
to check if the user enters the date with numbers or letters.
I try isAlpha() and isAlnum() but it is given me an error message.
Can some one help me please.

Error:
'class Date' has no member named 'isAlpha'
'class Date' has no member named 'isAlnum'

Here is my code:

class Date
{
friend istream &operator>>(istream&, Date &);
friend ostream &operator<<(ostream&, const Date &);
private:
int mon,day,year;
public:
Date(){mon=day=year=0;}

int operator-(const Date&)const;
void print();
};

istream& operator>>(istream &in, Date &d)
{
This function is supposed to load data from 'in' into 'd'. At this point
in the code the data in 'd' is meaningless. Asking if d.isAlpha() is
useless.

What you want to know is if the data contained in the 'in' variable is
letters or numbers...
if(d.isAlpha())
{
in>>d.mon;
in>>d.day;
in.ignore(1); //skip the ","
in>>d.year;
}
if(d.isAlnum())
{
in>>d.mon;
in.ignore(1); //skip the "/"
in>>d.day;
in.ignore(1); //skip the "/"
in>>d.year;
}
return in;
}
I suggest you start smaller. Something like this:

// put includes here

class Date {
int month, day, year;
public:
Date() { month = day = year = 0; }
int getMonth() const {
return month;
}

int getDay() const {
return day;
}

int getYear() const {
return year;
}

istream& readAsNum( istream& );
};

istream& Date::readAsNum( istream& in )
{
// place code here
return in;
}

int main() {
stringstream ss( "11/17/2007" );
Date result;
result.readAsNum( ss );
assert( result.getMonth() == 11 );
assert( result.getDay() == 17 );
assert( result.getYear() == 2007 );
cout << "OK!\n";
}

Take the above code and paste it into your cpp file. Then add code where
indicated until it prints "OK!" on the screen. Once you have done that,
come back here and post what you have so far for more help.
Nov 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.