Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My friends and I will give many thumbs up for a correct answer. Write an object-

ID: 3589939 • Letter: M

Question

My friends and I will give many thumbs up for a correct answer.

Write an object-oriented program to create a dictionary. The dictionary has 26 files (files). You may name the files (tables) as A.txt, B.txt,..., Z.txt. Your dictionary class should have at least the following attributes and methods:

#include

#include

#include

using namespace std;

class Dictionary

{

               private:

                              const      int maxWordsInDict;

                              const     int maxWordsPerFile;

                                             int          totalWordsInDict;

                                             int          numOfWordsInFile[26];

                              static     bool failure;

                              static     bool success;

              

               public:

                              Dictionary();

                              Dictionary(int dictMaxWords, int fileMaxWords);

                              bool AddAWord(string word);

                              bool DeleteAWord(string word);

                              bool SearchForWord(string word);

                              bool PrintAFileInDict(string filename);

                              bool SpellChecking(string fileName);

                              bool InsertWordsIntoDict(string fileName);

                              void ProcessTransactionFile();                   

};

bool Dictionary::failure = false;

bool Dictionary::success = true;

Dictionary::Dictionary()

{

/* This routine sets the following values to the following attributes

                              maxWordsInDict = 10000;

                              maxWordsPerFile = 100;

                              totalWordsInDict = 0;       

                              numOfWordsInFile[0] = 0; referring to A.txt

                              numOfWordsInFile[1] = 0; referring to B.txt

                             

                             

                              numOfWordsInFile[25] = 0; referring to Z.txt

*/

}

              

//------------------------------------------------------------------

Dictionary::Dictionary(int dictMaxWords, int fileMaxWords)

{

/* This routine sets the following values to the following attributes

                              maxWordsInDict = dictMaxWords;

                              maxWordsPerFile = fileMaxWords;

                              totalWordsInDict = 0;       

                              numOfWordsInFile[0] = 0; referring to A.txt

                              numOfWordsInFile[1] = 0; referring to B.txt

                             

                             

                              numOfWordsInFile[25] = 0; referring to Z.txt

*/

}

              

//------------------------------------------------------------------

bool AddAWord(string word)

{

/* This routine opens the appropriate file, (If the first letter of the word is A, it should be in A.txt, or if the first letter of the word starts with B it should be in B.txt, and so on) and tries to add the word that is passed to this function into that file.

Before adding the word to the file, you should call the search function to ensure that the word is not already in the appropriate file

If you could add a word successfully into the appropriate file, you should increment the attribute TotalWordsInDict by 1 as long as you do not exceed the maxWordsInDict.

Further, if you add a word to A.txt you need to increment numOfWordsInFile[0] by 1. Similarly if you add a word to B.txt you need to increment numOfWordsInFile[1] and so on. Incrimination should be done as long as you do not exceed the maximum value.

If the word that you are trying to add, could not be added into the appropriate file for any reason, this routine should return failure

                                                                           return (Dictionary::failure)

otherwise, if the word is successfully added, this routine should return success

                                                                           return (Dictionary::success)

HINT: suppose the word you try to add is "adam". The word "adam" should be added to A.txt. Therefore, you need to open "A.txt" first. To do that you can do the following

string fileName = "#.txt"; // all files should be have ".txt" extension

fileName[0] = toupper(word[0]);      // replaces the # sign with appropriate letter. Note that word is "adam" and. Letter 'a' is the first letter of the word and should be changed to upper case

ofstream fout;

fout.open(fileName.data(), ios::app); // ios::app means appending the word to the file rather than overwriting the old information in the file

fout << word << endl;

*/

}

//------------------------------------------------------------------

bool DeleteAWord(string word)

{

/* This routine opens the appropriate file where the word that you are looking for might be kept. (If the first letter of the word is A, it should be in A.txt, or if the first letter of the word starts with B it should be in B.txt, and so on. Then it places all the words into a vector and looks for the word in the vector. If the word is in the vector, it should be deleted and then the modified vector should be inserted back into the appropriate file

If you could remove a word successfully from the appropriate file, you should decrement the attribute TotalWordsInDict by 1.

Further, if you remove a word from A.txt you need to decrement numOfWordsInFile[0] by 1. Similarly if you remove a word from B.txt you need to decrement numOfWordsInFile[1] and so on.

If the word that you are trying to delete is not in the appropriate file, this routine should return failure

                                                                           return (Dictionary::failure)

otherwise, when the word is successfully deleted, this routine should return success

                                                                           return (Dictionary::success)

Note that before placing anything into the vector; it is a good idea to call the search function to ensure that the word is in the appropriate file

*/

}

