Question
PLEASE WRITE C++ PROGRAM you will rework the below C++ Program Called countWord_Program.cpp (Located in the last part of this page) to employ an
PLEASE WRITE C++ PROGRAM
you will rework the below C++ Program Called "countWord_Program.cpp" (Located in the last part of this page) to employ an object in an application. It constructs the same word list as was done in Project below ; one object for each unique word, with multiplicity.
Each word will now be represented in a full-blown object, replacing the data only structs from Project below:
Using the suggested name WordRec, here are the specs:
WordRec: Data attributes: word or token (string) and number of appearances (int)
Implement these member functions in the Word.Rec class to perform the actions given (operators noted):
- Constructor initializes word to " " and counter to 0.
- Set and get for each data member.
- Increment the counter (++; both pre and post).
- Return whether a WordRec object's word attribute is alphanumerically less than that of another Word.Rec object passed in (operator <)
- Return whether a WordRec object's word attribute is equal to that of another Word.Rec object passed in (operator ==)
Add the following non-member associated operators to the WordRec class' files (these are NOT friends):
- Print a WordRec object's data attributes in a well-formatted manner (operator <<)
- Read a string from an ifstream into a WordRec object (and set its counter to l) (operator >>)
This C++ class will be stored in files Word.Rec.h and Word.Rec.cpp.
Your application, to be named p2.cpp, will repeat the Project below task of reading the data into an array of 100 WordRec objects, and then sorting it while processing duplicates (still a combined operation). Additionally. it will now permit the user to request output of the data in several modes, chosen via a menu matching the one in the box.
Choice:
A)ll Words with Number of Appearances
P)rint Words That Appeared a Specified t Times S)how first N Characters of All Words
F)ind a Word
Q)uit
Functions :
- Open the file
-- Same as Project l's openFile ( )
- Read the file into the array of words
-- In a loop, call the >> operator to input the data (you can update the inputWords function from Project below).
- Sort/Remove duplicates.
-- Process User RequestsIn a loop prompt and input the user's choice. You must use the character choices (case insensitive) in the menu in the box. If the user enters:
-- 'A', print all words and their multiplicities, well formatted in a loop using the << operator you wrote for the WordRec class; you should be able to condense and convert the print function from project 1 for this purpose.
-- 'P', input an int and call a function (also in the application file) that prints qualifying words.
-- 'S' is the same as 'A', excpt you are printing all words after applying the substr() function of the string class. This won't be a << overload.
-- 'F',perform the search in yet another function in the application, reporting the result.
-- 'Q', terminate the program.
Notes:
- Your main () will be mostly function calls. Each task must be in its own module (function). This includes handling the user's choice in the application. This will be a point of emphasis in grading.
- Proper object-oriented design is a must. Implement your WordRec class properly, using sets and gets to access the data, even .in other member functions.
- The sort will no longer directly compare word members. It must use the overloaded < operator to compare entire WordRec objects by their words.
- Similarly, find will make use of == (const WordRec &,const string &) from above.
You should be able to reuse functions from Project 1, likely with_ modification to access data.
- Your prompts must be descriptive.
- Input of menu choices must be case insensitive. Letter grade penalty for non-compliance,
- Your output must be well labeled and easy to read. It must have category header(s) when user input results in output of tabular data. When a user specifies a multiplicity, you should not print how many times each word appeared (it will be the same for all of them; put that info in the header). If you print all the words, the output must line up. No category headers should be printed if no data is output; print a 'not found' message.
- To show the first N characters of a string requires using substr ( ).
- . All << operators must take a constant reference to the object. Note that >> operators can't have a constant reference; instead, they have a reference.
- A makefile is provided for you below under the name Makefile.txt Don 't forget to call it with /p2 .
- Word.Rec.h is provided for you below under the name Word.Rec.h . Do NOT add any functions to this file.
- To make sure the program is working , I will expect to type make to compile the file, and p2 to run it Make sure that it will run on acad under these conditions.
- The program must be well written, properly indented, and commented.
----------------------------------------------------------------------------------------------------------
Makefile.txt :
CC=/usr/bin/g++34 debug=-g p2: p2.o WordRec.o $(CC) -o p2 p2.o WordRec.o $(debug) p2.o: p2.cpp WordRec.h $(CC) -c p2.cpp $(debug) WordRec.o: WordRec.cpp WordRec.h $(CC) -c WordRec.cpp $(debug) clean: m -f *.o p2
------------------------------------------------------------------------------------------
Word.Rec.h :
// A WordRec is a container used to track a word and its multiplicity in data #ifndef WORDREC_H #define WORDREC_H #include#include #include #include using namespace std; class WordRec { public: // WordRec Constructor WordRec(string word="",int times=1); //Sets the WordRec data member word void setWord(string words); //Returns WordRec data member word string getWord() const; //Returns WordRec data member count int getCount() const; //Operator ++ overload(Pre and Post): Increments data member count WordRec &operator++(); WordRec operator++(int); //Operator < overload: // Returns whether a WordRec's word is alphanumerically less than another // WordRec's word bool operator<(const WordRec &right) const; //Operator == overload: // Returns whether a WordRec's word is equal to another WordRec's word bool operator==(const WordRec &right) const; private: //Contains a word from a file string word; //Contains the multiplicity of a word from a file int count; //Sets the WordRec data member count (why private?) void setCount(int counts); }; //Operator << overload: Prints a WordRec object ostream &operator<<(ostream &out, const WordRec &right); //Operator >> overload: Inputs words from file into a WordRec object ifstream &operator>>(ifstream &inf, WordRec &right); #endif
------------------------------------------------------------------------------------------------------------
countWord_Program.cpp :
#include -------- Thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started