The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
This is a hangman game that is supposed to pull words from a text file. There is a project file with the instructions. I have already commented out what each line should do in the cpp file
Week 4 Project – Hangman Game – 100 pointsDescriptonThe poin± of ±his projec± is ±o pu± ±oge±her several of ±he concep±s ±ha± we have been practcing.We will be implementng functons, random numbers, reading from and writng ±o Fles, looping,ge²ng inpu± from user and validatng ±ha± inpu±, displaying informaton ±o ±he user, using if/elseif s±a±emen±s, and becoming more familiar wi±h Visual S±udio.Hangman is a game where ±he user is presen±ed wi±h a word ±ha± has a speciFc number ofle³ers.The user can± see ±he le³ers and is asked ±o make guesses untl ei±her ±hey run ou± ofguesses or ±hey guess ±he word correc±ly.´or our projec± we will be implementng ±he basic concep±s of ±he game by presentng ±he userwi±h a word ±ha± con±ains all as±erisk, ±ell ±hem how many guesses ±hey have leµ, allow ±hem ±oen±er a guess, and if ±hey guessed a le³er ±ha± IS in ±he word, redisplay ±he word wi±h ±hecorrec± le³ers shown while all o±her will stll be as±erisk.Requiremen±s1)User will be presen±ed wi±h a Main Menu ±ha± will look like ±he following(making sure±ha± ±hey can only en±er ±he available optons, or ±he main menu jus± redisplays i±self)2)If user selec±s ±o play hangmana.Genera±e a random number be±ween 0 and 19b.Keep Reading ±he HangmanWords.±x± Fle untl you ge± ±o ±he n±h word(nrepresen±s ±he random number ±ha± was genera±ed)c.Display ±he game boardd.Ge± ±he users guesse.Valida±e ±he inpu± ±o make sure i± is a le³er(keep in mind i± should workregardless of upper or lower case le³ers)
televisioninternetcomputerrocketjupitersalmonapplausecognitivecollaboratecommissionembellishenhancementeventuallyfacilitatehereditaryinalienableinnovativemethodologyomnipotentperception
#include <iostream>#include <string>#include <cstdlib>#include <time.h>#include <fstream>#include <cctype>using namespace std;void runGame();string displayMainMenu();string readRandomWord();void displayGameBoard();void writeScoreToFile();void displayScoreToPlayer();int numGuessesLeft = 10;bool userWon = false;//flag to keep track of if player has wonstring userGuess;//variable to hold the users guessstring word;//variable to hold the random word that wasread from the filestring asteriskWord = "";//variable to hold asterisks for each letter ofthe original word and initializes it to an empty stringstring fileName = "";//filename that will be used to read the word fromthe file and initializes it to an empty stringstring menuSelection = "";//variable to hold the players choice on the mainmenu and initializes it to an empty stringint bestscore = 0;//variable to hold the players best score sofar (calculated by numGuessesLeft * lengthOfWord)int bestNumGuessesLeft;//variable to hold numOfGuesses for best score sofarstring bestscoreword;//variable to hold the word for the best score sofarstring input = ""//variable to hold main menu selection andinitializes it to an empty stringint main(){//kick off the gamereturn 0;}void runGame() {//get user selection from the main menu//keep looping until they press x or X//reset variables for start of a new gameasteriskWord = "";userWon = false;numGuessesLeft = 10;//get the random word from the file//fill in the asterisk word with all asteriks(hint:a loop might behelpful)//keep displaying game board in a loop until either they are out of
Attachments:
-----------