Question

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 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 that 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 contains 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++ and Visual Studio Word Finder Version Your version of word finder should allow players...
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++ 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...

  • 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...

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

  • 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...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • ​ 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...

  • Python 3.7 Coding assignment This Program should first tell users that this is a word analysis...

    Python 3.7 Coding assignment This Program should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file....

  • Note wordBank, an array of 10 strings (char *s). Your program should do the following: 1....

    Note wordBank, an array of 10 strings (char *s). Your program should do the following: 1. Select a word at random from the wordBank. This is done for you. 2. On each turn display the word, with letters not yet guessed showing as *'s, and letters that have been guessed showing in their correct location 3. The user should have 10 attempts (?lives?). Each unsuccessful guess costs one attempt. Successful guesses do NOT count as a turn. 4. You must...

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