Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN c++ I want to make word chain(Type a word to end it). If it does not match the word already entered, check it out.

IN c++

I want to make word chain(Type a word to end it). If it does not match the word already entered, check it out. Exclude duplicate words. If you type end, you end the input and in turn write the words you type

required position

:

1) Input by keyboard and output to monitor

2) Input words are stored in dynamic allocation according to their length.

3) Check well for overlapping words and ending words

4) Must be able to output all input words at the end

5) Maximum number of words that can be input is limited to 100

show like these :

Enter a word: apple

Enter a word: elephant

Enter a word: tiger

Enter a word: rabbit

Enter a word: tiger

#already used!

Enter a word: pineapple

#wrong word!

Enter a word: tomato

Enter a word: end

apple elephant tiger rabbit tomato

**becasue tiger finish R fineapple start F , as a result #wrong word

#include #include #include

using namespace std;

int main() {

//Creating a vector to store words. You can also use an array. vector vector1;

//Prompting user for input cout << "Enter a word: ";

//Declaring string and taking input from user to userInput string userInput; cin >> userInput;

//Declaring bool for condition (see In loop) bool isOkayToInsert;

//while user doesn't type end keep asking for input while (userInput != "end") {

//For now it's okay to insert element isOkayToInsert = true;

//Traversing vector to check for already used words and wrong inputs for (string s : vector1) {

//If word already exists if (userInput == s) { cout << "#already used!" << endl;

//Now it's not okay to insert the element isOkayToInsert = false;

//break from loop break; }

//If it's a wrong input if (userInput.find(s) != string::npos) { cout << "#wrong word!" << endl;

//Now it's not okay to insert the element isOkayToInsert = false;

//break from loop break; } }

//If it's okay to insert the element, then insert it. if (isOkayToInsert) { vector1.push_back(userInput); }

//Prompting for next input cout << "Enter a word: "; cin >> userInput; }

//Printing all words. for (string s : vector1) { cout << s << " "; } return 0; }

How do I fix it?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

Students also viewed these Databases questions