Create a class Hangman with the following private attributes: o Words: should be a static string array with 10 elements. o Word Name: should be a string attribute. o Chosen Letters: should be a pointer to a Boolean attribute. o Letter: should be a character attribute. o Number of Mistakes: should be an integer attribute. o Word Length: should be an integer attribute. The class Hangman should contain the following behaviors: o Constructor with no parameters: o Declare and initialize a random number between 0 and 9. o Assign Word Length to the length of a text inside Words based on the generated random number (Use the length function from the string class). o Dynamically allocate Chosen Letters based on the Word Length. o Assign Word Name to the chosen random text from Words. o Set the Number of Mistakes to 0 and initialize the array Chosen Letters to false. o Destructor: o Dynamically de-allocate Chosen Letters. o Constant get function for Number of Mistakes. o Check Value function: o The function should not take any parameters. o If the value of Letter found within the array Word Name, set the same element index of Chosen Letters to true and return true; otherwise return false. o Is Word Complete constant function: o The function should not take any parameters. o The function must return false if one element inside Chosen Letters is equal to false; otherwise return true. o Overloaded operators (<<, >>, ++): o operator<< must output the correct letters on screen; otherwise print an underscore “_”. o operator>> must input the letter chosen by the user into the attribute Letter. o operator++ (prefix) must increment the value of Number of Mistakes. A header file and source file must be created for the Hangman class. Another source file must be created for the main function: o Create a dynamic Hangman object. o Allow the user to have at most 6 mistakes before he loses the game. o The user must input a letter through the object. o Check if the letter is found within the word. o Print the word on the screen through the object. o If the user recognizes the whole word, print the text “Congratulations! You won the game.” otherwise print “Sorry! You lost the game.” o Ask the user if he wants to play again by choosing either the character Y for yes or the character N for no. o De-allocate the object at the end of the program. o Clear the text on the screen using the following line: system(“cls”); |
i completed most of it; my problem is in main() |
|
|
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code. It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/ http://www.cplusplus.com/articles/z13hAqkS/ Hint: You can edit your post, highlight your code and press the <> formatting button. You can use the preview button at the bottom to see how it looks. I found the second link to be the most help. |
int main()
not void main()
as "main" will return an "int" whether you tell it to or not.
|
|
|
|