USING C USE SYNTAX C ON VISUAL STUDIO DONT USE STRUC VECTOR

USING C++. USE SYNTAX C++ ON VISUAL STUDIO. DON\"T USE STRUC, VECTOR, OR C SYNTAX. THIS IS C++ ASSGINMENT. READ CAREFULLY.

The purpose of this assignment is to give you practice using dynamic memory allocation, c-string functions, sorting, and searching. You will write a spell checking program and test it.

Program Steps

Read a dictionary word file into an array of c-strings. You will need to dynamically allocate memory for each word in the dictionary. The word file contains 23,907 words.
Sort the dictionary.
Reading in a test file, one line at a time. Parse the line to get each individual word in the line. Search the dictionary word list (the array of c-strings) for each word in the line. If the word is not found, print a message. The search should be performed as a binary search.

Program Requirements

Use these files for your dictionary and the final spell check test.

Use an array of char pointers store your word file.  Allocate memory dynamically to store each word in a char array.  Store the dictionary words in lower case.

Use a temporary char array to hold each line in the test file. “Parse” each line into individual words for spell checking. Note, you may notuse the stringstream classes for this assignment.

Spell checking must ignore case. For example, “Hello” is the same as “hello”.

Program Output

Your output should looks quite similar to this:

Misspelled word, struggled on line 10
Misspelled word, consecrated on line 11
Misspelled word, unfinished on line 13
Misspelled word, nobly on line 14
Misspelled word, advanced on line 14
...

Program Hints

Follow the program steps. Write only one part of the program at a time. Test each part before you proceed to the next step. Do not continue if one part has a problem. Ask for help with a step, if you can\'t get it to work. Remember to allow plenty of time for this assignment.

Use a small dictionary and a small test file initially as you are developing your code.

For your dictionary sort, you can \"swap pointers\" since you are working with an array of pointers.

Use strtok() for the parsing of each line.

Xcode users: There is a \ at the end of each line in the test file. You can suppress it by adding \"\ \" as a delimiter for strtok().

Your program should find between 8 and 12 misspelled words.

Solution

Answer:

note: include the text files

c++ code:

#include <iostream>

#include <fstream>

#include <string>

#include <sstream>

#include <algorithm>

#include <vector>

using namespace std;

//main program

int main()

{

     //declares the variables

     string testlines;

     string codelines;

     vector<string> words;

     vector<string> apps;

//opening keywords text file

     ifstream Tests(\"keywords.txt\");

     if (!Tests)

     {

          cout << \"There was a problem opening the file. Press any key to close.\ \";

          return 0;

     }

   

     while (Tests)

     {

          Tests >> testlines;

          //cout << testline << endl;

          words.push_back(testlines);

     }

   

     //Dynamically allocating keyords to array

     for (int it = 0;it < words.size() - 1;it++)

    

     //sorting the keywords

     sort(words.begin(), words.end());

   

     cout << \"output\" << endl;

     //opening the input file

     ifstream codes(\"input.txt\");

     if (!codes)

     {

          cout << \"There was a problem opening the file. Press any key to close.\ \";

          return 0;

     }

     int n1 = 0;

     int count1 = 1;

     int map1 = 0;

     int g1 = 0;

     bool c1 = true;

     while (codes)

     {

        

     codes >> codelines;

        

          for (int jt = 0;jt < words.size();jt++)

          {

              if (codes.peek() == \'\ \')

              {

                   count1 = count1 + 1;

                   n1 = 0;

                   if (words[jt] == codelines)

                   {

                        c1 = true;

                        cout << \"line[\" << count1 << \"]\";

                        cout << codelines << \"[\" << n1 << \"]\";

                        cout << endl;

                        //   n = n+sizeof (codeline);

                        n1 = n1 + codelines.length();

                        map1 = map1 + 1;

                        break;

                   }

                   else

                        c1 = false;

                   break;

              }

              else

              {

                   if (words[jt] == codelines)

                   {

                        c1 = true;

                        cout << \"line[\" << count1 << \"]\";

                        cout << codelines << \"[\" << n1 << \"]\";

                        cout << endl;

                 

                        n1 = n1 + codelines.length();

                        map1 = map1 + 1;

                        break;

                 }

                   else

                        c1 = false;

              }

          }

          if (c1 == false && n1 != 0)

              n1 = n1 + codelines.length();

   

     }

     cout << \"Total no of keywords found\" << map1 << endl;

     system(\"pause\");

     return 0;

}

USING C++. USE SYNTAX C++ ON VISUAL STUDIO. DON\
USING C++. USE SYNTAX C++ ON VISUAL STUDIO. DON\
USING C++. USE SYNTAX C++ ON VISUAL STUDIO. DON\
USING C++. USE SYNTAX C++ ON VISUAL STUDIO. DON\
USING C++. USE SYNTAX C++ ON VISUAL STUDIO. DON\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site