REQ: Help With List Class - Linked List Based

Discussion in 'C++' started by Captn Japan, Dec 2, 2003.

  1. Captn Japan

    Captn Japan Guest

    below is what I have for my list class implementation - array based exercise from my book; it works and all.
    what I was wondering is if someone could help me out and code a 'link list based' solution to this problem. (adding two numbers and outputing the sum).

    thanks very much.


    ____________________________________
    #include <iostream.h>

    void reportResults(int, int);

    class CharacterPair {
    public:
    int numberOfQuestionMarks() { return ((ch1 == '?'?1:0) + (ch2 == '?'?1:0) ); }
    bool pairMatch() { return ( ch1 == ch2 || numberOfQuestionMarks() > 0); }
    bool sentinelPair() { return (ch1 == '*');}
    void getPair() {cin >> ch1 >> ch2; }
    private:
    char ch1;
    char ch2;
    };

    int main ()
    {
    CharacterPair cp;
    int qmCnt = 0, mpCnt = 0;

    cp.getPair();
    while ( !cp.sentinelPair() )
    {
    qmCnt += cp.numberOfQuestionMarks();
    if ( cp.pairMatch() ) mpCnt++;
    cp.getPair();
    }

    reportResults(qmCnt, mpCnt);
    return 0;
    }

    void reportResults (int qCnt, int mCnt)
    {
    cout << "Number of Question Marks is: " << qCnt << endl;
    cout << "Number of Matched Pairs is: " << mCnt << endl;
    }
    /*
    int CharacterPair::numberOfQuestionMarks()
    {
    int temp = 0;
    if (ch1 == '?') temp++;
    if (ch2 == '?') temp++;
    return temp;
    }

    bool CharacterPair::pairMatch()
    {
    return ( ch1 == ch2 || numberOfQuestionMarks() > 0);
    }

    bool CharacterPair::sentinelPair()
    {
    return (ch1 == '*');
    }

    void CharacterPair::getPair()
    {
    cin >> ch1 >> ch2;
    }

    */
    ____________________________________
     
    Captn Japan, Dec 2, 2003
    #1
    1. Advertising

  2. Re: Help With List Class - Linked List Based

    "Captn Japan" <> wrote...
    > below is what I have for my list class implementation - array based

    exercise from my book; it works and all.
    > what I was wondering is if someone could help me out and code a 'link list

    based' solution to this problem. (adding two numbers and outputing the sum).

    "I am fat, but I manage around the house and all. What I was
    wondering is if somebody could help me out and lift weights
    and jump the rope for me so I slim down and look better."
    Does this make sense?
     
    Victor Bazarov, Dec 2, 2003
    #2
    1. Advertising

  3. Re: Help With List Class - Linked List Based

    Victor Bazarov wrote:
    >
    > "Captn Japan" <> wrote...
    > > below is what I have for my list class implementation - array based

    > exercise from my book; it works and all.
    > > what I was wondering is if someone could help me out and code a 'link list

    > based' solution to this problem. (adding two numbers and outputing the sum).
    >
    > "I am fat, but I manage around the house and all. What I was
    > wondering is if somebody could help me out and lift weights
    > and jump the rope for me so I slim down and look better."
    > Does this make sense?


    Better then that:
    I am fat and I want to slim down. Can anybody else fly to Austriala
    and catch some kangoroos for me?

    The program posted doesn't do what he promises in the description.
    So he isn't able to do his own homework, he even isn't able to
    copy the correct example from the book.


    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Dec 3, 2003
    #3
    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.
Similar Threads
  1. Joshua
    Replies:
    8
    Views:
    6,147
    Joshua
    Sep 29, 2004
  2. Chris Ritchey
    Replies:
    7
    Views:
    514
    emerth
    Jul 10, 2003
  3. Chris Ritchey

    Generating a char* from a linked list of linked lists

    Chris Ritchey, Jul 9, 2003, in forum: C Programming
    Replies:
    7
    Views:
    503
    emerth
    Jul 10, 2003
  4. fool
    Replies:
    14
    Views:
    548
    Barry Schwarz
    Jul 3, 2006
  5. joshd
    Replies:
    12
    Views:
    705
    John Carson
    Oct 2, 2006
Loading...

Share This Page