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

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

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

  • I need help building a program on microsoft visual studio using c++ language. implement a program...

    I need help building a program on microsoft visual studio using c++ language. implement a program called "charword_freq.cpp" to determine the number of words and the number of occurrences of each letter in a block of text stored in a data file called “mytext.dat”. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma, or the beginning or end of a line. You can assume that the input...

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

  • I really need help on this programming problem that am doing in Visual Studio 2019 in...

    I really need help on this programming problem that am doing in Visual Studio 2019 in C++ Submit your .cpp file as well as the input file, the output file, and the screen shot of all the files tiled next to each other here! Instructions: Write a menu driven program that has three options: Option 1: Write a function that calculates the tax for an iphone. The price and the tax rate should be asked from the user. Input validation:...

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

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