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;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 <vector>
#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", "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<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:
Transcribed Image Text: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:
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.
Transcribed Image Text: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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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):
Transcribed Image Text: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):
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!
Transcribed Image Text: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!
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education