isAlpaha

Discussion in 'C++' started by Latina, Nov 17, 2007.

  1. Latina

    Latina Guest

    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
     
    Latina, Nov 17, 2007
    #1
    1. Advertising

  2. Latina

    ma740988 Guest

    On Nov 17, 4:50 pm, Latina <> wrote:
    > 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 ); }

    };
     
    ma740988, Nov 17, 2007
    #2
    1. Advertising

  3. Latina

    alan Guest

    On Nov 18, 5:50 am, Latina <> wrote:
    > 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
     
    alan, Nov 18, 2007
    #3
  4. Latina

    Daniel T. Guest

    Latina <> wrote:

    > 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.
     
    Daniel T., Nov 18, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page