This is only stage 1 of 5 on a C++ coding lab I am struggling with. Here is my code so far: #include #include #include #include #include #include using namespace std; vector dictionary1 = {"airy", "aisle", "aisles", "ajar", "akimbo", "akin", "juveniles", "juxtapose", "knowledges", "known", "president", "tries", "trifle", "tugs", "wrongdoers", "wroth", "wyvern", "xenophon", "xylol", "yodle", "yurt", "zeugma", "ziggurat", "zootomy"}; vector dictionary2 = {"aback", "abased", "acknowledgers", "administers", "affair", "aforementioned", "aggrieving", "agitating", "agree", "airlines", "ajar", "basin", "bawdy", "cheap", "cheated", "examiner", "excel", "lewdness", "liberal", "mathematician", "ordered", "president", "sandwich", "swagger", "swarm", "vomit", "yell", "zero" "zodiac", "zoo"}; vector dictionary3 = {"ajar", "anachronism", "basin", "bawdy", "bleed", "bystander", "chariot", "cheap", "cheated", "clay", "contrive", "critiques", "databases", "derivative", "dog", "earthenware", "echo", "examiner", "excel", "fatiguing", "floppy", "goldsmith", "halt", "implies", "jam", "klutz", "lively", "malt", "meteor", "nonsense", "orphans", "paint", "playful", "railroad", "revolt", "shark", "spook", "syntax", "tablet", "thing", "ugly", "vigilant", "whirr", "yell", "zap", "zoo"}; void add_word(vector& dictionary, const string& word) { dictionary.push_back(word); sort(dictionary.begin(), dictionary.end()); } void delete_word(vector& dictionary, const string& word) { dictionary.erase(remove(dictionary.begin(), dictionary.end(), word), dictionary.end()); } int search_word(const vector& dictionary, const string& word) { for (size_t i = 0; i < dictionary.size(); ++i) { if (dictionary[i] == word) { return i; } } return -1; } void swap_words(vector& dictionary, const string& word1, const string& word2) { int idx1 = search_word(dictionary, word1); int idx2 = search_word(dictionary, word2); if (idx1 != -1 && idx2 != -1) { swap(dictionary[idx1], dictionary[idx2]); } } int main() { int dictionary_choice; string search, del; vector> dictionaries = {dictionary1, dictionary2, dictionary3}; cout << "Which Dictionary should be opened? Enter \"1\", \"2\", or \"3\": "; cin >> dictionary_choice; dictionary_choice--; int idx, del_idx; while (true) { cout << "\n--------------------------------------------\n" << "Options menu: \n" << "(1) Print words\n" << "(2) Find a word\n" << "(3) Find word, insert if found (assumes words are sorted alphabetically)\n" << "(4) Find word, delete if found \n" << "(5) Swap two words\n" << "(6) Sort words (Bubble Sort or Selection Sort)\n" << "(7) Find a word - Binary Search (assumes words are sorted alphabetically)\n" << "(8) Merge two dictionaries (will sort first)\n" << "(9) Write current dictionary to file\n" << "Enter a number from 1 to 9, or 0 to exit: "; int choice; cin >> choice;
This is only stage 1 of 5 on a C++ coding lab I am struggling with. Here is my code so far:
#include <iostream>
#include <
#include <fstream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
vector<string> dictionary1 = {"airy", "aisle", "aisles", "ajar", "akimbo", "akin", "juveniles", "juxtapose", "knowledges", "known", "president", "tries", "trifle", "tugs", "wrongdoers", "wroth", "wyvern", "xenophon", "xylol", "yodle", "yurt", "zeugma", "ziggurat", "zootomy"};
vector<string> dictionary2 = {"aback", "abased", "acknowledgers", "administers", "affair", "aforementioned", "aggrieving", "agitating", "agree", "airlines", "ajar", "basin", "bawdy", "cheap", "cheated", "examiner", "excel", "lewdness", "liberal", "mathematician", "ordered", "president", "sandwich", "swagger", "swarm", "vomit", "yell", "zero" "zodiac", "zoo"};
vector<string> dictionary3 = {"ajar", "anachronism", "basin", "bawdy", "bleed", "bystander", "chariot", "cheap", "cheated", "clay", "contrive", "critiques", "
void add_word(vector<string>& dictionary, const string& word) {
dictionary.push_back(word);
sort(dictionary.begin(), dictionary.end());
}
void delete_word(vector<string>& dictionary, const string& word) {
dictionary.erase(remove(dictionary.begin(), dictionary.end(), word), dictionary.end());
}
int search_word(const vector<string>& dictionary, const string& word) {
for (size_t i = 0; i < dictionary.size(); ++i) {
if (dictionary[i] == word) {
return i;
}
}
return -1;
}
void swap_words(vector<string>& dictionary, const string& word1, const string& word2) {
int idx1 = search_word(dictionary, word1);
int idx2 = search_word(dictionary, word2);
if (idx1 != -1 && idx2 != -1) {
swap(dictionary[idx1], dictionary[idx2]);
}
}
int main() {
int dictionary_choice;
string search, del;
vector<vector<string>> dictionaries = {dictionary1, dictionary2, dictionary3};
cout << "Which Dictionary should be opened? Enter \"1\", \"2\", or \"3\": ";
cin >> dictionary_choice;
dictionary_choice--;
int idx, del_idx;
while (true) {
cout << "\n--------------------------------------------\n"
<< "Options menu: \n"
<< "(1) Print words\n"
<< "(2) Find a word\n"
<< "(3) Find word, insert if found (assumes words are sorted alphabetically)\n"
<< "(4) Find word, delete if found \n"
<< "(5) Swap two words\n"
<< "(6) Sort words (Bubble Sort or Selection Sort)\n"
<< "(7) Find a word - Binary Search (assumes words are sorted alphabetically)\n"
<< "(8) Merge two dictionaries (will sort first)\n"
<< "(9) Write current dictionary to file\n"
<< "Enter a number from 1 to 9, or 0 to exit: ";
int choice;
cin >> choice;
![This assignment will be built in stages. When one stage is finished and passes the testing, copy your
code from that part and use it to start the next part.
Start this second piece of the Linked List program by copying your successful code from Lab "Bi-Directional Linked List (1 of 3), Part V". To
better manage our increasing functionality, we will set up a menu.
The program will still start by asking which dictionary to open and loading it into your linked list. The new menu will come next. The
program should ask:
Options menu:
(1) Print words.
(2) Find a word.
(3) Find word, insert if found (assumes words are sorted alphabetically)
(4) Find word, delete if found
(5) Swap two words
(6) Sort words (Bubble Sort or Selection Sort)
(7) Find a word - Binary Search (assumes words are sorted alphabetically)
(8) Merge two dictionaries (will sort first)
(9) Write current dictionary to file
Enter a number from 1 to 9, or 0 to exit:](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9974cb88-485f-4954-981d-1d67477878d4%2F0d3f4ff0-7757-4ae0-b34b-a9ed709baa49%2Folb6mkn_processed.png&w=3840&q=75)
![The code for the output could be:
cout << "\n----
-\n"
<< "Options menu: \n"
<< "(1) Print words\n"
<<"(2) Find a word\n"
<< "(3) Find word, insert if found (assumes words are sorted alphabetically) \n"
<<"(4) Find word, delete if found \n"
<< "(5) Swap two words\n"
<<"(6) Sort words (Bubble Sort or Selection Sort) \n"
<< "(7) Find a word - Binary Search (assumes words are sorted alphabetically) \n"
<<"(8) Merge two dictionaries (will sort first) \n"
<< "(9) Write current dictionary to file\n"
<< "Enter a number from 1 to 9, or 0 to exit: ";
For now, all options that aren't yet done, for instance if the user enters "6", should return:
Coming soon!
These choices should be on a loop, so if the user chooses "1", the list would print to the screen, and then the options menu and prompt
would reappear. If the user enters anything not on the menu, it should be treated as entering "0" and the program would exit with:
Thank you! Bye!
The already implemented code, like print, find, insert, etc., should work just as in the previous part.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9974cb88-485f-4954-981d-1d67477878d4%2F0d3f4ff0-7757-4ae0-b34b-a9ed709baa49%2Fdb460uh_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
I wanted to put an example of one of the tests it was supposed to pass but there wasn't enough room. Can you adjust the code so the output is what the expected output is? I can't seem to do that without messing up the code even more.
![Which Dictionary should be opened? Enter "1", "2", or "3":
Options menu:
(1) Print words
(2) Find a word
(3) Find word, insert if found (assumes words are sorted alphabetically)
(4) Find word, delete if found
(5) Swap two words
(6) Sort words (Bubble Sort or Selection Sort)
(7) Find a word - Binary Search (assumes words are sorted alphabetically
(8) Merge two dictionaries (will sort first)
(9) Write current dictionary to file
Enter a number from 1 to 9, or 0 to exit: airy
aisle
aisles
ajar
akimbo
akin
juveniles
juxtapose
knowledges
known
president
tries
trifle
tugs
wrongdoers
wroth
wyvern
xenophon
xylol
yodle
yurt
zeugma
ziggurat
zootomy
Enter the word you want to find: The word "0" was not found in the dicti
Enter the word you want to find and insert if not found: The word "0" wa
Enter the word you want to find and delete if found: The word " was not
Enter the first word to swap: Enter the second word to swap: Sorting the
Enter the word you want to find (Binary Search): Found "0" at position
Choose a second dictionary to merge (1, 2, or 3):](https://content.bartleby.com/qna-images/question/9974cb88-485f-4954-981d-1d67477878d4/59fd6231-2cef-4a26-bd61-1776895a16a9/tzyjy5l_thumbnail.png)
![Which Dictionary should be opened? Enter "1", "2", or "3":
Options menu:
(1) Print words
(2) Find a word
(3) Find word, insert if found (assumes words are sorted alphabetically)
(4) Find word, delete if found
(5) Swap two words
(6) Sort words (Bubble Sort or Selection Sort)
(7) Find a word - Binary Search (assumes words are sorted alphabetically
(8) Merge two dictionaries (will sort first)
(9) Write current dictionary to file
Enter a number from 1 to 9, or 0 to exit:
airy
aisle
aisles
ajar
akimbo
akin
juveniles
juxtapose
knowledges
known
president
tries
trifle
tugs
wrongdoers
wroth
wyvern
xenophon
xylol
yodle
yurt
zeugma
ziggurat
zootomy
Options menu:
(1) Print words
(2) Find a word
(3) Find word, insert if found (assumes words are sorted alphabetically)
(4) Find word, delete if found
(5) Swap two words
(6) Sort words (Bubble Sort or Selection Sort)
(7) Find a word Binary Search (assumes words are sorted alphabetically
(8 Merge two dictionaries (will sort first)
19 Write current dictionary to file
Enter a number from 1 to 9, or 0 to exit:
Thank you! Bye!](https://content.bartleby.com/qna-images/question/9974cb88-485f-4954-981d-1d67477878d4/59fd6231-2cef-4a26-bd61-1776895a16a9/vuosyso_thumbnail.png)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)