Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ program Dynamic memory, searching and C strings. The purpose of this assignment is to give you practice using dynamic memory allocation, c-string functions, sorting,

C++ program

Dynamic memory, searching and C strings.

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

1.Read an unsorted keywords file once to determine how many words are in the file.

2.Allocate memory dynamically to store the unsorted keywords in an array of C strings. (Hint: be sure to clear your input file stream before re-reading the file)

3.Reread the keywords file a second time and store the words in the dynamically allocated array of C strings.

4.Sort the array of key words. (Hint: be sure to check your sorted array of key words - there should be 84)

5.Search a C++ program input file for occurrences of the keywords:

-Read one line at a time from the code file.

-Parse each line into separate words. Ignore any words that are inside a comment.

-Search the keyword array to determine if each word is a keyword.

-For keywords, print the line number, the keyword, and the position of the keyword in the line.

-Keep a count of the number of keywords found

Program Requirements

1.This zipped file (https://drive.google.com/file/d/1UyUute4xoc0vfW7mZ_tG1WZjfWiql2Xy/view) contains the keywords file and the input code file for searching.

2.Use a char array to hold each line from the input code file. Parse each line into individual words for spell checking. Note, you may NOT use the stringstream classes for this assignment.

3.Make sure you check the input file for successful opens.

4.Your output should match the format show below with the correct line number and position of each word in the line. The line character positions start at zero. Note, there are more than 50 lines of output.

Program Output

Your output should looks like this:

Line 8: using(0) namespace(6) <== using occurs at position 0 on line 8, namespace occurs at position 6 on line 8

Line 10: const(0) int(6)

Line 12: void(0) const(19)

Line 13: void(0) char(20) int(32) const(48)

Line 14: bool(0) const(24) char(30) const(42)

Line 15: void(0) char(17)

Line 16: void(0)

Line 17: void(0)

Line 19: int(0)

Line 21: const(4)

...

Number of keywords found = ?? <== Add this line at the end of your output, replace ?? with the correct number

Program Hints

1.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.

2.Use a small keyword file and a small test C++ code file initially as you are developing your code.

3.Use strstr() to find the // of a C++-style comment.

4.Use strtok() for the parsing of each line. You should "parse out" much of the program "punctuation".

5.You might want to make a copy of each line (maybe as a string) to determine the position of the keyword in the line. This is because strtok() destroys the original line.

6.Mac 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().

7.Your program should produce more that 50 lines of output and you should find more than 70 keywords (many are repeats).

The keyword file looks like this:

for

if

nullptr

break

int

long

sizeof

return

short

else

friend

const

static_cast

...

The input code file looks like this:

#include

#include

#include

#include

#include

#include

#include

using namespace std;

const int DictionarySize = 23907;

void getDictionary(const string& filename,string*);

void spellCheckLine(char* line, int lineNumber, const string* dictionary);

bool wordIsInDictionary(const char* word, const string* dictionary);

void toLowerCase(char* text);

...

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

More Books

Students also viewed these Databases questions

Question

4. What will the team agreement contain?

Answered: 1 week ago