Can I please get help writing this in C++ Write a class called Word that stores a word from a product review in a data member called “word.” The class should also contain an integer variable representing the number of times (i.e. frequency) that the word was found in a product review document.  The class should have a one-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.   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. 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 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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.2: Providing Class Conversion Capabilities
Problem 5E
icon
Related questions
Question

Can I please get help writing this in C++

Write a class called Word that stores a word from a product review in a data member called “word.” The class should also contain an integer variable representing the number of times (i.e. frequency) that the word was found in a product review document.  The class should have a one-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.

 

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.

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

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
Reference Types in Function
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning