Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- string command, new_Word;
- class Validator {
- private:
- vector< string > words = {"hello", "hi", "goodbye", "greetings"};
- public:
- int add_word(string word) {
- this -> words.push_back(word);
- return 1;
- }
- int check_word(string word) {
- for (int i = 0; i < words.size(); i++) {
- if (word == words[i]) return 1;
- }
- return 0;
- }
- string get_Word(int i) {
- return words[i];
- }
- int len_Dict() {
- return words.size();
- }
- };
- int main() {
- while (1) {
- Validator Validate;
- 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;
- cin >> command;
- if (command != "get") {
- cin >> new_Word;
- }
- if (command == "add") {
- Validate.add_word(new_Word);
- cout << "Your word: " << new_Word << " has been added successfully" << endl;
- }
- else if (command == "check") {
- if (Validate.check_word(new_Word)) cout << "Your word is correct" << endl;
- else cout << "Your word is incorrect" << endl;
- }
- else if (command == "get") {
- for (int i = 0; i < Validate.len_Dict(); i++) {
- cout << Validate.get_Word(i) << endl;
- }
- }
- else cout << "Your command is not recognized" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement