YCP Logo Assignment 5: Roulette II - Using Functions

Due: Thursday, March 18th by 11:59 PM

Getting Started

Start by downloading CS101_Assign5.zip, saving it in the directory H:\CS101.

Start a Cygwin Bash Shell and run the following commands:

cd h:
cd CS101
unzip CS101_Assign5.zip
cd CS101_Assign5

Using Notepad++, open the file

H:\CS101\CS101_Assign5\Roulette.cpp

You will add your code to this file.

Run the command

make

when you are ready to compile the program. To run the program, run the command

./Roulette.exe

Your Task

Rewrite Roulette (refer to Assignment 2) to use functions.

Your program should include the following functions:

  • get_bet_amount() - which will return a valid bet amount obtained from the user. The function should contain all prompts for the user.
  • get_bet_type() - which will return a valid bet type obtained from the user. The function should contain all prompts for the user.
  • spin_wheel() - which will return a random number generated between 0-37
  • evaluate_odd() - which will be called if the bet type is odd and return appropriate winnings (or losses)
  • evaluate_even() - which will be called if the bet type is even and return appropriate winnings (or losses)
  • evaluate_number() - which will be called if the bet type is a particular number and return appropriate winnings (or losses)
  • print_winnings() - which will print out the winnings based on the current spin, the total winnings so far, and the current amount of money the user has remaining

You will need to determine appropriate return types and parameter lists for each function.

A good starting point may be your Assignment 2 code which can serve as a basis for this assignment.

Hints

Consider the tasks that each function must perform and sketch out a pseudocode strategy for the program. The main() function should simply implement the game process, i.e. get a bet amount, get a bet type, spin the wheel, evaluate the outcome, update the amounts, and print the results using functions. Since we cannot return multiple values at this point, you will need to only return the winnings from the evaluation functions and then update all necessary amounts in main().

You may be able to use parts of your assignment 2 code by placing sections that perform the required tasks into separate functions (with appropriate parameters), and using a function call containing the necessary arguments in the new program. This procedure is called refactoring.

Remember to place function prototypes before main(), then have main(), and finally the functions definitions after main().

Grading Criteria

For a Grade up to 70%:

The program should implement the entire roulette functionality but with functions that only obtain valid user input.

For a Grade up to 75%:

Write a function that obtains a random number for the wheel spin.

For a Grade up to 85%:

Write functions to evaluate the even and odd bet types.

For a Grade up to 90%:

Write a function to evaluate the particular number bet type.

For a Grade up to 100%:

Write a function to print all amounts for the current game along with the cummulative winnings and current amount of money remaining. The function should format the output in a well organized fashion with negative amounts showing the minus sign before the dollar sign.

Submitting

To submit your work, make sure your Roulette.cpp file is saved, and type the command

make submit

Enter your Marmoset username and password (which you should have received by email.) Note that your password will not be echoed to the screen. Make sure that after you enter your username and password, you see a message indicating that the submission was successful.

Important: Make sure that you check the file(s) you submitted to ensure that they are correct. Log into the server using the following URL:

https://camel.ycp.edu:8443/view/course.jsp?coursePK=61

You should see a list of labs and assignments. In the row for assign5, click the link labeled view. You will see a list of your submissions. Download the most recent one (which should be listed first). Verify that it contains the correct files.

You are responsible for making sure that your submission contains the correct file(s).