Question

Use C++ Word Finder Version Your version of word finder should allow players to find as...

Use C++

Word Finder Version

Your version of word finder should allow players to find as many words as they can from the list of letters. Name the cpp file called wordFinder_LastNameFirstName.cpp

  • Words must contain at least 3 letters but no more than 6 letters.

  • The program must first read the words from a file but only can read in at most 5 words from a text file. The program should skip words that contain less than 3 letters and more than 6 letters.

  • The program should print all the letters to the screen but remove any duplicate letters.

  • Based on the letters shown, the user should try and guess the words that were read from the text file based on the letters shown. The user is not allowed more than 10 guesses.

  • Once all the words are guessed correctly, print all the words to the screen and the game is over.

    Requirements:

  • Must have a loop.

  • Must have some functions.

  • Must read information from a text file.

  • Must contain string Array to store the correct guessed words

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

#include<iostream>

#include<string>

#include<fstream>

using namespace std;

string write(string str);

bool isPresent(string s[], int n,string g);

int main()

{

//declare array of strings of size 5 to hold 5 words

string words[5];

string letters="",str;

//declare ifstream object to read from file

ifstream in;

//open file

in.open("input.txt");

//check if file open

if (!in)

{

cout << "Not able to open input.txt file" << endl;

return - 1;

}

int i=0;

while (!in.eof())

{

//read each word and check if it's length greater than 3 and less than 6

in >> str;

if (str.length() >= 3 && str.length() <= 6)

{

words[i] = str;

if(i == 0)

letters+=words[i++];

else

{

letters += " ";

letters+= words[i++];

}

}

//otherwise ignore that word

if (i < 5)

{

continue;

}

else

break;

}

//remove duplicates

str.clear();

str=write(letters);

cout << "Words Finder 1.0 " << endl;

cout << "5 words were read from the file" << endl;

cout << "Below are the letters to create words from: " << endl;

cout << endl<<endl<<str << endl;

string guess;

int count = 0,correct=0;

do

{

cout << "Please start guessing: ";

cin >> guess;

if (isPresent(words, 5, guess) == true)

{

cout << guess << "<- In File" << endl;

++correct;

}

else

{

cout << guess << "<- Not In File" << endl;

}

if (correct == 5)

{

break;

}

++count;

} while (count < 10);

if (correct < 5)

{

cout << "You did not guess all words\n";

}

cout << "Below are the words that were found: "<<endl;

for(int i = 0; i < 5;i++)

cout << words[i]<<" ";

cout << endl << "Game Over!!!" << endl;

system("pause");

}

string write(string str)

{

string st1 = "";

for (int i = 0; i<str.length(); i++)

{

int j;

for (j = 0; j<i; j++)

if (str[i] == str[j])

break;

if (j == i)

{

if(str[i]!=32)

st1 += str[i];

}

}

return st1;

}

bool isPresent(string s[], int n,string g)

{

for (int i = 0; i < n; i++)

{

if (s[i] == g)

return true;

}

return false;

}

-----------------------------------------------

//output

Words Finder 1.0
5 words were read from the file
Below are the letters to create words from:


dogjumpcatfishwr
Please start guessing: dog
dog<- In File
Please start guessing: dig
dig<- Not In File
Please start guessing: jump
jump<- In File
Please start guessing: cat
cat<- In File
Please start guessing: wish
wish<- Not In File
Please start guessing: fish
fish<- In File
Please start guessing: word
word<- Not In File
Please start guessing: words
words<- In File
Below are the words that were found:
dog jump cat fish words
Game Over!!!
Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
Use C++ Word Finder Version Your version of word finder should allow players to find as...
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
  • Use C++ and Visual Studio Word Finder Version Your version of word finder should allow players...

    Use C++ and Visual Studio Word Finder Version Your version of word finder should allow players to find as many words as they can from the list of letters. Name the cpp file called wordFinder LastNameFirstName.cpp. Words must contain at least 3 letters but no more than 6 letters The program must first read the words from a file but only can read in at most 5 words from a text file. The program should skip words that contains less...

  • With basic (do not use #include <algorithm>, etc.) and simple C++ Write a program which reads...

    With basic (do not use #include <algorithm>, etc.) and simple C++ Write a program which reads a text file “input.txt” and stores all the distinct words in an array. A word consists of letters only - uppercase and/or lowercase. An incoming word should be inserted into the array such that it is always in ascending order. Use binary search to ensure that no duplicate words are added. Assume that there are no more than 100 distinct words. Assume that the...

  • Hangman is a game for two or more players. One player thinks of a word, phrase...

    Hangman is a game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers, within a certain number of guesses. You have to implement this game for Single Player, Where Computer (Your Program) will display a word with all characters hidden, which the player needed to be guessed. You have to maintain a dictionary of Words. One word will be selected by your program....

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

  • ​ TEXT FILE IS ALREADY GIVEN, JUST NEED TO READ IN THE PROGRAM. Learning objectives: The...

    ​ TEXT FILE IS ALREADY GIVEN, JUST NEED TO READ IN THE PROGRAM. Learning objectives: The intent of this programing project is to allow you the opportunity to demonstrate your ability to solve problems using procedural C++ programming. This project HANG MAN will focus on file I/O and string manipulation in the implementation of the game Hangman. Program Description: In this project, you will write a C++ program that simulates playing the game Hangman. This version of the game will...

  • Help c++ Description: This program is part 1 of a larger program. Eventually, it will be...

    Help c++ Description: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This will help you prepare for next week Print the final messages of...

  • Help please, write code in c++. The assignment is about making a hangman game. Instructions: This...

    Help please, write code in c++. The assignment is about making a hangman game. Instructions: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This...

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