How to understand the code perfectly without unclear steps

Assignment Help Basic Computer Science
Reference no: EM13307799

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

#include <stdio.h>

#include <time.h>

#include <string>

#include <fstream>

#include <iomanip>

#include <math.h>

#include <Ctime>

#include <iostream>

 

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<WORDSIZE; 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<WORDSIZE; 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 << "|-----|"<<endl;

  switch (bodysize){

  case1:

  cout <<"| O"<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  break;

  case2:

  cout <<"| O"<<endl;

  cout <<"| |"<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  case3: cout <<"|"; break;

  cout <<"| O"<<endl;

  cout <<"| /|"<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  break;

  case4:

cout <<"| O"<<endl;

  cout <<"| |"<<endl;

  cout <<"| /|\\"<<endl;

  cout <<"| "<<endl;

  cout <<"| "<<endl;

  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

 

Reference no: EM13307799

Questions Cloud

Will ibms plan to give away some of its it assets : Will IBM's plan to give away some of its IT assets and intellectual property and increase support of opensource software products like linux ,be a successful growth strategy in the "brutally competitive marketplace" in which it operates?why OR WHY..
How much heat must be supplied to the water : A pot containing1.00 liter of water, initially at 20.08C, is placed on a 1000 W electric heating element. How much heat must be supplied to the water to bring it to a boil
At the time what percentage of the principal has been paid : A company borrowes $25000 at an interest rate of a nominal 16% per year compounded quarterly. The company desires to repay the loan in 36 equal quartely payments, with the first payment starting three months from now.
What is the heat-flow rate along the rod : One end of an iron rod 40 cm long and 3.3 cm in diameter is in ice water, the other in boiling water. What is the heat-flow rate along the rod
How to understand the code perfectly without unclear steps : 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.
Calculate kg per day of sludge process if sludge is solid : The effluent contains 20 mg/L of solids and 20 mg/L of BOD the biological treatment process produced .32 kg of bacterial solids per kg of BOD removed
Types of contracts and performance-based acquisition : Types of Contracts and Performance-Based Acquisition
What will be the stars rotational period : A uniform, spherical cloud of interstellar gas has mass 2.0x10^30 kg, and radius 1.0x10^13 m and is initially rotating with a period of 1.4x10^6 yrs. what will be the star's rotational period
Calculate the f per m ration for the aeration tank : An activated sludge process receives 4000m^3 / day containing 120 mg BOD /L from the primary settling tank and 3500 m^3/day Containing 25mg BOD/L from the secondary settling tank.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Create a column of integers 1 through 30

In the next three columns show how each value is represented using the binary, octal, and hex number systems. Identify when and why each of the each three numbering systems is used ?

  How to deal with each type of known attack

Include Denial of Service attacks, Spoofing, Replays, TCP Session Hijacking, and Attacks on Encrypted Data (such as passwords).

  Write the function linecount

Write the function linecount that reads text files (.txt) and gives you number of lines in the file.

  Related to web services

A review paper usually should include multiple (about 5) references. I would like to see references from referred conference proceedings or journals.

  Procedure to charge lower rate for ongoing support services

Create complete, written procedure for New Century Health Clinic maintenance change requests. Include suitable forms with procedure.

  Experts suggest regarding search for information on internet

Which of the following do experts recommend regarding the search for information on the Internet? Avoid Boolean operators since new technology has made them obsolete.

  Make this code appear from right to left it is html code

Please make this code appear from right to left, it's HTML Code

  Transmitting station montiors bus during transmission

If each transmitting station montiors bus during transmission, how long before it notices the interference in seconds? In bit times?

  Write program that asks user how many students to process

Write a program that asks the user how many students to process (must be at least 1, but no more than 20) and then reads in the scores for three items, an exam average score (double number), lab average score (double number) and homework average s..

  Write overall approach when application developer needs data

Describe overall approach when application developer needs to show in form data from the database table

  Explain worst possible reports from system

Imagine worst possible reports from a system. What is wrong with them? Write as many problems as you can. What are the consequences of such reports?

  Write and explain briefly three guidelines for sound policy

Write and explain briefly three guidelines for sound policy, as stated by Bergeron and Bérubé. Are policies different from standards? In what way? Are policies different from procedures? In what way?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd