Question
In this assignment, you will write a program (dictionary.cc) that a user can add a word, delete a word, search a word, and list all
In this assignment, you will write a program (dictionary.cc) that a user can add a word, delete a word, search a word, and list all words in a dictionary. The user can issue the following commands (all in capital letters).
ADD aword Add aword into the dictionary. If aword already exists in the dictionary, display aword is already added.. Otherwise, add it to the end of the dictionary and display aword is added.. DELETE aword Delete aword from the dictionary. If aword does not exist in the dictionary, display aword is not found.. Otherwise, delete it from the dictionary and display aword is deleted.. SEARCH aword Search aword in the dictionary. If aword does not exist in the dictionary, display aword is not found.. Otherwise, display aword is found. and display the number of comparisons. LIST List all the words in the current dictionary, one word one line. EXIT Display bye bye and exit to the terminals prompt
the following functions must be used
(a) string* myAdd(string *dictionary, int &wordCount, string aWord); This function implements the command ADD as discussed above. In this function, if the aword is added to the dictionary, you need to resize the dictionary and return the new dictionary. (
b) string *myDelete(string *dictionary, int &wordCount, string aWord); This function implements the command DELETE as discussed above. In this function, if aword is deleted from the dictionary, you need to resize the dictionary.
(c) void mySearch(string dictionary[], int wordCount, string aWord); This function implements the command SEARCH as discussed above. In this function, you will call another function called linear_search which will be discussed below.
(d) void myList(string dictionary[], int wordCount); This function implements the command LIST as discussed above. In this function, you list each word, one on a line, from the dictionary.
(e) void myExit(); This function implements the command EXIT as discussed above.
(f) bool linearSearch(const string dictionary[], int wordCount, string aword, int &count); This function returns true if aword can be found in dictionary of wordCount words, and false otherwise. Use the linear search algorithm. The count parameter should return the number of comparisons made to array elements. (
g) Write the main function which prompts the user to issue a command, processes the command, and then repeats. It can be easily seen that the main function is just a switch board. It analyzes the input string, figures out the command, and then calls the corresponding function. You must implement the dictionary as an array.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started