By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

REQ: Help With List Class - Linked List Based

P: n/a
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;
}

*/
____________________________________
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Captn Japan" <fa**@ekaf.com> 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?
Jul 22 '05 #2

P: n/a
Victor Bazarov wrote:

"Captn Japan" <fa**@ekaf.com> 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
kb******@gascad.at
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.