Question

//wrigte a program that read continuously word (string)from the user until string end the number (string)of word t the numb

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IN C++ !!

#include <iostream>

#include <string>

#include <vector>

using namespace std;

int main()

{

string userInput;

vector<string> words;

cout << endl << "Enter words (end to quit): " << endl;

do

{

cin >> userInput;

if(userInput.compare("end") == 0)

break;

else

{

words.push_back(userInput);

}

}while(userInput.compare("end") != 0);

// count the number of words that start with 'T' or 't'

int countT = 0;

for(int i = 0; i < words.size(); i++)

{

if(words[i][0] == 'T' || words[i][0] == 't')

countT++;

}

cout << endl << "Number of words starting with T/t = " << countT << endl;

// count the number of words that start with 'E' or 'e'

int countE = 0;

for(int i = 0; i < words.size(); i++)

{

if(words[i][0] == 'E' || words[i][0] == 'e')

countE++;

}

cout << endl << "Number of words starting with E/e = " << countE << endl;

// find the shortest word and the number of characters in it

vector<int> wordLength;

int index = 0;

for(int i = 0; i < words.size(); i++)

{

wordLength.push_back(words[i].length());

}

int min = wordLength[0];

for(int i = 0; i < wordLength.size(); i++)

{

if(wordLength[i] < min)

{

min = wordLength[i];

index = i;

}

}

cout << endl << "The shortest word is \"" << words[index] << "\" with " << min << " characters." << endl;

return 0;

}

******************************************************************** SCREENSHOT *******************************************************

Enter words (end to quit): clever stunning taller tower egg eggwhite Ego Am end Number of words starting with T/t 2 Number of

Add a comment
Know the answer?
Add Answer to:
//wrigte a program that read continuously word (string)from the user until string "end" the number (string)of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • Using Java write a program that takes a string input from the user and then outputs...

    Using Java write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word.

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99...

    Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99 is entered. Once the user has stopped entering numbers, display the number of numbers entered AND the sum of those numbers. You'll need a counter and an accumulator for this . Make sure your loop is structured Don't forget to comment your code. Don't forget to display appropriate prompts when requesting input from the user. Use a NAMED CONSTANT for the constant in this...

  • Write a program in C++ to read a large piece of text from the user (multiple...

    Write a program in C++ to read a large piece of text from the user (multiple lines) until the user inputs EOF. Assume the input only contains alphabets, numbers, commas and periods. The program should first compute the number of occurrences of each character in the input. Next, the program displays a sorted list (in descending order) of each character and the corresponding number of occurrences of that character. The sorting should be performed on the counts and not the...

  • Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99...

    Prepare pseudocode for a program that lets a user continuously enter numbers until the number 99 is entered. Once the user has stopped entering numbers, display the number of numbers entered AND the sum of those numbers. You'll need a counter and an accumulator for this (see pp. 179-181 and 205-208). Make sure your loop is structured (see priming input in figure 3-16). Don't forget to comment your code. Don't forget to display appropriate prompts when requesting input from the...

  • solve using the code provided Write a program that will continuously read words from the user,...

    solve using the code provided Write a program that will continuously read words from the user, word by word till the user enter "quit”, the program should print each word in reverse order. Sample Session: (User input in Red color) Enter a word: hello olleh Enter a word: Ahmad damhA Enter a word: quit Good Bye 9 dinclude <iostream> 10 dinclude <cstring> 11 using namespace std; 12 13 int main() { 14 15 char word(100); 16 cin>>word; 17 while (strcmp(word,...

  • Write a C program where user enter a string input, tokenizer the string using space character....

    Write a C program where user enter a string input, tokenizer the string using space character. Calculate the lengh of string. Find word start. Find word end. Count words.

  • Write a C program named space_to_line.c that features a while loop that continuously reads input from...

    Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...

  • C++. Use <iostream>, using namespace std; Please Allow a user to enter a set of one-word...

    C++. Use <iostream>, using namespace std; Please Allow a user to enter a set of one-word string and character pairs until they type "Done". For each pair, calculate how many of that character exists in that string and print out the resulting count. Write a user-defined function (not main) with two parameters. The first parameter is a one-word string, the second parameter is a character The function returns an integer specifying how many times that character is found in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT