Question

In: Computer Science

THIS ASSIGNMENT MUST BE DONE IN C++ 17 AND MUST FOLLOW EACH GUIDELINE LISTED BELOW. INSTRUCTIONS...

THIS ASSIGNMENT MUST BE DONE IN C++ 17 AND MUST FOLLOW EACH GUIDELINE LISTED BELOW.

INSTRUCTIONS START HERE:

Our satisfied clients are back to ask us to implement another interactive dictionary. Our dictionary takes input from users and uses the input as search key to look up values associated with the key. Requirements:

- Coding: No hard coding

- Data Source: a text file, Data.CS.SFSU.txt -

Data Structure: Use existing data structure(s) or create new data structure(s) to store our dictionary’s data. Each keyword, each part of speech, and each definition must be stored in a separate data field. Do not combine them such as storing three parts in one String.

- Data Loading: When our program starts, it loads all the original data from the data source into our dictionary’s data structure. The data source file is opened once and closed once per run. It must be closed as soon as possible. It must be closed before our program starts interacting with users.

- User Interface: A program interface allows users to input search keys. This interface then displays returned results. Our program searches the dictionary’s data (not the data source text file) for values associated with the search keys.

- Identical Output: Our program’s output must be identical to the complete sample run’s output: ASMT02_PC_Run.pdf 1. Program Analysis to Program Design, 10 points In 1 full page, please explain the following in detail: ▪ Your analysis of the provided information and the provided sample output. Compare to the ASMT 01 Java version.

HERE IS THE .TXT FILE THAT NEEDS TO BE IMPLEMENTED INTO THE PROGRAM: please store the .txt file into a map or multimap.

IF YOU KNOW HOW TO PARSE THE .TXT FILE, please include that as well.

arrow|noun -=>> Here is one arrow: -=>> ..   
book|noun -=>> A set of pages.|verb -=>> To arrange something on a particular date.|verb -=>> to arrange for someone to have a seat on a plane.|noun -=>> A written work published in printed or electronic form.
bookable|adjective -=>> Can be ordered in advanced.
bookbinder|noun -=>> A person who fastens the pages of books.   
bookcase|noun -=>> A piece of furniture with shelves.
csc210|adjective -=>> ready for CSC 220.|adjective -=>> Comfortable with Objects and Classes.|noun -=>> Intro to Java.|verb -=>> To learn Java.
csc220|noun -=>> data Structures.|verb -=>> To create data structures.|adjective -=>> Ready to create complex data structures.   
csc340|adjective -=>> = C++ version of CSC210 + CSC220 + more.|noun -=>> a CS upper division course.|noun -=>> many hours outside of class.|noun -=>> Programming Methodology.   
placeholder|noun -=>> To be updated...|adjective -=>> To be updated...|adjective -=>> To be updated...|adverb -=>> To be updated...|conjunction -=>> To be updated...|interjection -=>> To be updated...|noun -=>> To be updated...|noun -=>> To be updated...|preposition -=>> To be updated...|pronoun -=>> To be updated...|verb -=>> To be updated...   
distinct|noun -=>> Distinct is a parameter in this assignment.|noun -=>> a keyword in this assignment.|adjective -=>> unique. No duplicates. Clearly different or of a different kind.|adjective -=>> Familiar. Worked in Java.|noun -=>> An advanced search option.|noun -=>> A keyword in this assignment.|noun -=>> A keyword in this assignment.|adverb -=>> Uniquely. Written "distinctly".
adverb|noun -=>> Adverb is a word that adds more information about place, time, manner, cause or degree to a verb, an adjective, a phrase or another adverb.
adjective|noun -=>> Adjective is a word that describes a person or thing, for example big, red and clever in a big house, red wine and a clever idea.
conjunction|noun -=>> Conjunction is a word that joins words, phrases or sentences, for example 'and', 'but', 'or'.   
interjection|noun -=>> Interjection is a short sound, word or phrase spoken suddenly to express an emotion. Oh!, Look out! and Ow! are interjections.
noun|noun -=>> Noun is a word that refers to a person, (such as Ann or doctor), a place (such as Paris or city) or a thing, a quality or an activity (such as plant, sorrow or tennis).
preposition|noun -=>> preposition is a word or group of words, such as in, from, to, out of and on behalf of, used before a noun or pronoun to show place, position, time or method.
pronoun|noun -=>> pronoun is a word that is used instead of a noun or noun phrase, for example he, it, hers, me, them, etc...
verb|noun -=>> verb is a word or group of words that expresses an action (such as eat), an event (such as happen) or a state (such as exist).
reverse|verb -=>> Change something to opposite.|verb -=>> go back.|verb -=>> turn something inside out.|verb -=>> revoke ruling.|adjective -=>> Opposite to usual or previous arrangement.|adjective -=>> On back side.|noun -=>> The opposite.|noun -=>> Change to opposite direction.|noun -=>> A dictionary program's parameter.|noun -=>> To be updated...|verb -=>> To be updated...|noun -=>> To be updated...|noun -=>> To be updated...|verb -=>> To be updated...|noun -=>> To be updated...

THE OUTPUT MUST PRINT OUT LIKE THIS:

