0

How to put a dictionary in C++, and more?

-including swapping adjacent characters in a word, -inserting a single character in between two adjacent characters in a word, -deleting a single character from a word, and -replacing a character in a word with another character

7th Apr 2018, 8:52 PM
Anfernee Skinner
Anfernee Skinner - avatar
8 odpowiedzi
+ 1
Object called Word, that has an internal private data structure that is a String, representing a word. Then public methods that do what you want to the word, declared something like this: bool swapAdjacentCharacters(int letterIndex) bool insertCharacterBetweenAdjacentCharacter(int letterIndex, char characterToInsert) Does that give you enough to get on with?
7th Apr 2018, 9:34 PM
Emma
+ 1
Thank you, would it make a difference if I use void instead of bool?
7th Apr 2018, 10:18 PM
Anfernee Skinner
Anfernee Skinner - avatar
+ 1
I'd do #include <array> array<string, 10> HashTable; Try to avoid handcrafted data structures and raw pointers.
8th Apr 2018, 7:48 AM
Timon Paßlick
+ 1
And don't use namespace std in a header file because you force everybody who includes it to use it, too.
8th Apr 2018, 7:50 AM
Timon Paßlick
0
void is fine. Bool was just so if the function failed, it could return false. This is to improve error checking. Example, if word is a single character "a" or "I", functions will fail. If index specified is bigger than the word length,.etc. You should probably capture errors.
7th Apr 2018, 10:26 PM
Emma
0
Should I use a data type char, or string when I'm declaring a variable to represent words?
7th Apr 2018, 10:45 PM
Anfernee Skinner
Anfernee Skinner - avatar
0
String, as there are more things you can do to a string, and it's less prone to pointer problems.
7th Apr 2018, 10:52 PM
Emma
0
This is my header file so far: #include <cstdlib> #include <iostream> #include <string> using namespace std; #ifndef SPELL_H #define SPELL_H class spellchecker { private: static const int tableSize = 10; struct item { string W; item* next; }; item*HashTable[tableSize]; public: spellchecker(); int Spellchecks(string s); bool Insert(string W); bool swapAdjChar(); void SpellCheck(); void Remove(); }; #endif /*SPELL_H*/
7th Apr 2018, 11:11 PM
Anfernee Skinner
Anfernee Skinner - avatar