Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. class Dictionary
  2. {
  3. char** words;
  4. int dictionarySize;
  5. char* meaning;
  6.  
  7. void rePlace(char** &first, char** &second, int size)
  8. {
  9. for (int i = 0; i < size; i++)
  10. {
  11. int lenght = strlen(second[i]) + 1;
  12. first[i] = new char[lenght];
  13. strcpy_s(first[i], lenght, second[i]);
  14. }
  15. }
  16.  
  17. void copyDic(const Dictionary& other)
  18. {
  19. this->dictionarySize = other.dictionarySize;
  20. for (int i = 0; i < other.dictionarySize; i++)
  21. {
  22. int lenght = strlen(other.words[i]) + 1;
  23. this->words[i] = new char[lenght];
  24. strcpy_s(this->words[i], lenght, other.words[i]);
  25. }
  26.  
  27. }
  28. public:
  29. Dictionary()
  30. {
  31. this->words = nullptr;
  32. this->dictionarySize = 0;
  33. this->meaning = nullptr;
  34. }
  35.  
  36. void setSize(const int _dictionarySize)
  37. {
  38. this->dictionarySize = _dictionarySize;
  39. this->words = new char*[dictionarySize];
  40. }
  41.  
  42. Dictionary(const int _dictionarySize)
  43. {
  44. setSize(_dictionarySize);
  45. }
  46. void setWord(const int position, const char* _word)
  47. {
  48. int lenght = strlen(_word) + 1;
  49. this->words[position] = new char[lenght];
  50. strcpy_s(this->words[position], lenght, _word);
  51. }
  52. int getSize()
  53. {
  54. return this->dictionarySize;
  55. }
  56. char* getWord(const int position)
  57. {
  58. return this->words[position];
  59. }
  60. Dictionary(Dictionary& other)
  61. {
  62. copyDic(other);
  63. }
  64. Dictionary& operator = (Dictionary& other)
  65. {
  66. if (this != &other)
  67. copyDic(other);
  68. return *this;
  69. }
  70. void reSize(const int _newSize)
  71. {
  72. int tempSize = this->dictionarySize;
  73. char** tempArray = new char*[this->dictionarySize];
  74. rePlace(tempArray, this->words, this->dictionarySize);
  75. delete[] this->words;
  76. this->setSize(_newSize);
  77. rePlace(this->words, tempArray, tempSize);
  78. }
  79.  
  80. void printWord(const int position)
  81. {
  82. cout << this->words[position] << endl;
  83. }
  84. void printAll()
  85. {
  86. for (int i = 0; i <this->dictionarySize; i++)
  87. cout << this->words[i] << " ";
  88. }
  89. ~Dictionary()
  90. {
  91. if (this->words != nullptr)
  92. delete[] words;
  93. }
  94. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement