Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 9th, 2006, 9:03 PM   #1
sweetvirgogirl
Newbie
 
Join Date: Jan 2006
Posts: 23
Rep Power: 0 sweetvirgogirl is on a distinguished road
C++ HW where I dont even know what they are asking

This assignment is to implement a symbol table which uses "hashing" to
organize the symbols in the table so that they can be accessed efficiently.
The table uses the following C++ declarations:

template <class AT>
class item {
public:
item(string s);
string getName(void); // returns the name
AT attr; // attributes other than name
private:
string name;
};

template <class AT>
class SymTab {
public:
SymTab(); //initializes to the empty table
item<AT> * find(string s); //returns item pointer or null
item<AT> * insert(string s); //inserts if necessary and
//returns item pointer
};

For each symbol stored in the table there is a record of type AT which contains the values associated with the symbol. This information is stored with the symbol's name in an instance of the class item. AT is a type parameter in these declarations because the attributes of a symbol
typically vary from application to application. A symbol table is an
instance of class SymTab whose find function returns a pointer to the item
in which its input symbol is stored. If the symbol is not stored in the
table, find returns NULL. The function insert performs the same function as
find except that it always returns a pointer to the item instance for the
symbol because it creates a new instance of item for a symbol that is not
stored in the table, and then stores it in the table before returning.
Thus, insert never returns NULL.

The hash table itself is implemented as an array of 137 linked-lists which
is "hidden" from clients of SymTab. Each linked-list represents the set of
symbols that "hash" to that entry of the array; i. e., each element in the
list contains the item for a symbol that hashes to the index of the array
element which points to the list. You may use any reasonable hashing
function in your implementation. You may implement the linked-lists yourself or you may use the implementation in the C++ Standard Template Library (STL).

^^ I'm confused about sentences in the bigger font.
like I dont even know what they are asking ...
and why 137?!
sweetvirgogirl is offline   Reply With Quote
Old Feb 9th, 2006, 9:11 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Read the forum's rules/FAQ.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 9th, 2006, 10:18 PM   #3
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
A hash is a function that given some input (in this case your string) and returns a number for it. The number returned for any given string must always be the same. A good hash function scatters the hash values around.

In this case 137 is a (semi) arbitrary number of hash values your function should return.

When you get given a string, use your hash function to return a number from 0 to 136. Then put (or find) the string in the list in the array entry associated with that hash number. The idea is that the hash function is much faster than searching the full list of all names, so you end up with your string searches (and insert) being approximately 137 times fast.

Give it a go and see how far you can get. Post some code here if you get stuck.
The Dark is online now   Reply With Quote
Old Feb 10th, 2006, 5:25 AM   #4
sweetvirgogirl
Newbie
 
Join Date: Jan 2006
Posts: 23
Rep Power: 0 sweetvirgogirl is on a distinguished road
Quote:
Originally Posted by DaWei
Read the forum's rules/FAQ.
well I didnt ask anyone to do my assignment, all I'm asking is at least explain the assignment to me so that I can do it .... I mean you have to agree that I cant do assignment if I dont even know what they are asking
if I cant post this question here ... then where should I post it?
sweetvirgogirl is offline   Reply With Quote
Old Feb 10th, 2006, 8:05 AM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
He means that you are supposed to ask your question differently, using code tags and formulating your question nicely.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Feb 12th, 2006, 5:39 PM   #6
sweetvirgogirl
Newbie
 
Join Date: Jan 2006
Posts: 23
Rep Power: 0 sweetvirgogirl is on a distinguished road
how do covert a string into an integer?

suppose the string is "blah"
how do i get a numerical value for the string?
sweetvirgogirl is offline   Reply With Quote
Old Feb 12th, 2006, 5:53 PM   #7
sweetvirgogirl
Newbie
 
Join Date: Jan 2006
Posts: 23
Rep Power: 0 sweetvirgogirl is on a distinguished road
^i dont even know if it's possible ...
but if it is not, i need someone to tell me that it's not lol
sweetvirgogirl is offline   Reply With Quote
Old Feb 12th, 2006, 6:02 PM   #8
nindoja
Programmer
 
Join Date: Jun 2005
Posts: 92
Rep Power: 4 nindoja is on a distinguished road
If you are on windows, look into atoi, and itoa to store an integer in a character array.
nindoja is offline   Reply With Quote
Old Feb 12th, 2006, 6:04 PM   #9
sweetvirgogirl
Newbie
 
Join Date: Jan 2006
Posts: 23
Rep Power: 0 sweetvirgogirl is on a distinguished road
Quote:
Originally Posted by nindoja
If you are on windows, look into atoi, and itoa to store an integer in a character array.
yeah i looked into that ... no luck
it just gives me 0 ... !!

if i use "42" as a string, it will tell me 42
but if i use "blah" as a string, it'll give me plain zero..
see my problem?
sweetvirgogirl is offline   Reply With Quote
Old Feb 12th, 2006, 6:08 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You don't get an integer from a string containing the word "blah." You get integers from strings containing numeric characters such as '0', '1', et. al. Try to be rational. If you like, you can assign binary numerical values to each of the codes (as they did with ASCII back in the olden days), and do with them whatever you like. You might even try to put them in the bank to supplement your salary as a programmer.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC