Question
SOLVE THIS PROBLEM USING VECTORS, STRUCT, STRING IN C++ Given a string variable string s; initialize the value of s by receiving a paragraph in
SOLVE THIS PROBLEM USING VECTORS, STRUCT, STRING IN C++
Given a string variable string s; initialize the value of s by receiving a paragraph in English text from the standard input cin. You could assume that this paragraph consists of no more than 500 tokens. Again, tokens are sequences of contiguous characters separated by any of the user-specified delimiters (e.g., white spaces and Comma). Please implement a C++ program to recognize each unique token in s and its frequency (i.e., the number of times this token appears in s); Specifically, you are required to include the following elements in your program:
1. Identify the least frequent letter in the above text. Implement a separate function void getLeastFreqLetter(string& ) for this task. The main() function then calls this function to find out the least frequent letter and its frequency.
2. Declare a struct TokenFreq that consists of two data members: (1) string token; and (2) int freq; Obviously, an object of this struct will be used to store a specific token and its frequency. Remember to declare this struct at the beginning of your program and outside any function. A good place would be right after the "using namespace std;" line. This way, your functions will be able to use this struct to declare variables.
3. Implement the function vector
Example input and outputs:
Assume that you type the following input string on your keyboard and store it in string s:
"And no, I'm not a walking C++ dictionary. I do not keep every technical detail in my head at all times. If I did that, I would be a much poorer programmer. I do keep the main points straight in my head most of the time, and I do know where to find the details when I need them. by Bjarne Stroustrup"
After having called the getTokenFreq() function, you should identify the following list of (token, freq) pairs and store them in a vector (note that the order might be different from yours):
{ 'no': 1, 'and': 1, 'walking': 1, 'be': 1, 'dictionary': 1, 'Bjarne': 1, 'all': 1, 'need': 1, 'Stroustrup': 1, 'at': 1, 'times': 1, 'in': 2, 'programmer': 1, 'where': 1, 'find': 1, 'that': 1, 'would': 1, 'when': 1, 'detail': 1, 'time': 1, 'to': 1, 'much': 1, 'details': 1, 'main': 1, 'do': 3, 'head': 2, 'I': 6, 'C++': 1, 'poorer': 1, 'most': 1, 'every': 1, 'a': 2, 'not': 2, 'I'm': 1, 'by': 1, 'And': 1, 'did': 1, 'of': 1, 'straight': 1, 'know': 1, 'keep': 2, 'technical': 1, 'points': 1, 'them': 1, 'the': 3, 'my': 2, 'If': 1}
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