Question
(4) Save an empty file called word guess.cpp (source code) in your directory. Add the following statements to this file: #include suppose to accomplish. (1)
(4) Save an empty file called word guess.cpp (source code) in your directory. Add the following statements to this file: #include
suppose to accomplish. (1) Complete each function and test it thoroughly before moving onto the next one. Programming Tips You can start anywhere you like. Note that in this assignment, you are encouraged to create one or more functions that are helpful. These do not need to be included in the hpp file. However, they must be documented: what they do, what input is required and what is returned. When a programmer builds functions that are not included in the hop file, it is assumed that only the programmer will be using them, so rigid error-checking is not required Some new topics that you have not seen before Computer programming languages often contain a random number generator that will produce pseudo random numbers."A onetime to call start the generator provides a seed number and then recurrent calls to produce the next number result in a set of numbers that appears random. It only appears so,
because if the programmer re-seeds the generator with the same value, then the exact same sequence of numbers will be generated again. Because the user gains an advantage over the computer if the same seed is use in several games, it is best to use a different seed each time. One often used seed value is the internal clock on the computer. To set that up for this game, add the following two statements inside the main function: int main() { time. t seed; srand (seed); ) Note that the #include statement allows us to use the time_t data type. Once the generator is seeded, then all subsequent calls to rand() will produce a pseudo random integer. More information on how to create a random integer follows in the function details section The functions The functions that are mentioned in the hop file are required. The comments are used to generate the html documentation file that accompanies this assignment package.
The following subsections describe some of the how-to implement information to you, the programmer. contains This function determines whether a given character is contained within a string. Note that to access and update the individual characters within a string object, we can use square brackets. The example code on the next page demonstrates how to access infor- mation about a string object. The length of a string is determined using the length() or equivalently size() methods, (functions that act on a particular object). Each letter in the string is accessible by its index position (starting at 0, as usual). *Random generators are never random. They are carefully crafted equations that when provided with a seed (a starting input), will repeatedly generate numbers within a range. Ideally, every number generated has an equal probability count_free_spaces This is a similar function that will access the individual characters within a string. This function counts the number of occurrences of the character'. inside the string and re- turns that value. insert_letter This function requires an interaction with the user.
Note that in the parameter list, there is an ampersand [&] between string and word. This means that word is pass-by-reference, and any changes made to word will live outside the scope of this function. The purpose is to replace one or more of the characters in the string object with the given char value and the user's input as to where it needs to be placed. See the example below where the program moves an 'X' into an empty position so the user can verify whether it is a correct insert position for the given letter. Note the following: . this function assumes that the letter will be inserted into the word, the letter may be inserted into more than one position, and the function updates the actual input parameter and prints out the updated value. Some structures in this function include: looping if-else statements. updates to the string object, using the square brackets containing an index position. . . . next-guess There a few programming considerations for this function, and we will be going over these during the lab
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started