Write a program that asks the user to input 5 Strings and st

Write a program that asks the user to input 5 Strings and store them in an ARRAY. Be sure to specify if they are to hit return or a space after each String.   Print out the array. Then remove all “short words” with a length less than or equal to 3 letters. Move up the remaining array elements to remove the gaps. Do not change the order of the elements. Fill unused portions at the end of the array with empty strings. Print out the new array. However, do not print out the unused portions.

The class Words should include:

-a constructor Words(construct default array )

-method inputArray (collects the 5 Strings from user and places into an array)

-method removeShortWords (removes the short words and adjusts the array (possibly by calling another method))

-method printArray (prints out the array)

-private instance field

The main class WordPrgm should:

-constructs a Words object

-Call the methods to remove the short words

-Print the arrays using the above methods

For example, if you are given the Strings:

“Mary”, “had”, “a”, “little”, “lamb”

The output would be:

The Original Array is: Mary had a little lamb

The New Array is: Mary little lamb

Solution

class wordprgm
{
string wds[5];
int len[5]=0;
public:
void inputarray();
void removeshortwds();
void printarray();
wordprgm()
{
cout<<\"the word program starts:\";
}

void inputarray()
{
int i;
cout<<enter the string :\"<<\"\ \"
for(i=1;i<=5;i++)
{
cin>>wds[i];
cout<<\"\ \";
}
}
void removeshortwds()
{
int i;

for(i=1;i<=5;i++)
{
while(wds[i]!=\'\\0\')
{
len[i]++;
}
}
}
void printarray()
{
int i;
for(i=1;i<=5;i++)
{
if(len[i]>3)
{
cout<<\"the remaining word :\"<<wds[i];
}

}
}
main()
{
wordprgm s1;
s1.inputarray();
s1.removeshortwds();
s1.printarray();
}

Write a program that asks the user to input 5 Strings and store them in an ARRAY. Be sure to specify if they are to hit return or a space after each String. Pri
Write a program that asks the user to input 5 Strings and store them in an ARRAY. Be sure to specify if they are to hit return or a space after each String. Pri

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site