Question: C++ Exercise 4: #include //including the proper header files #include #include using namespace std; // using name space std , so that , no need
C++

Exercise 4:
#include
#include
#include
using namespace std; // using name space std , so that , no need to write std :: everytime
// main function
int main()
{
vector
// where each element is pointer to string of vectors
// explanation :pointer of vector of strings will be reprensented as
// vector
// now here we need to allocate the memory to each pointer i.e . vector of strings using new keyword , which is used to dynamically allocate the memory
for (int i = 0; i
{
V[i] = new vector
}
string input; // this variable stores input
// looping till we get "quit" as input
while (true)
{
cin >> input; // taking the input
if (input == "quit") // if the input == "quit" , simply breaking out of loop
break;
int length = input.length(); // now checking the length of given string , so as to place in that length bucket
if ( length ==0 )continue; // if the length of string is 0 . i.e empty string just skip it
bool found = false; //initialing the found variable as false
// now iterating over that length bucket and cheking each string of that length bucket , if it is same as of input string or not
for (int i = 0; i
{
if (input ==( *V[length - 1])[i]) // if input string is found somewhere in that length bucket then simply make found =true and break
{
found = true;
break;
}
}
// if found variable is false then push back the input string else not
if (found == false)
V[length - 1]->push_back(input);
}
cout
// now printing the strings in the order of length ( and if the length is same they are printed in same order as of input )
for (int i = 0; i
{
for (int j = 0; j
{
cout
}
}
}
Example 1: Input: A Box Cube to happy hello computer mouse happiness quit
Output: 1 1 2 1 3 1 4 1 15 3 8 1 9 1
Example 2: Input: A A A B B B AB quit
Output: 2 2 2 1
(20 points) Extend the program in exercise 4 in the following way: after all input strings are read, you will output for each non-empty entry of V the number of letters in that entry and the number of strings in that entry. Input: Same as question 4 Output: 123415891111311
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
