Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Finish the following hangman C++ program and make it run well as well as comment the program through to help me understand the code perfectly without unclear steps.

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

 

constint numwords = 34;

 

void DrawBody(int bodysize);

 

usingnamespacestd;

constint WORDSIZE = 6;

constint BODYSIZE = 6;

int main(int argc, constchar * argv[])

{

  ifstream wordlist;

wordlist.open("wordlist.txt");

  if (!wordlist)

{

cout << "couldn't find word list";

  return1;

}

  int whichword = rand()%(numwords)+1;

  string nextwordstring;

  string word;

  int dotlocation = nextwordstring.find(".");

  while(nextwordstring.substr(0,dotlocation) != "4")

{wordlist >> nextwordstring;

  int dotlocation=nextwordstring.find(".");

word = nextwordstring.substr(dotlocation+1);

}

  cout << word;

// string word = "tester";

  char wordA[WORDSIZE]= {'t','e','s','t','e','r'};

bool correctA[WORDSIZE] = {false, false, false, false, false, false};

  int bodyCount = 0;

  int numCorrect = 0;

  char userGuess;

  while ((bodyCount < BODYSIZE) && (numCorrect < WORDSIZE))

{

  cout << "letter: ";

  cin >> userGuess;

  bool foundone = false;

 

  for(int i=0; i

{

  if (userGuess == wordA[i])

{

correctA[i] = true;

foundone = true;

numCorrect++;

}

}

  if (not foundone)

bodyCount++;

  cout << "bodycount = " << bodyCount << endl;

  DrawBody(bodyCount);

  for(int i=0; i

  if (correctA[i])

  cout << wordA[i];

  else

  cout << "_";

  cout << endl;

}

  if (bodyCount >= BODYSIZE)

  cout << "you lose";

  else

  cout << "you win";

  return0;

}

 

void DrawBody(int bodysize)

{

  cout << "|-----|"<

  switch (bodysize){

  case1:

  cout <<"| O"<

  cout <<"| "<

  cout <<"| "<

  cout <<"| "<

  cout <<"| "<

  break;

  case2:

  cout <<"| O"<

  cout <<"| |"<

  cout <<"| "<

  cout <<"| "<

  cout <<"| "<

  case3: cout <<"|"; break;

  cout <<"| O"<

  cout <<"| /|"<

  cout <<"| "<

  cout <<"| "<

  cout <<"| "<

  break;

  case4:

cout <<"| O"<

  cout <<"| |"<

  cout <<"| /|\\"<

  cout <<"| "<

  cout <<"| "<

  break;

}

}

========

text file of words:

 

1.abduce

2.abduct

3.abjure

4.ablest

5.abound

6.absurd

7.abused

8.abuser

9.acetyl

10.acquit

11.acuity

12.aculei

13.acumen

14.acuter

15.adieux

16.adjoin

17.adjure

18.adjust

19.advent

20.adverb

21.advert

22.advice

23.advise

24.afield

25.agnize

26.agonic

27.aguish

28.akimbo

29.albino

30.albite

31.alcove

32.alexin

33.algoid

34.alined

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9887117

Have any Question?


Related Questions in Computer Engineering

The rate of inflation in year 1 is expected to be 14 year

The rate of inflation in year 1 is expected to be 1.4%, year two is 1.8%, and years three through five is expected to be 2%. Assume the real risk-free rate, r*, is 3% for all maturities. What should the yield to maturity ...

Restaurant management database project the restaurant

Restaurant Management Database Project : The restaurant maintains the catalog for the list of food and beverage items that it provides. Apart from providing food facility at their own premises, the restaurant takes order ...

Question suppose a large array is maintained with the

Question : Suppose a large array is maintained with the following policy. The array is initially sorted. When new elements are added, they are inserted at the end of the array and counted. Whenever the number of new elem ...

What is a survey and pros and cons of using this method to

What is a Survey and pros and cons of using this method to collect data are? Have you done a survey? How successful were your results?

Question write a minimum of 100 words for each question

Question: Write a minimum of 100 words for each question. Provide Citation and reference for each question. Provide two responses for each question. 1. Let us suppose we are designing a computer for use for a graphic art ...

Question standards and advantages and disadvantages of

Question: Standards and Advantages and Disadvantages of Standards" Please respond to the following: • From the e-Activity and the information provided by the IEEE 802.11 WLAN Working Group for Wireless Standards, assess ...

Link changes in unemployment inflation wages and gdp to one

Link changes in unemployment, inflation, wages, and GDP to one another and how they impacted each other during periods of economic decline (recessions) and periods of economic growth (expansion) over the past 10 years.

Question suppose we perform a sequence of n operations on a

Question : Suppose we perform a sequence of n operations on a data structure in which teh ith operation costs i 2 of i is an exact power of 2 and 1 otherwise. Use aggregrate analasys and accounting method to determine th ...

Scenario 1 19500 ascii characters are transmitted over a 3

Scenario 1: 19,500 ASCII characters are transmitted over a 3 Mbps circuit. The protocol uses 8-bits to encode each ASCII character, and adds an additional parity bit to help detect errors. Calculate the transmission effi ...

What are the differences between the federal deficit and

What are the differences between the Federal deficit and Federal Debt? How does a government budget deficit affect the economy, specifically the unemployment rate and job creation? Identify two periods in recent history ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As