Advertisement
irmantas_radavicius

Untitled

Mar 23rd, 2022
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. string command, new_Word;
  7.  
  8. class Validator {
  9. private:
  10.     vector< string > words = {"hello", "hi", "goodbye", "greetings"};
  11. public:
  12.     int add_word(string word) {
  13.         this -> words.push_back(word);
  14.         return 1;
  15.     }
  16.     int check_word(string word) {
  17.         for (int i = 0; i < words.size(); i++) {
  18.             if (word == words[i]) return 1;
  19.         }
  20.         return 0;
  21.     }
  22.     string get_Word(int i) {
  23.         return words[i];
  24.     }
  25.     int len_Dict() {
  26.         return words.size();
  27.     }
  28. };
  29.  
  30. int main() {
  31.     while (1) {
  32.         Validator Validate;
  33.         cout << "Please type 'add' if you want to add words into the dictionary and type 'check' for the words you want to check and 'get' for all current words" << endl;
  34.         cin >> command;
  35.         if (command != "get") {
  36.             cin >> new_Word;
  37.         }
  38.         if (command == "add") {
  39.             Validate.add_word(new_Word);
  40.             cout << "Your word: " << new_Word << " has been added successfully" << endl;
  41.         }
  42.         else if (command == "check") {
  43.             if (Validate.check_word(new_Word)) cout << "Your word is correct" << endl;
  44.             else cout << "Your word is incorrect" << endl;
  45.         }
  46.         else if (command == "get") {
  47.             for (int i = 0; i < Validate.len_Dict(); i++) {
  48.                 cout << Validate.get_Word(i) << endl;
  49.             }
  50.         }
  51.         else cout << "Your command is not recognized" << endl;
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement