Advertisement
Metaraddin

Untitled

Dec 19th, 2019
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Word {
  6. private:
  7. string value;
  8. string font;
  9. int size;
  10.  
  11. public:
  12. Word(string valueInp, string fontInp, int sizeInp) {
  13. value = valueInp;
  14. font = fontInp;
  15. if (sizeInp < 1) { size = 1; }
  16. else if (sizeInp > 72) { size = 72; }
  17. else { size = sizeInp; }
  18. }
  19.  
  20. ~Word() {}
  21.  
  22. string getValue() { return value; }
  23. string getFont() { return font; }
  24. int getSize() { return size; }
  25.  
  26. void setValue(string valueInp) { value = valueInp; }
  27. void setFont(string fontInp) { font = fontInp; }
  28. void setSize(int sizeInp) {
  29. if (sizeInp < 1) { size = 1; }
  30. else if (sizeInp > 72) { size = 72; }
  31. else { size = sizeInp; }
  32. }
  33. };
  34.  
  35.  
  36. class Editor
  37. {
  38. private:
  39. vector <Word> mas;
  40. public:
  41. Editor() {}
  42. ~Editor() {}
  43.  
  44. void addWord(Word word) {
  45. mas.push_back(word);
  46. }
  47.  
  48. bool insert(int ind, Word word) {
  49. if ((ind >= 0) && (ind < mas.size())) {
  50. mas.insert(mas.begin() + ind, word);
  51. return true;
  52. }
  53. return false;
  54. }
  55.  
  56. bool erase(int ind) {
  57. if ((ind >= 0) && (ind < mas.size())) {
  58. mas.erase(mas.begin() + ind);
  59. return true;
  60. }
  61. return false;
  62. }
  63.  
  64. void replace(string value, Word word) {
  65. for (int i = 0; i < mas.size(); i++) {
  66. if (mas.at(i).getValue() == value) {
  67. mas.at(i) = word;
  68. }
  69. }
  70. }
  71.  
  72. bool swap(int ind1, int ind2) {
  73. if ((ind1 >= 0) && (ind2 >= 0) && (ind1 < mas.size()) && (ind2 < mas.size())) {
  74. Word temp = mas.at(ind1);
  75. mas.at(ind1) = mas.at(ind2);
  76. mas.at(ind2) = temp;
  77. return true;
  78. }
  79. return false;
  80. }
  81.  
  82. bool setValue(int ind, string value) {
  83. if ((ind >= 0) && (ind < mas.size())) {
  84. mas.at(ind).setValue(value);
  85. return true;
  86. }
  87. return false;
  88. }
  89. };
  90.  
  91. class Menu {
  92. private:
  93. Editor editor;
  94.  
  95. Word newWord() {
  96. cout << "Введите значение слова: ";
  97. string value;
  98. cin >> value;
  99.  
  100. cout << "Введите название шрифта: ";
  101. string font;
  102. cin >> font;
  103.  
  104. cout << "Введите размер шрифта: ";
  105. int size;
  106. cin >> size;
  107.  
  108. return Word(value, font, size);
  109. }
  110.  
  111. int newInd(string num = "") {
  112. cout << "Введите индекс " << num << ": ";
  113. int ind;
  114. cin >> ind;
  115.  
  116. return ind;
  117. }
  118.  
  119. public:
  120. Menu() {}
  121. ~Menu() {}
  122.  
  123. void show() {
  124. int choice = -1;
  125. cout << "Выберите задачу:\n"
  126. << "1 - Добавить слово"
  127. << "2 - Вставить слово"
  128. << "3 - Удалить слово"
  129. << "4 - Заменить слово по значению"
  130. << "5 - Поменять слова местами"
  131. << "6 - Установить значение слова"
  132. << "0 - Выход";
  133.  
  134. cin >> choice;
  135. while (choice != 0) {
  136. string value;
  137. switch (choice) {
  138. case 1:
  139. editor.addWord(newWord());
  140. break;
  141. case 2:
  142. editor.insert(newInd(), newWord());
  143. break;
  144. case 3:
  145. editor.erase(newInd());
  146. break;
  147. case 4:
  148. cout << "Введите значение слова: ";
  149. cin >> value;
  150. editor.replace(value, newWord());
  151. break;
  152. case 5:
  153. editor.swap(newInd("1"), newInd("2"));
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. }
  160. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement