isAlpaha

L

Latina

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
 
M

ma740988

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 ); }

};
 
A

alan

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?
 
D

Daniel T.

Latina said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top