YCP Logo Assignment 5: Refactoring Roulette Using Functions

Due: Tuesday, March 24th 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.

You will need to consider the design of your program, identify blocks of code that perform identical or similar tasks, and change them into function calls. Your goal is to simplify the program. When you are done, you should find that your program is significantly easier to read and understand.

The behavior of the program should not change (unless you need to fix bugs) and meet all the requirements of the original assignment (including those at the 100% level).

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

Hints

Consider the tasks that the program must perform and sketch out a pseudocode strategy for the program. Look for tasks that are repeated, serve a single purpose, and/or have some degree of complexity as potential functions. You should end up with a reasonable number of functions, but the exact number will vary from student to student based on how you decide to break up the problem.

Then determine what values are needed for the computations within each function - i.e. the parameters - and what values are generated by each function - i.e. the return values.

Finally consider cutting those parts of your assignment 2 code out of main(), placing them into a separate function (with appropriate parameters), and replacing the original code with a function call containing the necessary arguments. This procedure is called refactoring.

You should refactor incrementally so that as you create each separate function, your program should function as it did before you created the function. When you are finished, there should be no functional difference (other than bug correction) from the original program but it should be much better organized.

Grading Criteria

25% of your grade will be based on the basic functionality of the program (as described in the original assignment 2 description.)

75% of your grade will be based on how well you used functions to simplify the implementation of the program.

Coding style: Make sure that you use meaningful variable names, that your code is properly indented, and that you include some comments explaining how the code works. Credit may be deducted if you use poor coding style.

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=54

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