Part 1: Loading and processing phrases For your hangman game, you will need some phrases for the…

Part 1: Loading and processing phrases

For your hangman game, you will need some phrases for the user to guess. The first step is to load the phrases from a file, initialize the attributes of each phrase, and sort them by difficulty. To verify that this part is working, you will temporary display all of the phrases.

Create a struct called Phrase that has three members:

  1. A string called text that will store the text of a phrase.
  2. An unsigned int named guessesRequired that will contain the minimum number of guesses required. Note that this member can never be negative.
  3. A bool named isUsed that will be set from false to true if and when a phrase is used.

Create the following functions:

  • uniqueLetterCount: Accepts a constant reference to a string and returns the number of unique letters in that string. Only letters (‘A’ through ‘Z’ and ‘a’ through ‘z’) count as letters. The function is case insensitive which means that ‘A’ and ‘a’ only count as one unique letter. For example, the phrase, "A wolf in sheep's clothing" contains 14 unique letters. This function will be used to determine the correct guesses required to get the phrase.
    Hints: One approach would be to use a string to store the unique lowercase letters you find. Use string‘s find function to see if a character from the input string exists in the unique letters string. After finding all the unique letters, return the length of the unique letters string.
  • loadPhrasesFromFile: Reads in a file where each line is the text of a phrase. Initializes an array of Phrases. This function accepts (1) the filename as a const string reference, (2) an array of Phrases, and (3) the array length. The function should return the number of Phrases read from the file. The guessesRequired member should be set to the value returned by uniqueLetterCount and the isUsed member should be initialized to false. The function should read in phrases from the file up to the end of the file or the array size (whichever comes first). Then, return the number of phrases read from the file.
  • sortPhrases: Uses the Selection Sort algorithm to sort the array of Phrases by their guessesRequired. See the Chapter 8 lecture notes/videos (or pages 545 – 549 of your textbook) for the algorithm and some code to get you started. The function should include the array length as the second parameter and only sort values within the bounds of the array length. You may create additional functions for finding the max index and swapping Phrases split this problem into subproblems.
  • printPhrases: Outputs to the screen an array of phrases. The output should be formatted such that there is one Phrase per line, with the following order for phrase members: (1) guessesRequired, (2) text, and (3) isUsed. isUsed should be output as a human readable string of either "used" or "unused." The output should be in an aligned table format that matches this sample output:
    Sample Output # Phrase State 13 A bird in the hand is worth two in the bush. unused 9 A broken heart unused 8 A cross to bear unused 14 A drop in the bucket unused 11 A fly in the ointment unused 8 A graven image unused 15 A house divided against itself cannot stand. unused 8 A labor of love unused 14 A leopard cannot change its spots unused 12 A man after his own heart unused 12 A multitude of sins unused 11 A nest of vipers unused 11 A sign of the times unused 14 A wolf in sheep’s clothings unused 11 A thorn in the flesh unused 11 All things must pass unused 11 All things to all men unused 13 Am I my brother’s keeper? unused 9 An eye for an eye, a tooth for a tooth unused 10 As old as Methuselah unused 9 As old as the hills unused 9 As white as snow unused 11 You reap what you sow. unused 8 Ashes to ashes dust to dust unused 9 At his wits end unused 11 Baptism of fire unused 14 Be fruitful and multiply. unused 14 Beat swords into plowshares. unused 8 Bite the dust unused 13 Blessed are the peacemakers. unused 7 Born again unused 10 Breath of life unused 13 By the skin of your teeth unused 14 Can a leopard change its spots? unused 14 Cast bread upon the waters. unused 11 Cast the first stone. unused 14 Charity begins at home. unused 11 Coat of many colors unused 17 Don’t cast your pearls before swine. unused 5 Dust to dust unused 11 Eat drink and be merry. unused 4 Eye to eye unused 12 Faith that moves mountains unused 9 Fall from grace unused 8 Fight the good fight. unused 12 Fire and brimstone unused 10 Flesh and blood unused 13 For everything there is a season unused 16 Forgive them for they know not what they do unused 10 Gird your loins. unused 11 Go the extra mile. unused 8 Heart’s desire unused 10 Holier than thou unused 13 In the beginning was the word. unused 13 In the twinkling of an eye unused 13 It’s better to give than to receive unused 9 Labour of love unused 12 Lamb to the slaughter unused 6 Land of Nod unused 14 Let he who is without sin cast the first stone. unused 12 To everything there is a season. unused 13 Jumping Jehosaphat! unused

Test your code: The main function should use these functions to do the following in order: (1) read in the file, (2) output the phrases to the screen, (3) sort the phrases, and (4) output the phrases again now that they are sorted. For the actual game, you will not print the phrases, but you should do this temporary to make sure everything is working. After removing the calls to printPhrases, keep this function defined in your code so you can use it for debugging as needed in the future.

Part 2: Print out the phrase with an underscore for each unguessed letter.

Create a function named phraseWithBlanks that accepts a constant reference to the text from a phrase and a constant reference to a string of correctly-guessed lowercase letters. The function will return a string representing the phrase where every unguessed letter is represented by an underscore character and each character is separated by a space. Non-letter characters should be output as is. For example, if the phrase text is "It's time to eat!" and the correctly guessed string is "io", then the function should return "I _ ' _ _ i _ _ _ o _ _ _ !".

Hint 1: You may find that the tolower function is helpful, which can be used if you include the cctype. Also, it may be helpful to create an isLetter function that returns true if a single character is a letter (or use isalpha from cctype).

Hint 2: Use string‘s find function to see if a character in the phrase-text string exists in the correctly-guessed letters string.

Part 3: Select a random phrase based on the difficulty level

Create a function named getDifficultyLevel that displays three difficulty levels: (1) Easy, (2) Medium, and (3) Hard. The function should ask the user to enter a number for the difficulty level they wish to play at. The function should then validate the user input, making sure that it is an integer between 1 and 3 inclusive. If it is not, the function should prompt the user for input again until the input number is valid. When a valid input is entered, the function should return the requested difficulty level minus 1 (e.g., if the user inputs 1, return 0).

Use the following example output for how the prompts should be formatted.

Sample Output (user input is in yellow)Difficulty levels: 1 Easy 2 Medium 3 Hard Pick a difficulty level (1 to 3): 4 Please choose a difficulty level between 1 and 3: four again Please choose a difficulty level between 1 and 3: 2

Optional Extension: Instead of using an int type for difficulty, you could create new enum type called DifficultyLevel with the values EASY, MEDIUM, HARD, and INVALID_DIFFICULTY. Have getDifficultyLevel return a value from this enum.

Create another function, named randomPhraseIndex that accepts three parameters: (1) the difficulty level, (2) a const array of Phrases, and (3) the length of the array (i.e., the phrase count). The function should produce a random number that will be the index of the next Phrase to be guessed. If the difficulty level is EASY (0), the random number should fall within the first third of the indices of initialized Phrases in your sorted Phrase array. Likewise, if the difficulty level is MEDIUM (1), the number should fall in the second third of valid indices. The HARD difficulty level should include the last third of the phrases and any phrases that do not divide evenly into 3 groups. (See the posted video on random numbers for information about how to do this step.)

Create a loop in randomPhraseIndex that checks if the Phrase at the random index is unused (isUsed == false). Keep generating new random indices until the index points to an unused Phrase. When the loop ends, return the random index of the unused phrase.

In the main function, seed the random number generator and call these two functions. Do NOT seed the random number generator in another function; we wan’t to make sure we only set the seed once and other function may be called multiple times. Add some temporary code to main to make sure everything is working correctly.

Part 4: The game loop

This step is where everything comes together into a playable game. Create a function called runGame that accepts a reference to a Phrase. Create a do...while loop that continues while the number of incorrect guesses is less than 5 and the number of correct guesses is less than the Phrase‘s guessesRequired. In that loop first call the drawGallows function (see starter code), then print the phrase with blanks, then prompt the user to enter a guess. After getting the user’s input, output 20 newlines to “clear” the screen. Then, consider the following conditions based on the guess:

  1. If the guess is not a letter, output an error message. For example, "'!' is not a valid guess. Please enter a letter."
  2. Otherwise, if the guess has already been guessed, output an error message in the following format: "You have already guessed an 'e'."
  3. Otherwise, if the guess is in the phrase, output “Good guess” and store the guess in a sting of correct guesses.
  4. Otherwise, output the message, “Sorry, bad guess.” and add the guess in a string of incorrect guesses.

After the loop, draw the gallows one more time and the phrase (with blanks as needed). Depending on the number of incorrect guesses, output either "You Win!" or "You're Dead! The phrase was:" followed by the phrase.

Call this function from main and make sure everything is working correctly.

Hint: It may be helpful to store the current phrase’s text as an all-lowercase string to be used in comparisons. You may want to create a function named toLowerCase that accepts a constant reference to a string and returns that string, but with all lowercase letters.

Part 5: Allow the user to play multiple times per run.

Add a do...while loop to your main function that includes the necessary code to:

  1. Select a phrase at random based on the chosen difficulty level
  2. Run the game with the current phrase.
  3. Mark the current phrase as used and maintain a count of the number of phrases asked.
  4. If there are more phrases to be guessed at that difficulty level, ask the user if he/she would like to play again with this prompt, "Would you like to play again? (y/n): "

The loop should continue while there are more phrases to be guessed and the user inputs a ‘y’ to play again.

Test your code to make sure it works like the demo video. You have created your own commandline game!

ACTIONSSubmit ProjectThe due date for this project has passed. Your instructors can give you an extension if they see fit.

 

"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

Write a two to three (2-3) page paper in which you: 1. Identify and discuss the three (3) levels of

Write a two to three (2-3) page paper in which you:
1. Identify and discuss the three (3) levels of Kohlbergs stages of Moral Development, and explain how you would address each level within your department.
2. Explain how your officers can use Kohlbergs Stages of Moral Development to evaluate three (3) types of criminals who are at different stages of moral development.
3. Illustrate two to three (2-3) ways in which you would address self-interest and pursuit of pleasure to prevent police corruption.
4. Identify and discuss at least three (3) Prima Facie Duties that you believe all of your law enforcement officers should fulfill.
5. Support your position statement with two (2) relevant and credible references, documented according to latest edition of APA. (Note: Do not use open source sites such as Ask.com, eHow.com, Answers.com, and Wikipedia.)

Your assignment must follow these formatting requirements:
Be typed, double spaced, using Times New Roman font (size 12), with one-inch margins on all sides; citations and references must follow APA format (latest edition). Check with your professor for any additional instructions.
Include a cover page developed in accordance with the latest edition of APA, including a running head, page number, the title of the assignment, the students name, the professors name, the course title, and the date. The cover page, revision of the previous assignment, and the reference page are not included in the required assignment page length.

The specific course learning outcomes associated with this assignment are:
Recommend ways to use ethics to improve decision making in the criminal justice system.
Analyze various philosophical approaches for ethical decision making, and the effectiveness and limits of each approach for making ethical choices.
Analyze basic questions about morality, norms, and values.
Examine the concepts and effectiveness of reward and punishment.
Explain why and how the concept of justice is important to the field of criminal justice.
Explain Kohlbergs moral development stages and how they can be applied to issues in criminal justice.
Use technology and information resources to research issues in ethics and leadership in criminal justice.
Write clearly and concisely about ethics and leadership in criminal justice using proper writing mechanics.

 

"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

What are the four types of social responsibilities that businesses have? From a historical perspecti

What are the four types of social responsibilities that businesses have? From a historical perspective, where have businesses failed with these in the past?

Discuss the ethical pros and cons of doing business with a sweatshop in a developing nation. Use key terms from our text to support your thoughts.

 

Also summarize either one of the following sites as it pertains to the weekly text

 

http://www.nbcnews.com/feature/season-of-kindness/best-way-give-money-charity-holiday-season-n462946  or 

 

http://www.reuters.com/article/2015/11/15/us-france-shooting-oil-idUSKCN0T40QE20151115?feedType=RSS&feedName=businessNews#ruapMOSjkv3tUcMU.97

 

Minimum of 300 words in APA format with credible references

    • Posted: 4 years ago
    • Due: 17/11/2015
    • Budget: $10
     

    "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

    Using diagraming software such as Visio or some other software, model the feedback loop used for… 1 answer below »

    Week 1 Assignment: Create a Diagram of a Basic Web Mining Model Instructions

    Using diagraming software such as Visio or some other software, model the feedback loop used for web data mining. You can download many different options of feedback loops by doing an Internet search for tools or use your word processing tool explain what this means

    In your model, you need to:

    • Include users, websites, queries, and data warehouses.
    • Illustrate how the mining is used to improve search results in a search engine.
    • Write a paragraph summary detailing the process and how it improves the results.

    Length: 3-4 pages, not including title and reference pages.

    References: Please include one or two scholarly sources.

    Your model should demonstrate thoughtful consideration of the ideas and concepts presented in the course by providing new thoughts and insights relating directly to this topic. Your response should reflect scholarly writing and current APA standards. Be sure to adhere to Northcentral University’s Academic Integrity Policy.

     

    "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

    Create a gui form named TheArea, that allows the user to enter the length, width, or radius and then

    Create a gui form named TheArea, that allows the user to enter the length, width, or radius and then displays the area of the selected shape as follows: a. A brief explanation of what the user should do. b. the user will enter the length and width or radius via separate textboxes (three separate textboxes). c. Use a radio button that allows them to select a shape to calculate 1. rectangle, 2.Circle 3. Square. Create three area calculating methods: 1. rectangle-using to double 'value' input parameters (L & W) on double 'ref' parameter to return to the double Area. 2. circle-use on double 'value' input parameter (R), one double 'out' parameter that contains the Area. 3. square-use one double 'value' input parameters (L), use the Method's return to return the double Area. Using a switch statement, determine which area is to be calculated and call the appropriate method from within the switch statement. Include a button, labeled The Area to initiate the area calculation and displays the shape selected and its' area. Include a try catch block within your buttons code that catches non numeric input and displays a message to the user. Include a Clear All button that clears all and an Exit Button

     

     

     

    "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

    A startup company plans to develop an app which allows users to keep records of their invoice… 1 answer below »

    A startup company plans to develop an app which allows users to keep records of their invoices of purchases. The requirements for the app are listed as follows: 1. When a user opens the app, the main user interface appears, which includes the following items: a. A list of invoices is shown. For each invoice item, its “title”, “date”, and “shop name” are displayed. b. A toolbar with two entries: “New”, “Help”. 2. When the user clicks the menu item “New” in the main UI, a new UI appears to allow the user to log a new invoice. The following items should be displayed:

    Attachments:

     

    "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

    Suppose that you own two farms on which to grow corn. in order to lower the cost of production, you

    Suppose that you own two farms on which to grow corn. in order to lower the cost of production, you determine to increase production on farm 1 and reduce it on farm 2. this implies that the marginal cost of production on farm 1 is:

     

    "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

    Write a 2 page paper that discusses the strategic, psychological, and propaganda impact of terrorist

    Write a 2 page paper that discusses the strategic, psychological,  and propaganda impact of terrorist weapons such as snipers, Improvised Explosive Devices (IEDs), Explosively Formed Penetrators (EFPs), and suicide bombers. 

     

    Can you complete this in less than 5 hours? If so bid. APA, no plag.

      • Posted: 4 years ago
      • Due: 24/01/2016
      • Budget: $8
       

      "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"

      You need to discuss and justify the partnership deductions (both those you included and excluded)… 1 answer below »

      1. You need to discuss and justify the partnership deductions (both those you included and excluded) and then the capital gains for one of the partners. This will be in the written section (body) of your report. You do not need to discuss other income or the tax calculation components. You should use headings and sub-headings to indicate what you are discussing, e.g. “Partnership Deductions”, “Non-deductible Items”, “Capital Gains” etc. You should also refer to the section of the appendices that contains the calculations for the items you are discussing. No calculations should appear in the body of the report.

      2. You need to calculate the s 90 net income and s 92 distribution for the partnership. You should also calculate the tax payable or refund amount for Carl Crabapple only. Note that Carl has also had capital gains events as an individual taxpayer outside of the partnership. All calculations will be in your appendices. You should set out your calculations neatly and label them clearly.

      You MUST support your discussion with an explanation of the relevant law and with section numbers, case law and rulings where appropriate. Referencing lecture slides, paragraphs in the Principles of Taxation or the ATO website in general (as opposed to legislation, cases or rulings) will NOT achieve any marks. This is a tax law assignment, you should NOT reference academic journal articles

      Attachments:

       

      "Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"