//------------------------------------------------------------------

bool SearchForWord(string word)

{

/* This routine opens the appropriate file where the word that you are looking for might be kept. (If the first letter of the word is A, it should be in A.txt, or if the first letter of the word starts with B it should be in B.txt, and so on. If the word cannot be found in the appropriate file, this routine returns failure

                                                                           return (Dictionary::failure)

otherwise, if the word does exist in the appropriate file, it returns success

                                                                           return (Dictionary::success)

*/

}

//------------------------------------------------------------------

bool PrintAFileInDict(string filename)

{

/* This routine opens the file fileName, read the words one by one and print them on the screen. You should only print 5 words per line.

If the fileName could not be opened, this routine returns failure

                                                            return (Dictionary::failure)

otherwise, it returns success

                                                            return (Dictionary::success)

*/

}

//------------------------------------------------------------------

bool SpellChecking(string fileName)

{

/* This routine opens the file fileName, read the words one by one and does the spell checking of the words. Every word is searched and those that are not in the dictionary are reported on the screen

If the fileName could not be opened, this routine returns failure

                                                            return (Dictionary::failure)

otherwise, it returns success

                                                            return (Dictionary::success)

*/

}

//------------------------------------------------------------------

bool InsertWordsIntoDict(string fileName)

{

/* This routine opens the file fileName, read the words one by one and try to insert them into the dictionary. Note that before inserting a word into the dictionary, you should search the dictionary to ensure that the word is not there.

If the fileName could not be opened, this routine returns failure

                                                            return (Dictionary::failure)

otherwise, it returns success

                                                            return (Dictionary::success)

*/

}

//------------------------------------------------------------------

void ProcessTransactionFile()

{

/* In this routine, you need to ask the user to enter a transaction file. A transaction file has two information per line. The first information is a command telling the programmer what to do. The second information is the data associated with the command. For example, a possible transaction file may contain

                                             AddW                                                 student

                                             DeleteW                                             play

                                             SearchW                                            medical

                                             PrintF                                                 Q.txt

                                             SpellCheck                                        myEssay.txt

                                             InsertF                                                data.txt

                                             ....

                                             ....

                                             ....

AddW should add the word "student" into the dictionary. You should call the AddAWord(string word) function to add the word "student" into the dictionary

DeleteW should remove the word "play" from the dictionary. You should call the DeleteAWord(string word) function to remove the word "play" from the dictionary

SearchW should search for the word "medical" in the dictionary. You should call the SearchForWord(string word) function to search for the word "medical" in the dictionary

PrintF should print all the words in a particular fie on the screen. You should call the function PrintAFileInDict(string fileName) to print the content of file Q.txt on the screen

SpellCheck should do the spell checking of a file. All errors should be reported on the screen. You should call the function SpellChecking(string fileName) to do the spell checking of the file called "myEssay.txt"

InsertF should process the content of a file and insert word by word in the file into the dictionary. You should call the function InsertWordsIntoDict(string fileName) to add the content of the file called "data.txt" into the dictionary

Note that if the transaction file does not exist, you need to print appropriate failure message on the screen

*/

}

//------------------------------------------------------------------

int main()

{

               Dictionary DictForCS211;

               DictForCS211.ProcessTransactionFile();

               return 0;

}

/*

Other Comments:

1)           Do not worry about punctuations. Your program should only consider words and ignore all punctuations.

2)            All words should be in lower case before it is placed in the dictionary

3)           Do not write 26 statements to open/close A.txt to Z.txt files.

4)           When a file name is a variable, you need to open it as follows:

                                             fin.open(fileName.data());

*/

Place the following in your Transaction file

AddW                    student

AddW                    teacher

AddW                    cs211

InsertF                   data.txt

PrintF                    S.txt

DeleteW                 student

AddW                    hello

SpellCheck            myEssay.txt

DeleteW                 play

SearchW                medical

SearchW                cs211

PrintF                    C.txt

PrintF                    H.txt

PrintF                    T.txt

Place the following in your data.txt file

Current approaches to enhancing concurrency in database systems have been focused on developing new transaction models that typically demand changes to either the atomicity consistency or isolation properties of the transactions themselves Indeed much of this work has been successful but most of these attempts suffer from being either computationally infeasible or requiring the transaction designer be sufficiently knowledgeable to determine a priori how the application semantics must interface with the transaction model

Our approach exploits an object-oriented world but is different than these others in that the transaction designer is not expected to have intimate application knowledge this load is placed on the transaction system which must be able to determine by static analysis how to maintain database consistency This paper describes an overall architectural model to facilitate multiversion objects that are explicitly designed to enhance concurrency Within the context of concurrency the key aspects addressed by this paper are as follows

First A transaction model is introduced to show how transactions are managed in our multiversion environment

Second A new correctness criterion is described that emits more histories than conflict serializability and is computationally tractable

Third an architectural model is developed to support multiversioning that provides the well-known ACID transaction properties These build a framework for the implementation of an optimistic concurrency control algorithm Further they exploit related issues required to generate reconciliation procedures which have an important role for providing a reliable system

Place the following in your myEssay.txt file

Concrrent approaches to enhancing concurrency in database systems have been focused on developing new transaction models that typically demand changes to either the atomicity consistency or isolation properties of the transactions themeselves Indeed much of this work has been successful but most of these attempts suffer from being either computationally infeasible or requiring the transaction designer be sufficiently knowledgeable to determine a priori how the application semantics must interface with the transaction model

Our approach exploits an object-oriented world but is diferent than these others in that the transaction designer is not expected to have intimate application knowledge this load is placed on the transaction system wich must be able to determine by static analyziz how to maintain database consistency This paper describes an overall architectural model to facilitate multiversion objects that are explicitly designed to enhanc concurrency Within the context of concurrency the key aspects addressed by this paper are as follows

First A transactian model is introduced to show how transactions are managed in our multiversion environment

Second A new correctness criterion is described that emits more histories than conflict serializability and is computationally tractable

Third an architectural model is developed to support multiversioning that provides the well-known ACID transaction properties These build a framework for the implementation of an optimistic concurrency control algorithm Further they exploit relatted issues required to generate reconciliation procedures which have an important role for providing a reliable system

Explanation / Answer

Below is your implementation of Dictionary class cpp file... Let me know if you have any issue

#include <iostream>

#include <fstream>

#include <ctype.h>

#include <string>

#include "Dictionary.h"

Dictionary::Dictionary() : maxWordsInDict(10000), maxWordsPerFile(10000)

{

// Purpose: to initialize the dictionary with 10000 being both

// the max number of words in the dictionary, and in any file.

totalWordsInDict = 0;

for (int i = 0; i < 26; i++)

{

numOfWordsInFile[i] = 0;

}

} // END Dictionary()

Dictionary::Dictionary(int dictMaxWords, int fileMaxWords) : maxWordsInDict(dictMaxWords), maxWordsPerFile(fileMaxWords)

{

// Purpose: to initialize the dictionary with dictMaxWords being used as the value for the

// maximum number of words in the dictionary, and fileMaxWords being used as the

// maximum number of words in any particular file.

totalWordsInDict = 0;

for (int i = 0; i < 26; i++)

{

numOfWordsInFile[i] = 0;

}

} // END Dictionary(int, int)

string Dictionary::toLowerCase(const string& word)

{

// Purpose: to take any string and return a modified copy,

// in which all alphabetical characters are lowercase.

string convWord = word; // Duplicate the passed string

for (unsigned int i = 0; i < convWord.length(); i++) // Iterate through it

{

if (isalpha(convWord[i])) // If the current letter is alphabetical

{

convWord[i] = (char) tolower(convWord[i]); // Convert it to lowercase, overwriting the current letter with this lowercase value.

}

}

return convWord; // return the lowercased word.

} // END toLowerCase

bool Dictionary::wordIsValid(const string& word)

{

// Purpose: To check word validity.

// A word is valid if it is 1 character or longer and starts with

// an alphabetical character.

return (( word.length() != 0 ) && ( isalpha(word[0]) ));

} // END wordIsValid

unsigned int Dictionary::getCorrespondingIndex(const string& word)

{

// Purpose: to get the index corresponding to the first letter

// off the passed word. a = 0, b = 1, B = 1, etc

return (unsigned int) (tolower(word[0]) - 'a');

} // END getCorrespondingIndex

string Dictionary::getFilenameByWord(const string& word)

{

// Purpose: to get the corresponding filename, using the passed word.

string filename = " .txt";

filename[0] = toupper(word[0]);

return filename;

} // END getFilenameByWord

bool Dictionary::AddAWord(const string& word)

