Question

C++ SECTION 1) (15 points) Write a full C++ program that reads an integer, a list of words, and a character. The integer sign
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the solution below. Added comments for better understanding of the program. Also attached screenshot of the program run.

C++ Source Code

#include <iostream>
#include <vector>

using namespace std;

int main() {

int i;
int numWords;
vector < string > inputWords;
char searchCharacter;
string userInput;
unsigned int j;

cin >> numWords;

// Take user input for list of words and store into the vector - inputWords
for (j = 0; j < numWords; j++) {
cin >> userInput;
inputWords.push_back(userInput);
}

// Take user input for character to be searched
cin >> searchCharacter;

// For each word in vector - inputWords, check if searchCharacter is present or not
for (j = 0; j < numWords; j++) {
// Check whether searchCharacter is present or found in inputWords[j] using string method - find()
if (inputWords[j].find(searchCharacter) != string::npos) {
cout << inputWords[j] << endl;
}
}

return 0;
}

Output

4 hello zoo sleep drizzle z zoo drizzle - - -- - - - Process exited after 17.01 seconds with return value o Press any key to

Add a comment
Know the answer?
Add Answer to:
C++ SECTION 1) (15 points) Write a full C++ program that reads an integer, a list...
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
  • 5.19 LAB: Contains the character Write a program that reads an integer, a list of words,...

    5.19 LAB: Contains the character Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list will always contain less than 20 words. Each word will always contain less than 10 characters...

  • Take the following C++ code and add to it the following: Write a program that reads...

    Take the following C++ code and add to it the following: Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count. #include<iostream> #include<string> using namespace std; int countVowel(char, char); int main(void) { string str1; int countA = 0; int countE = 0; int countI...

  • In C++ Please The given program reads a list of single-word first names and ages (ending...

    In C++ Please The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a string rather than an int. At FIXME in the code, add a try/catch statement to catch ios_base:: failure, and output o for the age. Ex: If the input is: Lee 18 Lua 21 Mary Beth 19 Stu 33...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • C++ program: can you help create a autocorrect code using the cpp code provided and the...

    C++ program: can you help create a autocorrect code using the cpp code provided and the words below using pairs, vectors and unordered map: Objectives To practice using C++ std::pair, std::vector, and std::unordered_map To tie together what we've learned into the context of a real-world application used by millions of people every day Instructions For Full Credit You're given a short list of words in known_words_short.txt that contains a handful of very different words. Assume this short list of words...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • Write a program that reads a list of integers ending with a negative, and that then...

    Write a program that reads a list of integers ending with a negative, and that then outputs that list in reverse. After the negative that ends the list, a character indicates what character should separate the output integers. If the input is: 3 5 2 - 1 * the output is: 2*5*3 LAB ACTIVITY 7.16.1: LAB: Reverse a list, with separating characters 2 / 10 main.cpp Load default template... 6 7 8 int numbers [100],i=0, num, size; char character; cin>>num;...

  • Consider the following C++ program. It reads a sequence of strings from the user and uses...

    Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...

  • Instructions: Consider the following C++ program. It reads a sequence of strings from the user and...

    Instructions: Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13...

  • Write a program that can remove spaces from an input string, find the indexes of a...

    Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character. Here is an example input: I am an input string a b The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and...

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
ADVERTISEMENT