! Opening data file... C:\Users\MickeyMouse\AbsolutePath\DB\Data.CS.SFSU.txt ERROR ===> File could not be opened. ERROR ===> Provided file path: C:\Users\MickeyMouse\AbsolutePath\DB\Data.CS.SFSU.txt Enter the CORRECT data file path: ./Data.CS.SFSU.txt ! Loading data... ! Loading completed... ! Closing data file... ./Data.CS.SFSU.txt ====== DICTIONARY 340 C++ ===== ------ Keywords: 19 ------ Definitions: 61 Search [1]: !help | PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' | Search [2]: | PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' | Search [3]: aRRow | Arrow [noun] : Here is one arrow: -=>> . | Search [4]: adverb | Adverb [noun] : Adverb is a word that adds more information about place, time, manner, cause or degree to a verb, an adjective, a phrase or another adverb. | Search [5]: noun noun reverse | Noun [noun] : Noun is a word that refers to a person, (such as Ann or doctor), a place (such as Paris or city) or a thing, a quality or an activity (such as plant, sorrow or tennis). | Search [6]: cSc220 | CSC220 [adjective] : Ready to create complex data structures. CSC220 [noun] : Data Structures. CSC220 [verb] : To create data structures. | Search [7]: CSc340 noun distinct REVERSE | CSC340 [noun] : Programming Methodology. CSC340 [noun] : Many hours outside of class. CSC340 [noun] : A CS upper division course. | Search [8]: book NOUN distinct reverse | Book [noun] : A written work published in printed or electronic form. Book [noun] : A set of pages. | Search [9]: placeHOLDER | Placeholder [adjective] : To be updated... Placeholder [adjective] : To be updated... Placeholder [adverb] : To be updated... Placeholder [conjunction] : To be updated... Placeholder [interjection] : To be updated... Placeholder [noun] : To be updated... Placeholder [noun] : To be updated... Placeholder [noun] : To be updated... Placeholder [preposition] : To be updated... Placeholder [pronoun] : To be updated... Placeholder [verb] : To be updated... | Search [10]: placeholder distinct | Placeholder [adjective] : To be updated... Placeholder [adverb] : To be updated... Placeholder [conjunction] : To be updated... Placeholder [interjection] : To be updated... Placeholder [noun] : To be updated... Placeholder [preposition] : To be updated... Placeholder [pronoun] : To be updated... Placeholder [verb] : To be updated... | Search [11]: placeHolder adjective reverse | Placeholder [adjective] : To be updated... Placeholder [adjective] : To be updated... | Search [12]: distinCT DISTINct | Distinct [adjective] : Familiar. Worked in Java. Distinct [adjective] : Unique. No duplicates. Clearly different or of a different kind. Distinct [adverb] : Uniquely. Written "distinctly". Distinct [noun] : A keyword in this assignment. Distinct [noun] : An advanced search option. Distinct [noun] : Distinct is a parameter in this assignment. | Search [13]: distinct noun distinct REVERSE | Distinct [noun] : Distinct is a parameter in this assignment. Distinct [noun] : An advanced search option. Distinct [noun] : A keyword in this assignment. | Search [14]: reverse reverse | Reverse [verb] : Turn something inside out. Reverse [verb] : To be updated... Reverse [verb] : To be updated... Reverse [verb] : Revoke ruling. Reverse [verb] : Go back. Reverse [verb] : Change something to opposite. Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : The opposite. Reverse [noun] : Change to opposite direction. Reverse [noun] : A dictionary program's parameter. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [adjective] : On back side. | Search [15]: reverse distinct reVERSE | Reverse [verb] : Turn something inside out. Reverse [verb] : To be updated... Reverse [verb] : Revoke ruling. Reverse [verb] : Go back. Reverse [verb] : Change something to opposite. Reverse [noun] : To be updated... Reverse [noun] : The opposite. Reverse [noun] : Change to opposite direction. Reverse [noun] : A dictionary program's parameter. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [adjective] : On back side. | Search [16]: reverse ok | | | Reverse [adjective] : On back side. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [verb] : Change something to opposite. Reverse [verb] : Go back. Reverse [verb] : Revoke ruling. Reverse [verb] : To be updated... Reverse [verb] : To be updated... Reverse [verb] : Turn something inside out. | Search [17]: reverse noun ok | | | Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... | Search [18]: reverse noun ok distinct | | | | | Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... | Search [19]: reverse noun distinct ok | | | Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated... | Search [20]: reverse ok ok ok | | | | | | | Reverse [adjective] : On back side. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [noun] : A dictionary program's parameter. Reverse [noun] : Change to opposite direction. Reverse [noun] : The opposite. Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [verb] : Change something to opposite. Reverse [verb] : Go back. Reverse [verb] : Revoke ruling. Reverse [verb] : To be updated... Reverse [verb] : To be updated... Reverse [verb] : Turn something inside out. | Search [21]: reverse reverse ok ok | | | | | Reverse [verb] : Turn something inside out. Reverse [verb] : To be updated... Reverse [verb] : To be updated... Reverse [verb] : Revoke ruling. Reverse [verb] : Go back. Reverse [verb] : Change something to opposite. Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : To be updated... Reverse [noun] : The opposite. Reverse [noun] : Change to opposite direction. Reverse [noun] : A dictionary program's parameter. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [adjective] : On back side. | Search [22]: reverse distinct reverse ok | | | Reverse [verb] : Turn something inside out. Reverse [verb] : To be updated... Reverse [verb] : Revoke ruling. Reverse [verb] : Go back. Reverse [verb] : Change something to opposite. Reverse [noun] : To be updated... Reverse [noun] : The opposite. Reverse [noun] : Change to opposite direction. Reverse [noun] : A dictionary program's parameter. Reverse [adjective] : Opposite to usual or previous arrangement. Reverse [adjective] : On back side. | Search [23]: reverse distinct reverse ok ok | PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' | Search [24]: reverse adverb | To be considered for the next release. Thank you. | | PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' | Search [25]: facebook | To be considered for the next release. Thank you. | | PARAMETER HOW-TO, please enter: 1. A search key -then 2. An optional part of speech -then 3. An optional 'distinct' -then 4. An optional 'reverse' | Search [26]: !Q -----THANK YOU-----

IT WILL BE FORMATTED DIFFERENTLY IN YOUR IDE BUT THE CONTENT MUST INCLUDE ^^

Solutions

Expert Solution

Working code implemented in and appropriate comments provided for better understanding.

Here I am attaching code for all files:

  • main.cpp
  • dictionary.cpp
  • dictionary.h
  • Entry.cpp
  • Entry.h
  • mapVector.cpp
  • mapVector.h

main.cpp:

#include <iostream>
using namespace std;

#include "Entry.h"
#include <fstream>
#include "mapVector.h"
#include "dictionary.h"

int main()
{
dictionary d;
d.userInterface();
return 0;
}

dictionary.cpp:

#include "dictionary.h"
#include "mapVector.h"
#include "Entry.h"
#include <iostream>
using namespace std;
#include <vector>
#include <map>
#include <fstream>

dictionary::dictionary()
{
fstream file;
map.addFile(file);
}

void dictionary::userInterface()
{
int searchNum = 1;
cout << "Enter '!help' to learn how to format your search." << endl;
cout << "Enter '!q' to quit the program." << endl;
cout << "Enter '!list' to see a list of searchable entries." << endl;

while(!quit)
{
string input;
cout << "Search [" << searchNum << "]: ";
cin >> input;
checkInput(input);
searchNum++;
}
}

void dictionary::checkInput(string &userInput)
{
if(userInput.empty() || userInput == " ")
printAdmin("");
vector<string> input;
stringParser(input, userInput);

input.at(0) = setLower(input.at(0));
if(input.size() > 4)
cout << "\t|\n\t<This dictionary accepts input of up to 4 words.>\n\t<Any words beyond that have been ignored>\n\t|" << endl;

if(input.empty() || input.at(0).at(0) == '!' || input[0].empty())
printAdmin(input[0]);
else if(checkSameInput(input))
printAdmin("");
else
{
if(input.size() == 1)
map.Search(input[0]);
else if(input.size() == 2)
{
input[1] = setLower(input[1]);
if(checkDistinct(input[1]))
map.Search(input[0], "", true, false);
else if(checkReverse(input[1]))
map.Search(input[0], "", false, true);
else if(checkPOS(input[1]))
map.Search(input[0], input[1]);
else
{
printErrors(2, input[1], checkPOS(input[1]), checkDistinct(input[1]), checkReverse(input[1]));
map.Search(input[0]);
}
}
else if(input.size() == 3)
{
input[1] = setLower(input[1]);
input[2] = setLower(input[2]);
if(checkDistinct(input[1]))
{
if(checkReverse(input[2]))
map.Search(input[0], "", true, true);
else
{
printErrors(3, input[2], checkPOS(input[2]), checkDistinct(input[2]), checkReverse(input[2]));
map.Search(input[0], "", true, false);
}
}
else if(checkReverse(input[1]))
{
cout << "\t|\n\t<'Reverse' should be the last value input>\n\t|" << endl;
map.Search(input[0], "", false, true);
}
else if(checkPOS(input[1]))
{
//check if distinct or reverse is in 3
if(checkDistinct(input[2]))
map.Search(input[0], input[1], true, false);
else if(checkReverse(input[2]))
map.Search(input[0], input[1], false, true);
//Search(input[0],input[1],"reverse");
else
{
printErrors(3, input[2], checkPOS(input[2]), checkDistinct(input[2]), checkReverse(input[2]));
map.Search(input[0],input[1]);
}
}
else
{
printErrors(2, input[1], checkPOS(input[1]), checkDistinct(input[1]), checkReverse(input[1]));
if(checkDistinct(input[2]))
{

map.Search(input[0], "", true, false);
}
else if(checkReverse(input[2]))
{
map.Search(input[0], "", false, true);
}
else if(checkPOS(input[2]))
{
map.Search(input[0], input[2]);
}
else
{
printErrors(3, input[2], checkPOS(input[2]), checkDistinct(input[2]), checkReverse(input[2]));
map.Search(input[0]);
}
}
}
else if(input.size() >= 4)
{
input[1] = setLower(input[1]);
input[2] = setLower(input[2]);
input[3] = setLower(input[3]);
//check input[1]
//check if distinct is in 2 or 3
//check if reverse is in 2, 3, or 4
if(checkDistinct(input[1]))
{
if(checkReverse(input[2]))
{
//Search(input[0], "distinct", "reverse");
cout << "\t<The entered 4th parameter '" <<input[3] <<"' was disregarded.>\n\t|" << endl;
map.Search(input[0], "", true, true);
}
else
{
printErrors(3, input[2], checkPOS(input[2]), checkDistinct(input[2]), checkReverse(input[2]));
if(checkReverse(input[3]))
{
map.Search(input[0], "", true, true);
}
else
{
printErrors(4, input[3], checkPOS(input[3]), checkDistinct(input[3]), checkReverse(input[3]));
map.Search(input[0], "", true, false);
}
}
}
else if(checkReverse(input[1]))
{
cout << "\t|\n\t<'Reverse' should be the last qualifier included.>\n\t|" << endl;
map.Search(input[0], "", false, true);
}
else if(checkPOS(input[1]))
{
//check if distinct or reverse is in 3
if(checkDistinct(input[2]))
{
if(checkReverse(input[3]))
map.Search(input[0], input[1], true, true);
else
{
cout << "\t|\n\t<The entered 4th parameter should be 'reverse.'>" << endl;
printErrors(4, input[3], checkPOS(input[3]), checkDistinct(input[3]), checkReverse(input[3]));
map.Search(input[0], input[1], true, false);
}
}
else if(checkReverse(input[2]))
{
//Search(input[0],input[1],"reverse");
cout << "\t|\n\t<'Reverse' should be the last command>" << endl;
map.Search(input[0], input[1], false, true);
}
else
{
printErrors(3, input[2], checkPOS(input[2]), checkDistinct(input[2]), checkReverse(input[2]));
if(checkReverse(input[3]))
{
map.Search(input[0], input[1], false, true);
//Search(input[0[, input[1], "reverse");
}
else if(checkDistinct(input[3]))
{
map.Search(input[0], input[1], true, false);
}
else
{
printErrors(4, input[3], checkPOS(input[3]), checkDistinct(input[3]), checkReverse(input[3]));
map.Search(input[0], input[1],false, false);
}
}
}
else
{
//input[1] is bad
printErrors(2, input[1], checkPOS(input[1]), checkDistinct(input[1]), checkReverse(input[1]));
if(checkDistinct(input[2]))
{
if(checkReverse(input[3]))
{
map.Search(input[0], "", true, true);
}
else
{
printErrors(4, input[3], checkPOS(input[3]), checkDistinct(input[3]), checkReverse(input[3]));
map.Search(input[0], "", true, false);
}
}
else if(checkReverse(input[2]))
{
cout << "\t|\n\t<'Reverse' should be the last command>\n\t|" << endl;
map.Search(input[0], "", false, true);
}
else if(checkPOS(input[2]))
{
if(checkDistinct(input[3]))
{
map.Search(input[0], input[2], true, false);
}
else if(checkReverse(input[3]))
{
map.Search(input[0], input[2], false, true);
}
else
{
printErrors(4, input[3], checkPOS(input[3]), checkDistinct(input[3]), checkReverse(input[3]));
map.Search(input[0], input[2]);
}
}
else
{
printErrors(3, input[2], checkPOS(input[2]), checkDistinct(input[2]), checkReverse(input[2]));
if(checkDistinct(input[3]))
{
map.Search(input[0], "", true, false);
}
else if(checkReverse(input[3]))
{
map.Search(input[0], "", false, true);
}
else if(checkPOS(input[3]))
{
map.Search(input[0], input[3]);
}
else
{
printErrors(4, input[3], checkPOS(input[3]), checkDistinct(input[3]), checkReverse(input[3]));
map.Search(input[0]);
}
}
}
}
}
}

void dictionary::printAdmin(string input)
{
if(input.empty() || input == "!help")
{
cout << "\t|\n\tPARAMETER HOW-TO, please enter:" << endl;
cout << "\t1. A search key -then 2. An optional part of speech -then\n\t3. An optional 'distinct' -then";
cout << " 4. An optional 'reverse'\n\t|" << endl;
}
//input == "q"
if(input == "!q" ||input == "!quit")
{
quit = true;
cout << "-----THANK YOU-----" << endl;
}
//input == "!list"
if(input == "!list")
{
map.printAllKeys();
}
}

bool dictionary::checkPOS(string str)
{
string s = setLower(str);
return (s == "noun" || s == "adjective" || s == "adverb" ||
s == "conjunction" || s == "interjection" || s == "preposition" ||
s == "pronoun" || s == "verb");
}

bool dictionary::checkDistinct(string str)
{
string s = setLower(str);
return s.compare("distinct") == 0;
}

bool dictionary::checkReverse(string str)
{
string s = setLower(str);
return s.compare("reverse");
}

void dictionary::printErrors(int place, string in, bool pos, bool dist, bool rev)
{
string pl;
switch(place)
{
case 2:
{
pl = "2nd";
break;
}
case 3:
{
pl = "3rd";
break;
}
case 4:
{
pl = "4th";
break;
}
default:
pl = "2nd";
}
cout << "\t|" << endl;
//not a part of speech
if(!pos)
cout << "\t<The entered " << pl << " parameter \"" << in << "\" is NOT a part of speech.>" << endl;
//not "distinct"
if(!dist)
cout << "\t<The entered " << pl << " parameter \"" << in << "\" is NOT 'distinct.'>" << endl;
//not "reverse"
if(!rev)
cout << "\t<The entered " << pl << " parameter \"" << in << "\" is NOT 'reverse.'>" << endl;
//none of them
if(!pos && !dist && !rev)
cout << "\t<The " << pl << " parameter should be a part of speech, 'distinct,' or 'reverse'>" << endl;

//Always print
cout << "\t<The entered " << pl << " parameter \"" << in << "\" was disregarded.>" << endl;
cout << "\t|" << endl;
}

bool dictionary::checkSameInput(vector<string> &currInput)
{
int min;
if(currInput.size() < lastInput.size())
min = currInput.size();
else
min = lastInput.size();

int numSame = 0;
for(int i = 0; i < min; i++)
{
if(lastInput[i] == currInput[i])
numSame++;
}

if(numSame == currInput.size())
{
lastInput.swap(currInput);
return true;
} else
{
lastInput.swap(currInput);
return false;
}
}

void dictionary::stringParser(vector<string> &input, string &userInput)
{

if(userInput.find(' ') == 0)
{
string str = userInput.substr(1);
stringParser(input, str);
}
else if(userInput.find(' ') == -1)
{
input.push_back(userInput);
}
else
{
int nextSpace(userInput.find(' '));
string word = userInput.substr(0, nextSpace);
input.push_back(word);

string str = userInput.substr(nextSpace + 1);
stringParser(input, str);
}
}

string dictionary::setLower(string& str)
{
string lowerCase;
for(char c: str)
{
lowerCase.push_back((char)tolower(c));
}
return lowerCase;
}

dictionary.h:

#ifndef CSC340_PROJECT3_DICTIONARY_H
#define CSC340_PROJECT3_DICTIONARY_H

#include <iostream>
using namespace std;
#include <vector>
#include "mapVector.h"

class dictionary {
private:
//instance variables
bool quit = false;
vector<string> lastInput = {"one", "two", "three", "four"};
//functions

/*
* returns true if the string is a verified part of speech
* returns false if the string isn't a part of speech
*/
static bool checkPOS(string);

/*
* returns true if the string is "distinct"
* returns false otherwise
*/
static bool checkDistinct(string);

/*
* returns true if the string is "reverse"
* returns false otherwise
*/
static bool checkReverse(string);

/*
* Takes an int of either 2, 3, or 4 and uses that to know which part of the input is erroneous.
* The string is the input that the user entered and prints out so they know their exact mistakes
* The booleans refer to part of speech, distinct, and reverse (respectively) and whether the string is one of them
*/
static void printErrors(int, string, bool, bool, bool);

/*
* returns true if the user input the same search as their previous search.
* Completed using the instance variable lastInput
*/
bool checkSameInput(vector<string>&);

/*
* The string is the user's input
* This method takes that string, splits it into an array and performs the operations on those words.
*/
void checkInput(string&);

/*
* Prints the administrative replies
*/
void printAdmin(string);

/*
* Helps to parse the user's input into readable chunks that the program can use.
*/
static void stringParser(vector<string>&, string&);

/*
* sets the entire string to lowercase
*/
static string setLower(string&);

public:
//instance variables
mapVector map;
//functions

//Constructor
dictionary();

/*
* The function that facilitates interaction between the dictionary and the user
*/
void userInterface();


};


#endif //CSC340_PROJECT3_DICTIONARY_H

Entry.cpp:

#include "Entry.h"
#include <iostream>
using namespace std;


Entry::Entry()
{
word = "Placeholder";
partOfSpeech = "noun";
def = "To be updated...";
}

Entry::Entry(string &w, string &pos, string &d)
{
this->word = w;
this->partOfSpeech = pos;
this->def = d;
}

string Entry::getWord()
{
return this->word;
}

string Entry::getPOS()
{
return this->partOfSpeech;
}

string Entry::getDef()
{
return this->def;
}

string Entry::print()
{
return this->word + " [" + this->partOfSpeech + "] : " + this->def;
}

bool Entry::compareTo(Entry e)
{
return (this->word.compare(e.getWord()) + this->partOfSpeech.compare(e.getPOS()) + this->def.compare(e.getDef()) == 0);
}

Entry.h:

#include <iostream>
using namespace std;
#ifndef CSC340_PROJECT3_ENTRY_H
#define CSC340_PROJECT3_ENTRY_H


class Entry {
private:
string word;
string partOfSpeech;
string def;

public:
Entry();
Entry(string&, string&, string&);
string getWord();
string getPOS();
string getDef();
string print();
bool compareTo(Entry);
};


#endif //CSC340_PROJECT3_ENTRY_H

mapVector.cpp:

#include "mapVector.h"
#include <iostream>
using namespace std;
#include <vector>
#include <map>
#include <fstream>
#include "Entry.h"

mapVector::mapVector()
{
std::map<string, vector<Entry>> map;
}

void mapVector::add(Entry &e)
{
string key = e.getWord();
//if the key isn't in the map
if(map.find(key) == map.end())
{
vector<Entry> v = {e};
map.insert({e.getWord(), v});
}
//if the key is in the map
else
{
map[e.getWord()].push_back(e);
}
}

void mapVector::addFile(fstream &file)
{
string line;
file.open("/Users/jasonfujii/CLionProjects/CSC340_Project3/Data.CS.SFSU.txt", ios::in);
if(!file.is_open())
{
cout << "The file entered cannot be opened. Please check the file name provided in mapVector.cpp in function addFile(fstream)" << endl;
exit(1);
}

while(getline(file, line))
{
//the first section will be the word
string name = line.substr(0, line.find("|"));
vector<Entry> list;
//the next sections are between "|". take a substring between those and then take the info between those
string pos, def;
string newString = line.substr(line.find("|") + 1);
wordParse(list, name, newString, pos, def);

map.insert({name, list});
}

file.close();
cout << "File closed" << endl;
}

void mapVector::wordParse(vector<Entry>& list, string& name, string& line, string& pos, string& def)
{
if(line.find("|") == 0 )
{
string s = line.substr(1);
wordParse(list, name, s, pos, def);
}
else if(line.find("|") == -1)
{
int endPos = line.find("-=>>");
pos = line.substr(0, endPos - 1);
def = line.substr(endPos + 5);
Entry entry(name, pos, def);
list.push_back(entry);
}
else
{
int endPos = line.find("-=>>");
int endDef = line.find('|');
int defLength = endDef - (endPos + 5);
pos = line.substr(0, endPos - 1);
def = line.substr(endPos + 5, defLength);
Entry entry(name, pos, def);
list.push_back(entry);

string newString = line.substr(line.find("|") + 1);
wordParse(list, name, newString, pos, def);
}
}
//book|noun -=>> A set of pages.|verb -=>> To arrange something on a particular date.|verb -=>> to arrange for someone to have a seat on a plane.|noun -=>> A written work published in printed or electronic form.

void mapVector::remove(string key)
{
if(map.find(key) != map.end())
map.erase(key);
else
cout << "\"" << key << "\" is not in the dictionary." << endl;
}

void mapVector::remove(Entry &e)
{
if(!map.empty()) {
string key = e.getWord();
if (map.find(key) != map.end()) {
vector<Entry>::iterator it;
for (it = map.at(key).begin(); it < map.at(key).end(); it++) {
int index = std::distance(map.at(key).begin(), it);
if (map.at(key).at(index).compareTo(e)) {
map.at(key).erase(it);
cout << "Entry successfully removed." << endl;
}
}
} else
cout << "| \n<NOT FOUND> To be considered for the next release.\n|" << endl;
} else
cout << "\tThe dictionary is empty..." << endl;
}

void mapVector::Search(string key)
{
cout << "\t|" << endl;
printKey(key);
cout << "\t|" << endl;
}

void mapVector::Search(string key, string pos)
{
cout << "\t|" << endl;
printPOS(key, pos);
cout << "\t|" << endl;
}


void mapVector::Search(string key, string pos, bool dist, bool rev)
{
if(pos.empty() && !dist && !rev)
{
//only key provided
Search(key);
}
else if(!dist && !rev)
{
//key and POS
Search(key, pos);
} else
qualifiedPrint(key, pos, dist, rev);
}

void mapVector::printAll()
{
if(!map.empty())
{
for(auto m: map)
{
for(int i = 0; i < m.second.size(); i++)
{
cout << "\t" << m.second.at(i).print() << endl;
}
}
} else
cout << "\tThe dictionary is empty..." << endl;
}

void mapVector::printAllKeys()
{
if(!map.empty())
{
int count = 0;
cout << "Choose from these entries: \n\t";
for(auto m: map)
{
if(count%6 == 5) {
cout << "\n\t" << m.second.at(0).getWord() << ", ";
count = 0;
}
else
cout << m.second.at(0).getWord() << ", ";
count++;
}
} else
cout << "\tThe dictionary is empty..." << endl;
}

void mapVector::printKey(string key)
{
if(!map.empty())
{
if(map.find(key) != map.end())
{
for(Entry e: map.at(key))
{
cout << "\t" << e.print() << endl;
}
} else
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
} else
cout << "\tThe dictionary is empty..." << endl;
}

void mapVector::printPOS(string key, string pos)
{
if(!map.empty())
{
if(map.find(key) != map.end())
{
int count = 0;
for(Entry e: map.at(key))
{
if(e.getPOS().compare(pos) == 0) {
cout << "\t" << e.print() << endl;
count++;
}
}
if(count ==0)
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
}
else
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
} else
cout << "\tThe dictionary is empty..." << endl;
}

void mapVector::printDistinct(vector<Entry> &list, string pos)
{
if(!map.empty())
{
if(!pos.empty())
{
int count = 0;
for(Entry e: list)
{
if(e.getPOS().compare(pos) == 0)
{
cout << "\t" << e.print() << endl;
count++;
} else
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
}
} else
{
for(Entry e: list)
cout << "\t" << e.print() << endl;
}
} else
cout << "\tThe dictionary is empty..." << endl;
}

void mapVector::qualifiedPrint(string key, string pos, bool dist, bool rev)
{
if(!map.empty())
{
if(map.find(key) != map.end())
{
if(!pos.empty())
{
//if dist & rev are *BOTH* true
if(dist && rev)
{
vector<Entry> distinct = distinctify(key);
cout << "\t|" << endl;
reversePrint(distinct, pos);
cout << "\t|" << endl;
}
//only dist is true
else if(dist)
{
vector<Entry> distinct = distinctify(key);
cout << "\t|" << endl;
printDistinct(distinct, pos);
cout << "\t|" << endl;
}
//only rev is true
else if(rev)
{
cout << "\t|" << endl;
reversePrint(map.at(key), pos);
cout << "\t|" << endl;
}
//dist and rev are *BOTH* false
else
{
cout << "\t|" << endl;
printPOS(key, pos);
cout << "\t|" << endl;
}
} else
{
if(dist && rev)
{
vector<Entry> distinct = distinctify(key);
cout << "\t|" << endl;
reversePrint(distinct, "");
cout << "\t|" << endl;
}
else if(dist)
{
vector<Entry> distinct = distinctify(key);
cout << "\t|" << endl;
printDistinct(distinct, "");
cout << "\t|" << endl;
}
else if(rev)
{
cout << "\t|" << endl;
reversePrint(map.at(key), "");
cout << "\t|" << endl;
} else
{
cout << "\t|" << endl;
printPOS(key, "");
cout << "\t|" << endl;
}
}
} else
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
} else
cout << "\tThe dictionary is empty..." << endl;
}

vector<Entry> mapVector::distinctify(string key)
{
vector<Entry> entries;
if(!map.empty())
{
if(map.find(key) != map.end())
{
entries.push_back(map.at(key).at(0));
for(Entry e: map.at(key))
{
bool dist = true;
for(Entry e2: entries)
{
if(e.compareTo(e2))
dist = false;
}
if(dist)
entries.push_back(e);
}
} else
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
} else
cout << "\tThe dictionary is empty..." << endl;

return entries;
}

void mapVector::reversePrint(vector<Entry> &list, string pos)
{
if(pos.empty())
{
for(int i = list.size(); i >= 0; i--)
{
cout << "\t" << list.at(i).print() << endl;
}
} else
{
int count = 0;
for(int i = list.size(); i >= 0; i--)
{
if(list.at(i).getPOS().compare(pos) == 0)
{
cout << "\t" << list.at(i).print() << endl;
count++;
}
}
if(count == 0)
cout << "\t|\n\t<NOT FOUND> To be considered for the next release.\n\t|" << endl;
}
}
/*
* Vector Constructors!
* vector<T> v1(): empty vector of element T
* vector<T> v2(4, 100): vector of size 4 with value 100 in each index
* vector<T> v3(v2): a copy of v2
* Useful vector functions!
* int size(): returns number of elements in the vector
* bool empty(); returns true if vector is empty, false otherwise
* vector[index]: returns the element at index. Used to instantiate the index
* at(index): returns the element at index. Throws an out of bounds exception if the index doesn't exist. Used to instantiate the index
* front(): returns/accesses the first element
* back(): returns/accesses the last element
* swap(vector& v): swaps the contents of *this* vector with the contents of v
* clear(): empties the vector and leaves it with a size of 0
*/

/*
* Map Constructors!
* map<T, K> m: an empty map with key value T and value value of K
* m['a'] = 10: with T = char, K = int, declaring that key 'a' has value 10
* Useful map functions!
* empty(): returns true if map container has size 0
* size(): returns the number of elements the map contains (number of keys)
* map[key]: accesses the element at key. Used to change the element or to access it
* at(key): accesses the element at key. Used to change the element or to access it
* find(key): returns map.end (an iterator) if the key isn't found
* if(map.find(key) != map.end()) --> Key found!
* else --> Key not found!
*/

mapVector.h:

#ifndef CSC340_PROJECT3_MAPVECTOR_H
#define CSC340_PROJECT3_MAPVECTOR_H

#include <iostream>
using namespace std;

#include <map>
#include <vector>
#include "Entry.h"

class mapVector {
private:

void wordParse(vector<Entry>&, string&, string&, string&, string&);

public:
/*
* Creates a new mapVector object
*/
mapVector();
map<string, vector<Entry>> map;
/*
* add() takes an Entry object and inserts it into the mapVector.
* Checks if the word is already in a key in the mapVector
* if yes, add the rest of the entry to the mapVector
* if no, add the key, then create the vector
*/
void add(Entry&);

/*
* iterates through a file, turns every element into an Entry obj, then adds that Entry object to the mapVector
*/
void addFile(fstream&);

/*
* remove(string) removes all entries at that specified key value
*/
void remove(string);

/*
* remove(Entry) removes an Entry object from the mapVector
*/
void remove(Entry&);

/*
* Search(string) is used when the user only inputs a single word
* It searches the map for the chosen key, then prints everything in that key's vector
* If the key cannot be found, print out this message:
* <NOT FOUND> To be considered for the next release
*/
void Search(string);

/*
* Search(string, string) takes the key value and a part of speech
* It searches the map for the chosen key, then only prints the entries with the specified part of speech
*/
void Search(string, string);

/*
* Search(string, string, bool, bool) takes the key, part of speech, and booleans for distinct and reverse
* It searches the table for the chosen key, find the values with the specified part of speech, then applies the
* distinct and reverse functions if needed.
*/
void Search(string, string, bool, bool);

/*
* Prints out the entirety of the map in the format:
* [word] [pos] : [desc]
*/
void printAll();

/*
* Prints a list of all the keys for the user to view their options
*/
void printAllKeys();

/*
* Prints all entries in the vector at the searched Key
*/
void printKey(string);

/*
* Prints all values at Key with the chosen part of speech
*/
void printPOS(string, string);

/*
* Input: vector<string>
* takes a new vector from distinctify() and prints out the terms with the chosen part of speech
*/
void printDistinct(vector<Entry>&, string);

/*
* Input: string key, string part of speech, boolean distinct, boolean reverse
* Takes account of distinct and reverse.
* If distinct is true, no repeat entries will be printed
* If reverse is true, the list will print backwards
*/
void qualifiedPrint(string, string, bool, bool);

/*
* Input:
* Iterates through the vector at Key and returns a vector of unique entries
*/
vector<Entry> distinctify(string);

/*
* Input: vector<Entry> list, string part of speech
* Takes a vector of entries and prints them in reverse according to the part of speech that was input.
*/
void reversePrint(vector<Entry>&, string);

};

/*
* Vector Constructors!
* vector<T> v1(): empty vector of element T
* vector<T> v2(4, 100): vector of size 4 with value 100 in each index
* vector<T> v3(v2): a copy of v2
* Useful vector functions!
* int size(): returns number of elements in the vector
* bool empty(); returns true if vector is empty, false otherwise
* vector[index]: returns the element at index. Used to instantiate the index
* at(index): returns the element at index. Throws an out of bounds exception if the index doesn't exist. Used to instantiate the index
* front(): returns/accesses the first element
* back(): returns/accesses the last element
* swap(vector& v): swaps the contents of *this* vector with the contents of v
* clear(): empties the vector and leaves it with a size of 0
*/

/*
* Map Constructors!
* map<T, K> m: an empty map with key value T and value value of K
* m['a'] = 10: with T = char, K = int, declaring that key 'a' has value 10
* Useful map functions!
* empty(): returns true if map container has size 0
* size(): returns the number of elements the map contains (number of keys)
* map[key]: accesses the element at key. Used to change the element or to access it
* at(key): accesses the element at key. Used to change the element or to access it
* find(key): returns map.end (an iterator) if the key isn't found
* if(map.find(key) != map.end()) --> Key found!
* else --> Key not found!
*/
#endif //CSC340_PROJECT3_MAPVECTOR_H

Sample Output Screenshots:


Related Solutions

Precis 3 To complete this assignment, follow the instructions below. You will have two arguments to...
Precis 3 To complete this assignment, follow the instructions below. You will have two arguments to address from both Chapter 8 and Chapter 9. From Chapter 8, Exercise 8.9, write a precis on passages 4 and 5. 4: If the Copernican and Darwinian theories are reasonable representatives of scientific revolutions, Sigmund Freud’s theory of psychology is a candidate for a revolution in thought. Thus, because both the Copernican and Darwinian theories are reasonable representatives of scientific revolutions, Freud’s theory is...
Instructions: The assignment is based on the mini case below. The instructions relating to the assignment...
Instructions: The assignment is based on the mini case below. The instructions relating to the assignment are at the end of the case. Katie Holmes and Sam Wilson are facing an important decision. After having discussed different financial scenarios into the wee hours of the morning, the two computer engineers felt it was time to finalize their cash flow projections and move to the next stage – decide which of two possible projects they should undertake. Both had a bachelor...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop...
Please follow these instructions to complete this assignment: 1. For this assignment, you are to develop 10 questions that you would ask a management official responsible for the financial planning for the organization you have chosen to research for the week 3 paper. 2. Make sure the questions will give you insight into what the company looks for when preparing their yearly budget, fiscal planning strategies, as well as how they monitor their financial condition throughout the year and make...
YOU MUST FOLLOW THE INSTRUCTIONS BELOW. IF YOU DON'T, YOU MAY KNOW THE CORRECT ENTRY BUT...
YOU MUST FOLLOW THE INSTRUCTIONS BELOW. IF YOU DON'T, YOU MAY KNOW THE CORRECT ENTRY BUT THE COMPUTER WILL NOT RECOGNIZE IT AND YOU WILL NOT RECEIVE CREDIT. After each transaction description, there are several "Account" submission boxes and corresponding "Amount" submission boxes. To indicate the accounts that you think are affected, choose them from the drop-down menu. But you MUST select them in the order that they are listed in the menu. FOR EXAMPLE, if you think that Cash...
This is very important. You must follow my instructions exactly. There are 9 questions. Each question...
This is very important. You must follow my instructions exactly. There are 9 questions. Each question requires you to answer TRUE or FALSE followed by an explanation. If you do not do this I will interpret your answer as I see it, so the word TRUE or FALSE is critical as a start to each question. The second important thing is to put each answer below the relevant question, not all at the end of the exam. So, you will...
YOU MUST COMPLETE THIS TO PASS THIS CLASS. Discussion Assignment: Referencing the ROME mnemonic listed below,...
YOU MUST COMPLETE THIS TO PASS THIS CLASS. Discussion Assignment: Referencing the ROME mnemonic listed below, prepare a factual submission article explaining the significance of the following lab results. Submit your results as your discussion contribution. Mrs. Breathless is a 42 year old female, just getting off a late shift. She reports to the ER in the early morning with shortness of breath. After several test, the following results are confirmed: ABG (arterial blood gases) lab results are: pH=7.44, PaCO2...
Respond to the following prompt to complete the CTE assignment. Be sure to follow the instructions...
Respond to the following prompt to complete the CTE assignment. Be sure to follow the instructions in the syllabus and your grade will be determined through the use of the related rubric (also located in the syllabus). As the Baby Boom generation continues to retire from the labor force, the ratio of retirees to workers will continue to increase. How will this demographic change impact the Social Security program? What "solution" or "solutions" would best offset the harmful effects of...
Memo Assignment #4 Instructions: This will be done in a professional memo format with complete sentences...
Memo Assignment #4 Instructions: This will be done in a professional memo format with complete sentences that explain your process and conclude in a recommendation. I would expect the memo to be no less than one full page and no more than four pages. The goal is two-fold: the professional recommendations AND the appropriate presentation. Heavenly Scents was founded by Riley Williams when she bought Bund Farm in 2015. Heavenly Scents has two departments, a harvesting department and a processing...
Write the basic JAVA code for the beginners and follow all the instructions listed 1. A...
Write the basic JAVA code for the beginners and follow all the instructions listed 1. A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for e.g., 1980), except that it is not a leap year if it is also divisible by 100 (for e.g., 1900); however, it is a leap year if it is further divisible by 400 (for e.g., 2000). Write a program that prompts the...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT