Question
I can read in the dict.txt file, and I am pretty sure I can make the hash table, its just the rest as far as
I can read in the dict.txt file, and I am pretty sure I can make the hash table, its just the rest as far as reading in the test files and making sure it meets the requirements.
In C++, this programming homework is to develop a simple spelling checker. The file dict.datcontains 25,021 frequently used words, each on a separate line in lowercase. Read the file, and insert the words into a hash table with 1373 buckets. Remember to move dict.dat to the csegrid. Then run the command dos2unix dict.dat (to remove those pesky /r's created by Windows)
Prompt for the name of an input text file to check. This file will contain a number of words.
For this assignment a word is any sequence of one or more characters separated by one or more Spaces or newlines. You could be reading text from a book, so you have to delete starting and ending quotations, and delete periods, question marks, exclamation marks and semi-colons from the back of the string (Conveniently strings have a .back member function, and the first character is at [0]). If you include cctype, you will be able to ask if isalnum. Also remember the purpose of
Read the document, and separate it into a sequence of words converted to lowercase. Use http://www.cplusplus.com/reference/locale/tolower/ (Links to an external site.) as an example way to convert. A for loop could be useful in converting all characters.
Print out the words that could be mispelled, then print out the # of Words in the Dictionary, # of Words in the File, # of words not in the dictionary.
Here are two files to check against (you may be a few off depending on how you coded):
check.txt
25021 dictionary words, 29 words in file, 4 misspelled
Potter.txt
25021 dictionary words, 78452 words in file, 19531 misspelled
/********************************************************************************/
HASH TABLES
A hash table contains buckets into which an object (data item) can be placed. When a hash function is applied to an object, a hash value is generated. The hash value is used to determine which bucket the object is assigned to. A bucket is a cluster (or a sub container) that holds a set of data items that hash to the same table location. Obviously, you can not store 25K words in 1373 slots and you need to use some kind of chaining schemes such as linear probing or the second hashing. The size of a bucket is independent from the number of data items you put into the hash. So if you have too many buckets, the hash will not have many collisions but you may waste the storage and you may have to deal with a rather complex hash function and longer keys. If you have too small number of buckets, then you have to deal with frequent collisions. Finding a good bucket number would play an important role in reducing collisions. That's why we usually pick a prime number for the number of bucket. We picked 1373 for the bucket number.
/*************************************************************************************/
IMPLEMENTATION
Implement with an array (SIZE=1373) of linked lists. Your linked lists should contain the word that was hashed to that array. When you land on a particular array cell (equal to the hash of the word), traverse the linked list until you either find the word, or the nullptr...then add the word. (You can use the STL list if you choose). For your hash function, you will be hashing strings.
To get a hash string you should declare a variable something like this: hash hashStr;
then when you want to hash a particular string (let's say called string1)
hashStr(string1);
This "function" will produce a long data type (which you should mod by 1373)
You don't have to interpret verb tense, plurals, conjugations etc. All you have to do is to check with each word against the dictionary.
Part of dict.dat
a a&m a&p aaa aaas aarhus aaron aau aba ababa aback abacus abalone abandon abase abash abate abater abbas abbe abbey abbot abbott abbreviate abc abdicate abdomen abdominal abduct abe abed abel abelian abelson aberdeen abernathy aberrant aberrate abet abetted abetting abeyance abeyant abhorred abhorrent abide abidjan abigail abject ablate ablaze able ablution abner abnormal abo aboard abode abolish abolition abominable abominate aboriginal aborigine aborning abort abound about above aboveboard aboveground abovementioned abrade abraham abram abramson abrasion abrasive abreact abreast abridge abridgment abroad abrogate abrupt abscess abscissa abscissae absence absent absentee absenteeism absentia absentminded absinthe absolute absolution absolve absorb absorbent absorption absorptive abstain abstention abstinent abstract abstracter abstractor abstruse absurd abuilding abundant abusable abuse abusive abut
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started