{

// Purpose: to add a word to the corresponding file, making sure

// that the word is valid and the word isn't already in the dictionary.

switch (SearchForWord(word)) // IF the word is already there, fuck that shit.

{

case FILE_DOES_NOT_EXIST:

case WORD_NOT_FOUND:

break; // Continue to the rest of the func. if the word isn't there.

case WORD_IS_NOT_VALID: // If word is invalid or

case WORD_FOUND: // the word is already there

default: // or something else gets returned.. somehow.

return failure; // exit, failure.

}

const string wordToAdd = toLowerCase(word); // Convert the word to lower-case.

unsigned int corrIndex = getCorrespondingIndex(wordToAdd); // Get correspond. index.

if ( numOfWordsInFile[corrIndex] >= maxWordsPerFile ||

totalWordsInDict >= maxWordsInDict) // If we're at the limit for words in this file, or total words in dictionary

{

cerr << "Error: maximum number of words in file "" << getFilenameByWord(wordToAdd) << ".txt" reached, or " <<

"maximum number of words in dictionary reached. No more words can be added." << endl;

return failure;

}

string outFilename = getFilenameByWord(wordToAdd);

fstream outFstream( outFilename.c_str(), ios::out | ios::app ); // Open the corresponding file

outFstream << wordToAdd << " "; // Add the word

outFstream.close(); // Done with the file

totalWordsInDict++; // We've added a word so increment totalWordsInDict

numOfWordsInFile[corrIndex]++; // And the number of words in the file.

return success;

} // END AddAWord

bool Dictionary::DeleteAWord(const string& word)

{

// Purpose: Delete a word from the dictionary, including all of its duplicates, if it has any.

// The various things it does before ultimately performing that task

// however, aren't as simple as this function's name would suggest.

switch (SearchForWord(word)) // Search for word in the dictionary.

{

case FILE_DOES_NOT_EXIST: // If the file doesn't exist

case WORD_NOT_FOUND: // or the word wasn't found

case WORD_IS_NOT_VALID: // Or the word wasn't valid:

return failure; // Failure

case WORD_FOUND: // Otherwise the word was found.

default: // This should never be tripped unless I make a wrong return (hehe) in SearchForWord

break;

}

const string wordToDel = toLowerCase(word); // Properly lowercased word

const string filename = getFilenameByWord(wordToDel); // Filename to use

const unsigned int corrIndex = getCorrespondingIndex(wordToDel); // corresponding index for this word

unsigned int nTimesWordAppeared = 0; // The number of times the certain word appeared

fstream fileToModify(filename.c_str(), ios::in); // Fstream used to read in the words then write the ones that weren't matched

string currentWord; // Stores the current word

vector<string> WordsToRetain; // Stores all words that didn't match wordToDel

while ( (fileToModify >> currentWord) )// && (words.size() < maxWordsPerFile) )

{

currentWord = toLowerCase(currentWord); // Convert to lowercase

if (currentWord == wordToDel) // If it matches, we don't need it

{

nTimesWordAppeared++;

continue; // Skip to the next word (although there may not be one)

}

else // Otherwise, add the word to the vector, to keep

{

WordsToRetain.push_back(currentWord);

}

}

fileToModify.close();

fileToModify.open(filename.c_str(), ios::out | ios::trunc); // Open and truncate

for (unsigned int i = 0; i < WordsToRetain.size(); i++) // Iterate through the words vector

{

fileToModify << WordsToRetain[i] << " "; // Write the current word and a space to the file

}

fileToModify.close();

numOfWordsInFile[corrIndex] -= nTimesWordAppeared; // Decrement by the number of words that weren't read into the vector.

totalWordsInDict -= nTimesWordAppeared; // Ditto

return success;

} // END DeleteAWord

Dictionary::SEARCH_RESULT Dictionary::SearchForWord(const string& word)

{

// Purpose: To search for a word to see if it's in the dictionary.

// I expanded its purpose however to help in other situations

// where I wanted more verbose error messages.

// If I did the error messages here, I wouldn't have a choice

// on whether they were printed, or I'd have to pass a bool (ugly)

if (!wordIsValid(word))

{

return WORD_IS_NOT_VALID; // Invalid word

}

const string wordToFind = toLowerCase(word);

string inFilename = getFilenameByWord(wordToFind);

fstream inFstream( inFilename.c_str(), ios::in );

if (!inFstream)

{

cerr << "Error: file "" << getFilenameByWord(word) << "" does not exist, and thus searching could not be performed." << endl;

return FILE_DOES_NOT_EXIST;

}

string currentWord;

while (inFstream >> currentWord)

{

currentWord = toLowerCase(currentWord);

if (currentWord == wordToFind)

{

return WORD_FOUND;

}

}

return WORD_NOT_FOUND;

} // END SearchForWord

