473,503 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

REQ: Help With List Class - Linked List Based

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
2 1236
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6072
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
7
4803
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am...
2
1377
by: Skywise | last post by:
I am fairly new to linked lists. I am trying to write a class using linked lists. It seems to work fine, but I need to know if I have any resource leaks in it because I plan on using this class...
5
859
by: Dream Catcher | last post by:
1. I don't know once the node is located, how to return that node. Should I return pointer to that node or should I return the struct of that node. 2. Also how to do the fn call in main for that...
10
15099
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
13
2072
by: B. Williams | last post by:
I have written some code to accept input and place this input at the beginning or end of a list, but I need assistance including a class so that it will allow input of a phone number that is...
14
2551
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
6
3251
by: APEJMAN | last post by:
I know what I'm posting here is wired, but it's been 3 days I'm workin g on these codes, but I have no result I post the code here I dont wanne bother you, but if any one of you have time to...
11
2528
by: Scott Stark | last post by:
Hello, The code below represents a singly-linked list that accepts any type of object. You can see I'm represting the Data variable a System.Object. How would I update this code to use...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.