Question

on Programs> Prog 4: Twisted Hangman & Sylabus ule nte zza ckboard ss Notes al Reference ference [Corrected sample output and rubric still to come ..] Write a program to play hangman where the computer chooses the word and the human user tries to guess the word. The twist is that the computer starts out with a dictionary of many words. After each human guess, the computer eliminates all words containing the letters guessed so far, making the word as hard to find as possible. Correct user guesses only show up once the list has been narrowed down so far that all remaining words have the letter that the user guesses. [Inspired by the SIGCE Nifty Assignment by Keith Schwartz ] ud based g Out opics ams 1. Toothpicks og 2: Memory og 3: Newton og 4: Twisted ngman A, Tutoring b 2 For the version that you turn in include the debugging information as illustrated below so that we can verify your program is working correctly. A sample of running this program is shown below (though it was originally made with a different dictionary, so your numbers will likely be different) og starting with 53529 words. What length word do you want? s Now we have 3538 words of length 5 3 b 4 15. Letters used so far: L tters found:

media%2F45f%2F45f3c85a-d92d-47df-84ae-e2

media%2Fac1%2Fac1114e4-a13c-44f3-8416-fe


code block and c++ only please

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

#include <iostream>

#include <cstdlib>

#include<string.h>

#include <fstream>

using namespace std;

int contains(char a[],char b,int size){

int i;

for(i=0;i<size;i++){

if(a[i]==b)

return 1;

}

return -1;

}

int deleteFromDict(char *dict[],int num_of_words,int chosen_size,char a){

int new_count=num_of_words;

for(int i=0;i<num_of_words;i++){

if(dict[i]==NULL)

continue;

int j=0;

for(;j<chosen_size;j++){

if(dict[i][j]==a){

break;

}

}

if(j<chosen_size){

dict[i]=NULL;

new_count--;

}

}

return new_count;

}

void hangman() {

int chosen_size;

cout<<"enter size of word: ";

cin>>chosen_size;

cout<<"\n";

char *dict[chosen_size];

int count=0;

string line;

ifstream myfile ("dictionary.txt");

if (myfile.is_open())

{

while ( getline (myfile,line) )

{

strcpy(dict[count],line.c_str());

count++;

}

myfile.close();

}

int size=count;

char word[chosen_size];

strcpy(word,dict[rand()%size]);

int chance=1;

char input;

char guessed_wrong[15];

char guessed_correct[chosen_size];

for(int i=0;i<chosen_size;i++){

guessed_correct[i]='_';

}

int gc=0,gw=0;

int cur_count=size;

cout<<"We have "<<size<<" words of length "<<chosen_size;

while(chance<=15){

chance++;

cout<<"Letters used so far: ";

for(int i=0;i<gw;i++){

cout<<guessed_wrong[i];

}

cout<<"\n";

cout<<"Letters found: ";

for(int i=0;i<gw;i++){

cout<<guessed_correct[i];

}

cout<<"\n";

cout<<"Guess a letter";

cin>>input;

cout<<"\n";

int index=contains(word,input,chosen_size);

if(index>-1){

guessed_correct[index]=input;

gc++;

}else{

guessed_wrong[gw];

gw++;

}

cur_count=deleteFromDict(dict,size,chosen_size,input);

cout<<"Now we have "<<cur_count<<" words\n";

}

}

Add a comment
Know the answer?
Add Answer to:
code block and c++ only please on Programs> Prog 4: Twisted Hangman & Sylabus ule nte...
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
  • 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 DO IN JAVA You can use any source for the dictionary or just a few...

    PLEASE DO IN JAVA You can use any source for the dictionary or just a few words are fine! description The purpose of this assignment is to practice with ArrayLists (and hopefully, you'll have some fun). As far as the user knows, play is exactly as it would be for a normal game of hangman, but behind the scenes, the computer cheats by delaying settling on a mystery word for as long as possible, which forces the user to use...

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

  • Create the game hangman using c code: Program description In the game of hangman, one player...

    Create the game hangman using c code: Program description In the game of hangman, one player picks a word, and the other player has to try to guess what the word is by selecting one letter at a time. If they select a correct letter, all occurrences of the letter are shown. If no letter shows up, they use up one of their turns. The player is allowed to use no more than 10 incorrect turns to guess what the...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

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

  • This is for C programming: You will be given files in the following format: n word1...

    This is for C programming: You will be given files in the following format: n word1 word2 word3 word4 The first line of the file will be a single integer value n. The integer n will denote the number of words contained within the file. Use this number to initialize an array. Each word will then appear on the next n lines. You can assume that no word is longer than 30 characters. The game will use these words as...

  • I need help doing all these questions (1-6) ASAP. Keep in mind we are only on...

    I need help doing all these questions (1-6) ASAP. Keep in mind we are only on chapter 5 of "Building Java Programs" so too advanced code cannot be used. Please use the appropriate code coved in the chapter and the chapters before. Thank you.? Preview File Edit View Go Tools Window Help O 2.15 GB 00% Sun Nov 27 4:01:43 PM Q e E Ch.5 Problem Set.pdf e 2 of 2) a Search Ch.5 Problem Set.pdf l. te an interactive...

  • SCREENSHOTS OF CODE ONLY!! PLEASE DON'T POST TEXT!! C++ CODE! PLEASE DON'T REPOST OLD POSTS! Objective...

    SCREENSHOTS OF CODE ONLY!! PLEASE DON'T POST TEXT!! C++ CODE! PLEASE DON'T REPOST OLD POSTS! Objective To gain experience with the operations involving binary search trees. This data structure as linked list uses dynamic memory allocation to grow as the size of the data set grows. Unlike linked lists, a binary search tree is very fast to insert, delete and search. Project Description When an author produce an index for his or her book, the first step in this process...

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