Question

Make a UML Class Diagram #include "stdafx.h" #include <iostream> #include <fstream>    #include <cctype> #include <cstring> #include...

Make a UML Class Diagram

#include "stdafx.h"
#include <iostream>
#include <fstream>   
#include <cctype>
#include <cstring>
#include <string>  
#include <iomanip>
#include <ctime>
#include <limits>

#include "HashTable.h"

#pragma warning(disable : 4996)
using namespace std;

typedef HashTable<string>::Iterator iterDec;

const char* DELIMITERS = " ,.-\':;?()+*/\\%$#!\"@\^&";

const int TABLE_SIZE = 29990;

int Spell_Check(HashTable<string>& hashTable, string word);

void Print_Table_Stats(HashTable<string>& hashTable);

string To_Lower_Case(string word);

int main()

{

   string filename;

   cout << "Enter the file name: ";

   cin >> filename;

   int result = 0;

   string userInput;

   string currWord;

   clock_t beg;     

   clock_t end;     

   char response;

   ifstream infile;

   HashTable<string> hashTable(TABLE_SIZE);

   infile.open(filename);

   if (infile.fail())

   {

       cout << "**FATAL ERROR - Sorry the dictionary file inputed by you could not be found...\n";

       exit(1);

   }

   cerr << "PLEASE WAIT Dictionary is loading........\n";

   beg = clock();  

   while (infile >> currWord)

   {

       if (!hashTable.Count(currWord))

       {    

           hashTable.Insert(currWord);

       }

   }

   infile.close();

   end = clock() - beg;  

   cout << "Your Dictionary has been loaded in: " <<

       (double)end / ((double)CLOCKS_PER_SEC) << " secs!";

   cout << endl;

   cout.fill('-');

   cout << left << setw(50) << "" << endl;

   do {    

       cout << "Please enter Sentence/Words: ";

       getline(cin, userInput);

       cout << endl;

       char* splitInput = strtok(const_cast<char*>(userInput.c_str()), DELIMITERS);

       while (splitInput != NULL)

       {

           currWord = splitInput;

           currWord = To_Lower_Case(currWord);

           result += Spell_Check(hashTable, currWord);

           splitInput = strtok(NULL, DELIMITERS);

       }

       if (result > 0)

       {     

           cout << "Number of Words Spelled Incorrectly: " << result << endl;

           result = 0;

       }

       cout << "Do you want to enter a Sentence/Words? (y/quit): ";

       cin >> response;

       cin.ignore(numeric_limits<streamsize>::max(), '\n');   

   } while (toupper(response) == 'Y');

   cout << "BYE The Dictionary Exits!!\n";

   return 0;

}

int Spell_Check(HashTable<string>& hashTable, string word)

{

   int result = 0;

   int suggestions = 0;

   string remove[256];

   int numRemove = 0;

   if (!hashTable.Count(word))

   {

       ++result;

       cout << "** " << word << ": ";

       for (unsigned x = 0; x < word.length(); ++x)

       {

           string alteration = word;

           for (char c = 'a'; c <= 'z'; ++c)

           {

               alteration[x] = c;

               if (hashTable.Count(alteration))

               {

                   cout << alteration << ", ";

                   remove[numRemove++] = alteration;

                   ++suggestions;

                   hashTable.Remove(alteration);

               }

               string insertion = word.substr(0, x) + c + word.substr(x);

               if (hashTable.Count(insertion))

               {

                   cout << insertion << ", ";

                   remove[numRemove++] = insertion;

                   ++suggestions;

                   hashTable.Remove(insertion);

               }

           }

       }

       for (unsigned c = 0; c < word.length() - 1; ++c)

       {

           string transposition = word.substr(0, c) + word[c + 1] + word[c] + word.substr(c + 2);

           if (hashTable.Count(transposition))

           {

               cout << transposition << ", ";

               remove[numRemove++] = transposition;

               ++suggestions;

               hashTable.Remove(transposition);

           }

           string deletion = word.substr(0, c) + word.substr(c + 1);

           if (hashTable.Count(deletion))

           {

               cout << deletion << ", ";

               remove[numRemove++] = deletion;

               ++suggestions;

               hashTable.Remove(deletion);

           }

       }

       while (numRemove >= 0)

       {

           hashTable.Insert(remove[numRemove--]);

       }

       if (suggestions< 1)

       {

           cout << "Sorry No spelling suggestion found...";

       }

       cout << endl << endl;

   }

   return result;

}

string To_Lower_Case(string word)

{  

   for (unsigned c = 0; c < word.length(); ++c)

   {    

       word[c] = tolower(word[c]);

   }

   return word;

}  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have created the UML using ArrayList. All you need to do is replce Array List with hashtable as per the needs of your code.

Add a comment
Know the answer?
Add Answer to:
Make a UML Class Diagram #include "stdafx.h" #include <iostream> #include <fstream>    #include <cctype> #include <cstring> #include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT