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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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