This assignment uses pointers to perform something done often in computer applications: the parsing of text to find “words” (i.e., strings delineated by some delimiter).   Assume you are working in the marketing department of a company that sells computers and accessories.  Your team has been tasked with determining how customers perceive your products based on customer surveys.  The questions in the surveys are open-ended.  That is, customers write product reviews as paragraphs about their perceptions of your products.  Your job is to prepare the customer responses to facilitate a sentiment analysis. Program executes without crashing Appropriate Internal Documentation main()      Declares variables appropriately (uses pointers where needed for tokenization and creates a Review object for storage of Words)      Prompts user to enter a filename with appropriate error checking      Contains a loop to tokenize each word in the product review using the            strtok_s function      Calls the AddWord function in the Review class (passing in each token) Review class:    Constructor(s) as appropriate       Data members: vector of Word objects       Functions: AddWord, DisplayWords, getters/setters as appropriate   Word class Constructor(s) as appropriate Data members:  word and frequency Functions:  ConvertToLowerCase, getters/setters as appropriat

New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter14: Exploring Object-based Programming: Designing An Online Poker
Section14.1: Visual Overview: Custom Objects, Properties, And Methods
Problem 7QC
icon
Related questions
Question

Can someone help me with this c++ code?

Instructions:

 

This assignment uses pointers to perform something done often in computer applications: the parsing of text to find “words” (i.e., strings delineated by some delimiter).

 

Assume you are working in the marketing department of a company that sells computers and accessories.  Your team has been tasked with determining how customers perceive your products based on customer surveys.  The questions in the surveys are open-ended.  That is, customers write product reviews as paragraphs about their perceptions of your products.  Your job is to prepare the customer responses to facilitate a sentiment analysis.

Program executes without crashing

Appropriate Internal Documentation

main()

     Declares variables appropriately (uses pointers where needed for tokenization and creates a Review object for storage of Words)

     Prompts user to enter a filename with appropriate error checking

     Contains a loop to tokenize each word in the product review using the
           strtok_s function

     Calls the AddWord function in the Review class (passing in each token)

Review class:

   Constructor(s) as appropriate

      Data members: vector of Word objects

      Functions: AddWord, DisplayWords, getters/setters as appropriate

 

Word class

Constructor(s) as appropriate

Data members:  word and frequency

Functions:  ConvertToLowerCase, getters/setters as appropriate

Processing:
After an entire product review is read in to your character array, print out the entire review in
sentence form. Next, tokenize each word using the strtok s function described above. As each
word in the review is tokenized, call a function in the Review class (passing in the token pointer
that is returned from the strtok s function) to add the new word to the Review object's vector of
words. Call this function AddWord.
Before storing the word as an object, the AddWord function in the Review class should search
the existing vector of Word objects to determine if the word already exists in it. To determine if
the word already exists in the vector of Word objects, you should loop over the vector and
Page 21 of 38
CSIS 112
compare each Word's "word' with the new word to be added. If it does not already exist, the
function should create a new Word object (passing in the pointer to the word as a parameter to
the constructor of the Word class), assign it a frequency of 1, and add the new object to the
vector in the Review class. If the word does already exist in the vector, you should merely call a
function in the Word class that will increase the frequency of that Word object by 1.
One note of caution: C++ is case sensitive. Therefore, the word "thanks" is considered
different from the word "Thanks'". Semantically, they are the same word. Therefore, we only
want to store one instance of the word. My recommendation is to create a function in the Word
class that will convert the word into lowercase before assigning it to the "word' data member.
The constructor of the class would be an excellent place to call this function (i.e. before the word
is ever stored in the member variable). To summarize: store only the lowercase versions of each
word in the Word objects.
For information on how to convert a character array into all lowercase characters, this blog on
StackOverflow is a good resource: https://stackoverflow.com/questions/27054353/c-converting-
array-of-char-into-lower-case
Be sure to cite it in the resources section of your program if you use any of this code.
Naturally, in real-life, you would want to eliminate words such as "the," "an," "and," “but," "or,"
etc. You would also want to only include root words. That is, there is no need to store "enjoy,"
"enjoyed," and “enjoying" as separate words. This process is called "stemming." However,
pruning your list to exclude words with no meaning and including only root words are tasks that
are beyond the scope of this assignment. Therefore, your vector should contain a unique list of
all the words in the product review with their respective frequencies.
Output:
The output of the program should be a listing of all of the words in the review with a count of
their frequencies. You do not have to assign meaning to any of these words as would be required
in a full-blown sentiment analysis. However, this program performs the necessary first steps in
preparing the data for a more extensive investigation of consumer sentiment.
Here is an example of how your output might look:
Transcribed Image Text:Processing: After an entire product review is read in to your character array, print out the entire review in sentence form. Next, tokenize each word using the strtok s function described above. As each word in the review is tokenized, call a function in the Review class (passing in the token pointer that is returned from the strtok s function) to add the new word to the Review object's vector of words. Call this function AddWord. Before storing the word as an object, the AddWord function in the Review class should search the existing vector of Word objects to determine if the word already exists in it. To determine if the word already exists in the vector of Word objects, you should loop over the vector and Page 21 of 38 CSIS 112 compare each Word's "word' with the new word to be added. If it does not already exist, the function should create a new Word object (passing in the pointer to the word as a parameter to the constructor of the Word class), assign it a frequency of 1, and add the new object to the vector in the Review class. If the word does already exist in the vector, you should merely call a function in the Word class that will increase the frequency of that Word object by 1. One note of caution: C++ is case sensitive. Therefore, the word "thanks" is considered different from the word "Thanks'". Semantically, they are the same word. Therefore, we only want to store one instance of the word. My recommendation is to create a function in the Word class that will convert the word into lowercase before assigning it to the "word' data member. The constructor of the class would be an excellent place to call this function (i.e. before the word is ever stored in the member variable). To summarize: store only the lowercase versions of each word in the Word objects. For information on how to convert a character array into all lowercase characters, this blog on StackOverflow is a good resource: https://stackoverflow.com/questions/27054353/c-converting- array-of-char-into-lower-case Be sure to cite it in the resources section of your program if you use any of this code. Naturally, in real-life, you would want to eliminate words such as "the," "an," "and," “but," "or," etc. You would also want to only include root words. That is, there is no need to store "enjoy," "enjoyed," and “enjoying" as separate words. This process is called "stemming." However, pruning your list to exclude words with no meaning and including only root words are tasks that are beyond the scope of this assignment. Therefore, your vector should contain a unique list of all the words in the product review with their respective frequencies. Output: The output of the program should be a listing of all of the words in the review with a count of their frequencies. You do not have to assign meaning to any of these words as would be required in a full-blown sentiment analysis. However, this program performs the necessary first steps in preparing the data for a more extensive investigation of consumer sentiment. Here is an example of how your output might look:
The Program: Setting up classes and understanding tokenization
The first step in a sentiment analysis is to perform text mining to parse sentences in a product
review document into words and store them in an array (or vector) along with their frequencies.
Tokenization:
The process of parsing sentences into words is called tokenization. To tokenize a sentence into
words, use the C++ function strtok s(). [Note: do not try to use the C++ strtok function because
it has been deemed unsafe and has therefore been deprecated.]
Your client code (main()) should contain a character array into which you will read an entire
product review from a file. [You may define this character array to contain 1000 characters.]
Using this character array, main() should call the function strtok_s() to tokenize the character
array into separate words. Here is an excellent discussion of tokenizing and the strtok_s
function: https://msdn.microsoft.com/en-us/library/ftsafwz3.aspx
Class Construction:
Write a class called Word that stores a word from a product review in a data member called
"word." The cla:
frequency) that the word was found in a product review document. The class should have a one-
should also contain an integer variable representing the number
times (i.e.
Page 20 of 38
CSIS 112
argument constructor that receives a pointer to a c-string (character array) containing the
word as its one parameter. (Note that the output of the strtok_s function described above is a
pointer to a c-string containing the word that was parsed. This is what you will pass in to
the Word constructor.) The Word constructor should also set the frequency of this Word object
to 1. Appropriate set and get functions should be included for both the word and frequency data
members.
Write a class called Review that contains a vector of objects of the Word class. The class
should contain functions to add a new Word object to the vector and to print out all of the Words
in the vector with their respective frequencies.
Logic of the
program
Main()
In main(), create an object of the Review class. You will use this object to call the functions in
the Review class that will manage the words retrieved from the document.
Data Inputs:
In this assignment, you will be reading in a single product review from a file.
You will prompt the user to enter a file that contains the product review. (Be sure to
include error checking to ensure that the file can be successfully opened.) Assume that the
sentences in the review consist of words separated by blanks, commas, and periods. There are no
punctuation marks, such as exclamation points, semi-colons, colons, etc. Only periods and
commas exist in each sentence.
A product review is less than 1000 characters.
Here is an example of what a product review could look like:
The laptop I purchased was awesome. It had twice as much memory and processing
speed as my last computer, yet it was small and lightweight. I am very pleased with this
purchase and the awesome customer service I received. I also purchased some
accessories that were really great, too. Thanks for being such a great and awesome
company. I will be purchasing more from you in the future.
Transcribed Image Text:The Program: Setting up classes and understanding tokenization The first step in a sentiment analysis is to perform text mining to parse sentences in a product review document into words and store them in an array (or vector) along with their frequencies. Tokenization: The process of parsing sentences into words is called tokenization. To tokenize a sentence into words, use the C++ function strtok s(). [Note: do not try to use the C++ strtok function because it has been deemed unsafe and has therefore been deprecated.] Your client code (main()) should contain a character array into which you will read an entire product review from a file. [You may define this character array to contain 1000 characters.] Using this character array, main() should call the function strtok_s() to tokenize the character array into separate words. Here is an excellent discussion of tokenizing and the strtok_s function: https://msdn.microsoft.com/en-us/library/ftsafwz3.aspx Class Construction: Write a class called Word that stores a word from a product review in a data member called "word." The cla: frequency) that the word was found in a product review document. The class should have a one- should also contain an integer variable representing the number times (i.e. Page 20 of 38 CSIS 112 argument constructor that receives a pointer to a c-string (character array) containing the word as its one parameter. (Note that the output of the strtok_s function described above is a pointer to a c-string containing the word that was parsed. This is what you will pass in to the Word constructor.) The Word constructor should also set the frequency of this Word object to 1. Appropriate set and get functions should be included for both the word and frequency data members. Write a class called Review that contains a vector of objects of the Word class. The class should contain functions to add a new Word object to the vector and to print out all of the Words in the vector with their respective frequencies. Logic of the program Main() In main(), create an object of the Review class. You will use this object to call the functions in the Review class that will manage the words retrieved from the document. Data Inputs: In this assignment, you will be reading in a single product review from a file. You will prompt the user to enter a file that contains the product review. (Be sure to include error checking to ensure that the file can be successfully opened.) Assume that the sentences in the review consist of words separated by blanks, commas, and periods. There are no punctuation marks, such as exclamation points, semi-colons, colons, etc. Only periods and commas exist in each sentence. A product review is less than 1000 characters. Here is an example of what a product review could look like: The laptop I purchased was awesome. It had twice as much memory and processing speed as my last computer, yet it was small and lightweight. I am very pleased with this purchase and the awesome customer service I received. I also purchased some accessories that were really great, too. Thanks for being such a great and awesome company. I will be purchasing more from you in the future.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning