Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Thisc c++ assignment gives you some practice using structs and gets you started on our final project (the Hangman game). For your hangman game, you

Thisc c++ assignment gives you some practice using structs and gets you started on our final project (the Hangman game). For your hangman game, you will need some phrases for the user to guess. In this assignment, you will read in these phrases from a file, sort them, and output them to make sure they are correct.

Create a struct called Phrase that has three members:

A string called text that will store the text of a phrase.

A member of type string::size_type named guessesRequired that will contain the minimum number of guesses required.

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. Hints: 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. The guessesRequired member should be set to the value returned by uniqueLetterCount and the isUsed member should be initialized to false. The function should take the file name, the array of Phrases, and a reference to the array length as parameters. The function should read in phrases from the file up to the end of the file or the array size (whichever comes first). If all the phrases are read into the file and there are still uninitialized phrases, the array size variable should be updated to be the total number of phrases.

sortPhrases: Uses selection sort to sort the array of Phrases by their guessesRequired. See pages 545 to 549 of your textbook for the algorithm and some code to get you started. The function should include the array length as a parameter and only sort values within the bounds of the array length.

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 formatted into columns that align between rows (the formatting is similar to the last assignment).

Your 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

1. How is the newspaper help to our daily life?

Answered: 1 week ago

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago