60 384
Assignments Done
Successfully Done
In April 2018

Answer to Question #27130 in C++ for sunday

Question #27130
b. Create a function in the StringProcessing class called wordSizeOccurrence that reads several lines of text and prints a table indicating the number of one-letter words, two-letter words, three-letter words, etc. appearing in the text. For example, the phrase
Expert's answer
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

class StringProcessing{
static const int nMax = 100;
void wordSizeOccurrence(void){
stringstream _s; //stream class to operate on strings (use a string buffer)
string _word, _str;
int wordSize[nMax] = {}; //array filled with 0
getline(std::cin, _str); //extracts characters from std::cin and stores them into _str
_s<<_str; //overwrites the contents _str in _s
wordSize[_word.length()]++; //increments the array element that meets a given length of words
for(int i = 0; i<nMax; i++) //if there are words with length from 1 to 100 characters, print the number of theirs
if(wordSize[i]!=0) cout<<i<<"-letter words: "<<wordSize[i]<<endl;

int main(){
StringProcessing ob;
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


Assignment Expert
23.04.15, 18:12

Dear Obed,
You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!

23.04.15, 08:01

This was so helpful, thank you guys so much! i really appreciate your help! :D

Leave a comment

Ask Your question

Privacy policy Terms and Conditions