Question

You are given an input C++ string and a dictionary of English words. You are asked...

You are given an input C++ string and a dictionary of English words. You are asked to see if the input is consisted of words only in the dictionary. For example:

Example #1

Input string = "joe";

Input dictionary = { "joe1", "joe" };

Output: true

Explanation: "joe" is in the dictionary.

Example #2

Input string = "joey";

Input dictionary = { "joe1", "joe" };

Output: false

Explanation: even though "joe" is in the dictionary, "y" is not.

Example #3

Input string = "applepie";

Input dictionary = { "pie", "apple" };

Output: true

Explanation: "apple" and "pie" are both in the dictionary.

Example #4

Input string = "hellonow";

Input dictionary = { "hello", "on", "hell", "now" };

Output: true

Explanation: "hello" and "now" are both in the dictionary.

Example #5

Input string = "hellonowl";

Input dictionary = { "hell", "on", "owl" };

Output: true

Explanation: "hell", "on", and "owl" are all in the dictionary.

Implement the following class method that takes the input string and a dictionary of English words, and checks to see if the given input is composed of only the words from the input dictionary:

class CIS14 {
   public:
      bool isInputInDictionary(string* s, unordered_set<string> &dict);
};

Constraints / Assumptions:

  • The input string cannot be NULL.
  • The input dictionary cannot be NULL; it has at least one English words.
  • The method takes a pointer to the input string.
  • The method takes a reference of the input dictionary.
  • HINT: this solution calls for recursion.
  • Your main() won't be graded but your class and its functionality will be graded.
  • It is your responsibility to compile your code in C++11/C++14 (no pre-C++11!). Failure to do that means your code isn't compilable and you will receive 0 points.
  • Wrong member function signature or wrong class declaration receive -1 styling point each
  • Grading for this problem is as follows:

Logic: 8 points (-1 point for each test failure)

Styling/Documentation: 2 points (-1 for wrong function signature, -1 for wrong class declaration, and/or -1 for lack of documentation)

PreviousNext

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

#include<iostream>

#include<string>

#include<unordered_set>

using namespace std;

class CIS14 {

public:

bool isInputInDictionary(string* s, unordered_set<string> &dict);

};

bool CIS14::isInputInDictionary(string* s, unordered_set<string> &dict){

unordered_set<string>::iterator itr;

for (itr = dict.begin(); itr != dict.end(); itr++){

if(*itr == *s)

return true;

}

return false;

}

int main(){

string str = "joey";

unordered_set<string> dict = {"joe1", "joe"};

CIS14 test;

cout<<test.isInputInDictionary(&str, dict)<<endl;

}

Add a comment
Know the answer?
Add Answer to:
You are given an input C++ string and a dictionary of English words. You are asked...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help writing this C code. Here is the description: Let's say we have a...

    I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know,  for each word in the dictionary,...

  • Write a French/English dictionary lookup program. Read a list of pairs of English and French words...

    Write a French/English dictionary lookup program. Read a list of pairs of English and French words from a file specified by the user. English/French words should be exact matches (don't try to find partial matches). Use the supplied EnglishFrenchDictionary.java class as your main class. Fill in the missing code in the DictionaryTable.java class to read the input file and perform the searches. Add code to the DictionaryTable read() method to: read pairs of lines (English word is on the first...

  • CODE: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as...

    CODE: def censor_words(sentence, list_of_words): """ The function takes a sentence and a list of words as input. The output is the sentence after censoring all the matching words in the sentence. Censoring is done by replacing each character in the censored word with a * sign. For example, the sentence "hello yes no", if we censor the word yes, will become "hello *** no" Note: do not censor the word if it is part of a larger word. For example,...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • Modification of original code so it can include 1) at least one array 2)*New English words...

    Modification of original code so it can include 1) at least one array 2)*New English words that are written/saved to the .txt file(s) must be in alphabetical order* (e.g, Apple cannot be in a lower line than Orange). This is what I'm really struggling with as I don't know how to organize alphabetically only the english word translation without the spanish equivalent word also getting organized. The only idea I have right now is to recreate the code using two...

  • Complete the following code: You are asked to write some functionalities for a spelling checker i...

    Complete the following code: You are asked to write some functionalities for a spelling checker inside Tree.java that has at least the following methods: /*Adds a word to a spelling checker’s collection of correctly spelled words*/ void add(String word) /*Returns true if the given word is spelled correctly*/ boolean check(String word) /*Returns back all words in the tree in alphabetical order*/ public String getDictionaryInAlphabeticalOrder() Store the collection of correctly spelled words in a 26-ary tree. The number 26 indicates that...

  • 26-ary tree for spell checker in JAVA You are asked to write some functionalities for a...

    26-ary tree for spell checker in JAVA You are asked to write some functionalities for a spelling checker inside Tree.java that has at least the following methods: /*Adds a word to a spelling checker’s collection of correctly spelled words*/ void add(String word) /*Returns true if the given word is spelled correctly*/ boolean check(String word) /*Returns back all words in the tree in alphabetical order*/ public String getDictionaryInAlphabeticalOrder() Store the collection of correctly spelled words in a 26-ary tree. The number...

  • In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need...

    In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1. If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end. 2. If the word begins with...

  • Two words or phrases in English are anagrams if their letters (and only their letters), rearranged,...

    Two words or phrases in English are anagrams if their letters (and only their letters), rearranged, are the same. We assume that upper and lower case are indistinguishable, and punctuation and spaces don't count. Two phrases are anagrams if they contain exactly the same number of exactly the same letters, e.g., 3 A's, 0 B's, 2 C's, and so forth. Some examples and non-examples of regular anagrams: * The eyes / they see (yes) * moo / mo (no) *...

  • Using loops with the String and Character classes. You can also use the StringBuilder class to...

    Using loops with the String and Character classes. You can also use the StringBuilder class to concatenate all the error messages. Floating point literals can be expressed as digits with one decimal point or using scientific notation. 1 The only valid characters are digits (0 through 9) At most one decimal point. At most one occurrence of the letter 'E' At most two positive or negative signs. examples of valid expressions: 3.14159 -2.54 2.453E3 I 66.3E-5 Write a class definition...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT