REQ: Help With List Class - Linked List Based

C

Captn Japan

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

*/
____________________________________
 
V

Victor Bazarov

Captn Japan said:
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?
 
K

Karl Heinz Buchegger

Victor said:
exercise from my book; it works and all.
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.
 

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

Similar Threads

Seek for help..linked list..urgent!!! 1
I need help 1
Memmove v/s Linked list Implementation 15
Alphabetizing Linked List data 1
doubly linked list 0
Infinite loop problem 1
Comments 'ok'? 17
for me its difficult 6

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top