Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dictionary
- {
- char** words;
- int dictionarySize;
- char* meaning;
- void rePlace(char** &first, char** &second, int size)
- {
- for (int i = 0; i < size; i++)
- {
- int lenght = strlen(second[i]) + 1;
- first[i] = new char[lenght];
- strcpy_s(first[i], lenght, second[i]);
- }
- }
- void copyDic(const Dictionary& other)
- {
- this->dictionarySize = other.dictionarySize;
- for (int i = 0; i < other.dictionarySize; i++)
- {
- int lenght = strlen(other.words[i]) + 1;
- this->words[i] = new char[lenght];
- strcpy_s(this->words[i], lenght, other.words[i]);
- }
- }
- public:
- Dictionary()
- {
- this->words = nullptr;
- this->dictionarySize = 0;
- this->meaning = nullptr;
- }
- void setSize(const int _dictionarySize)
- {
- this->dictionarySize = _dictionarySize;
- this->words = new char*[dictionarySize];
- }
- Dictionary(const int _dictionarySize)
- {
- setSize(_dictionarySize);
- }
- void setWord(const int position, const char* _word)
- {
- int lenght = strlen(_word) + 1;
- this->words[position] = new char[lenght];
- strcpy_s(this->words[position], lenght, _word);
- }
- int getSize()
- {
- return this->dictionarySize;
- }
- char* getWord(const int position)
- {
- return this->words[position];
- }
- Dictionary(Dictionary& other)
- {
- copyDic(other);
- }
- Dictionary& operator = (Dictionary& other)
- {
- if (this != &other)
- copyDic(other);
- return *this;
- }
- void reSize(const int _newSize)
- {
- int tempSize = this->dictionarySize;
- char** tempArray = new char*[this->dictionarySize];
- rePlace(tempArray, this->words, this->dictionarySize);
- delete[] this->words;
- this->setSize(_newSize);
- rePlace(this->words, tempArray, tempSize);
- }
- void printWord(const int position)
- {
- cout << this->words[position] << endl;
- }
- void printAll()
- {
- for (int i = 0; i <this->dictionarySize; i++)
- cout << this->words[i] << " ";
- }
- ~Dictionary()
- {
- if (this->words != nullptr)
- delete[] words;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement