Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- using namespace std;
- class Word {
- private:
- string value;
- string font;
- int size;
- public:
- Word(string valueInp, string fontInp, int sizeInp) {
- value = valueInp;
- font = fontInp;
- if (sizeInp < 1) { size = 1; }
- else if (sizeInp > 72) { size = 72; }
- else { size = sizeInp; }
- }
- ~Word() {}
- string getValue() { return value; }
- string getFont() { return font; }
- int getSize() { return size; }
- void setValue(string valueInp) { value = valueInp; }
- void setFont(string fontInp) { font = fontInp; }
- void setSize(int sizeInp) {
- if (sizeInp < 1) { size = 1; }
- else if (sizeInp > 72) { size = 72; }
- else { size = sizeInp; }
- }
- };
- class Editor
- {
- private:
- vector <Word> mas;
- public:
- Editor() {}
- ~Editor() {}
- void addWord(Word word) {
- mas.push_back(word);
- }
- bool insert(int ind, Word word) {
- if ((ind >= 0) && (ind < mas.size())) {
- mas.insert(mas.begin() + ind, word);
- return true;
- }
- return false;
- }
- bool erase(int ind) {
- if ((ind >= 0) && (ind < mas.size())) {
- mas.erase(mas.begin() + ind);
- return true;
- }
- return false;
- }
- void replace(string value, Word word) {
- for (int i = 0; i < mas.size(); i++) {
- if (mas.at(i).getValue() == value) {
- mas.at(i) = word;
- }
- }
- }
- bool swap(int ind1, int ind2) {
- if ((ind1 >= 0) && (ind2 >= 0) && (ind1 < mas.size()) && (ind2 < mas.size())) {
- Word temp = mas.at(ind1);
- mas.at(ind1) = mas.at(ind2);
- mas.at(ind2) = temp;
- return true;
- }
- return false;
- }
- bool setValue(int ind, string value) {
- if ((ind >= 0) && (ind < mas.size())) {
- mas.at(ind).setValue(value);
- return true;
- }
- return false;
- }
- };
- class Menu {
- private:
- Editor editor;
- Word newWord() {
- cout << "Введите значение слова: ";
- string value;
- cin >> value;
- cout << "Введите название шрифта: ";
- string font;
- cin >> font;
- cout << "Введите размер шрифта: ";
- int size;
- cin >> size;
- return Word(value, font, size);
- }
- int newInd(string num = "") {
- cout << "Введите индекс " << num << ": ";
- int ind;
- cin >> ind;
- return ind;
- }
- public:
- Menu() {}
- ~Menu() {}
- void show() {
- int choice = -1;
- cout << "Выберите задачу:\n"
- << "1 - Добавить слово"
- << "2 - Вставить слово"
- << "3 - Удалить слово"
- << "4 - Заменить слово по значению"
- << "5 - Поменять слова местами"
- << "6 - Установить значение слова"
- << "0 - Выход";
- cin >> choice;
- while (choice != 0) {
- string value;
- switch (choice) {
- case 1:
- editor.addWord(newWord());
- break;
- case 2:
- editor.insert(newInd(), newWord());
- break;
- case 3:
- editor.erase(newInd());
- break;
- case 4:
- cout << "Введите значение слова: ";
- cin >> value;
- editor.replace(value, newWord());
- break;
- case 5:
- editor.swap(newInd("1"), newInd("2"));
- break;
- default:
- break;
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement