Write my Paper on Lab: Functions

 

Chapter 6 Lab: Functions
This lab will give you experience writing and modifying functions in a program. You will be working with a “Rock, Paper, Scissors” program that has already been
partially written. To start this lab, first, download the program from the course website. Next, compile and run the program to see how it works. Finally, look
through the code to get an understanding of how it works, and what each function does.

Complete the decideWinner Function
In the program code you downloaded there is a function stub named decideWinner. This function needs to be completed. It takes in two strings as its’ arguments: the
computer’s choice and the user’s choice. It returns a string containing the outcome of the game. The output needs to look like this for every possible combination:

Tie! Try again!
Rock beats scissors, user wins!
Rock beats scissors, computer wins!
Paper beats rock, user wins!
Paper beats rock, computer wins!
Scissors beats paper, user wins!
Etc.

You need to write the logic statements that will compare the user and computer local function variables, then return the correct output string for the values supplied
to the function.

Modify a Function
In the program code you downloaded you will need to modify the function named getComputerChoice. As you’ve probably already noticed, the computer always chooses rock.
You need to fix this. You will need to implement a random number generator (from 1 to 3) that will simulate a random choice between rock (1), paper (2), and scissors
(3). Program 3-25, roughly page 127 in your book, implements a random number generator, use that as a reference. Note: before you use the rand() function as shown
in Program 3-25 be sure to get the system time and seed the random number generator as they did in the example.

Write a Function
Now, you will need to add a function to the program code you downloaded. Add a void function to complete the following task: write the outcome of the game (winner
and loser) to a text file. Review the slides from Chapter 5 discussing File IO as necessary. You may name the function and call it where ever you please, but, it
must record the winner and loser of each game and append the appropriate text to the end a file named: gameLog.txt. (Note: You will also need to create a file named
gameLog.txt in the same location as your program.)

 

Need help with this Essay/Dissertation?
Get in touch Essay & Dissertation Writing services

Is this question part of your assignment?

Place order