bool Dictionary::SpellChecking(const string& filename)

{

// Purpose: Check the file contents of filename to see if the words in it

// are in the dictionary or not already, thus "spell-checking" the file.

fstream fileToCheck(filename.c_str(), ios::in); // Try to get the requested file

if (!fileToCheck) // If we can't access it for whatever reason..

{

cerr << "Error: file "" << filename << "" does not exist, and thus spell-checking could not be performed." << endl;

return failure; // .. break out of the function

}

string currentWord;

while (fileToCheck >> currentWord) // Get a word

{

SEARCH_RESULT wordSearchResult = SearchForWord(currentWord);

if (wordSearchResult == WORD_IS_NOT_VALID) // Invalid word, don't even consider it.

{

continue;

}

else if (wordSearchResult == FILE_DOES_NOT_EXIST || // If the file isn't there, it's not in the dictionary, or ..

wordSearchResult == WORD_NOT_FOUND) // If the word was not found, it's also not in the dictionary

{

cout << "Word "" << currentWord << "" is not spelled correctly." << endl;

}

else // Word correct, this isn't necessary but I'll keep it here for now.

{

continue;

}

}

return success;

} // END SpellChecking

// Static public functions

bool Dictionary::PrintAFileInDict(const string& filename)

{

// Purpose: Print a file, with file words in each line. Printed to STDOUT.

fstream fileToPrint(filename.c_str(), ios::in);

if (!fileToPrint)

{

cerr << "Error: file "" << filename << "" does not exist, and thus printing could not be performed." << endl;

return failure;

}

string currentWord;

unsigned int currentWordNo = 0;

const unsigned int wordsPerLine = 5;

while (fileToPrint >> currentWord)

{

// This doesn't lowercase them first, it's a basically accurate version of the file.

cout << currentWord;

if ((++currentWordNo % wordsPerLine) == 0)

{

cout << endl;

}

else

{

cout << " ";

}

}

if (currentWordNo % wordsPerLine != 0) // If we didn't get to print a final endline, print one.

{

cout << endl;

}

return success;

} // END PrintAFileInDict

bool Dictionary::InsertWordsIntoDict(const string& filename)

{

// Purpose: insert the words found in the file specified into the dictionary

fstream sourceFile(filename.c_str(), ios::in);

if (!sourceFile)

{

cerr << "Error: file "" << filename << "" does not exist, and thus file-insertion could not be performed." << endl;

return failure;

}

string currentWord;

while (sourceFile >> currentWord)

{

if (totalWordsInDict >= maxWordsInDict) // If we're over the limit, don't keep calling the add a word function, it's a waste of time.

{

cerr << "Error: max words in dictionary (" << maxWordsInDict << ") has been reached. Complete insertion failed." << endl;

return failure; // As usual boolean values fail to suffice in certain contexs. We may have inserted SOME, so it's not a true absolute failure.

}

this->AddAWord(currentWord); // Add the word, this handles incrementation for us.

}

sourceFile.close();

return success;

}

void Dictionary::ProcessTransactionFile(const string& filename)

{

// Purpose: To process a transaction file and perform what it specifies.

ifstream transactFile(filename.c_str());

if (!transactFile)

{

cerr << "Error: Transaction file "" << filename << "" does not exist." << endl;

return;

}

string command, data;

while (transactFile >> command >> data)

{

if (command == "AddW")

{

this->AddAWord(data);

}

else if (command == "DelW")

{

this->DeleteAWord(data);

}

else if (command == "SearchW")

{

SEARCH_RESULT wordSearchResult = SearchForWord(data);

if (wordSearchResult == WORD_NOT_FOUND ||

wordSearchResult == FILE_DOES_NOT_EXIST)

{

cout << "Word "" << data << "" was not found." << endl;

}

else if (wordSearchResult == WORD_FOUND)

{

cout << "Word "" << data << "" was found." << endl;

}

else

{

cout << "Word "" << data << "" is not valid." << endl;

}

}

else if (command == "InsertF")

{

this->InsertWordsIntoDict(data);

}

else if (command == "PrintF")

{

this->PrintAFileInDict(data);

}

else if (command == "SpellCheck")

{

this->SpellChecking(data);

}

}

transactFile.close();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote