Saturday, May 22, 2010

I need a c++ program that takes a string input and counts the number of one-letter,two-letter words n so on.?

for ex: if input string is "ram is a good boy" then program shud count number of one-letter words(in this case it is 1 ie 'a'), two-letter words(here its 1 ie 'is'), three-letter words(here it is 2 ie 'ram' and 'boy') and more than three letter word( here it is 1 ie 'good')..... its very urgent

I need a c++ program that takes a string input and counts the number of one-letter,two-letter words n so on.?
rofl @ the General. haha.





I think it was a question-statement, where the question is hidden within the statement, thereby making the subject line "I need a c++ program that takes a string input and counts the number of one-letter,two-letter words n so on." the question.





What was asked was for us to make him a C++ program that takes an input stream of type string, and within that string counts how many words are one letter long, two letter long, three letter long, etc...





My answer: try to do it yourself and just ask for help, not for the entire program (which you did by saying "I need a c++ program"). If you want a programmer to make the program for you, try rentacoder.com or something, but Y!Answers is not a programmer for hire or homework do-er.....ugh. lol?
Reply:That's awesome !


You forgot to ask the question.
Reply:i wont provide u with a code,,, but i can tell u a pseudocode.,,,





there can be many approaches for that,, but for beginner it can be,,, create an integer array that will keep the record of the no. of counts, lets say array[0] will keep the record of words of size 1, and array[1] will keep the record of word of size 2 and so on.....





traverse thru the array of input string,, each time u pass the character, incremnet ur count variable, and as u get space in ur input string, store the value of count in array[count-1] location. reset the counter and start countign again frm where u left counting,, and when u r done,,, u have stored all ur results in ur array,, u can use dat aaray to print the results ...dats all !! hope it works!!


No comments:

Post a Comment