CS 230 Spring 2007 Assignment 7 – Sub Procedures
and Function Procedures 100 points
Assigned: 03/14/2007
Due: 03/21/2007 at the start of class
Pre-Lab (Do Before Lab): Bring materials – a way to
save a copy for you and a copy to turn in. Plan out tasks, objects, and events
needed for program. Write pseudocode for the main button and for
functions / independent sub procedures
.
Main Assignment:
Casinos
are coming to the Philadelphia area! Imagine that you are writing the
beginnings of a very basic program for a dice game. This time the user is
allowed to win! The first time playing, the user will enter into a textbox how
many “points” they have to start. They will also enter (each time they want to
play) a guess for the total for all rolled dice. When a “Roll” button is
Clicked, the program should (do this in a function!) generate a random number
of rolls between 10 and 20, and roll a die that many times, keeping track of
the total. If the player’s guess is below (or equal) the total of the rolled dice,
they win the number of points that they guessed. If the players guess is
greater than the total of the rolled dice, they lose the number of points that
they guessed. After the roll has been completed, display in labels or
read-only textboxes the number of rolls, and the total, and the user’s result
(how much they won or lost), along with updating the users current balance of
points.
·
Provide capabilities
to play, clear (the inputs and outputs except the user’s balance), reset (to
start over again – clear the balance too and make it no longer read-only), and
to exit.
Hand in:
- Floppy disk or CD-R with an entire folder containing all
files related to the project (or e-mail with zipped attachment containing
all files related to the project). Please set the name of the
project to something other than the default name
(WindowsApplication1, …). It is helpful if you use a name that
identifies you as well as the assignment (e.g. yourlastname assignment
7). Use Windows to copy the whole folder, instead of trying to “Save As”.
- Print out of your code.
Task Details:
·
In this task, we mainly only
get one of the benefits of procedures and functions (dividing up into
manageable tasks). Most procedures or functions you would write will only be
called from one place in your code. However, you must write some
procedures and functions for this assignment (and use them!)
o
The rolling of dice must be
handled by a function
o
Determining if the user wins
or loses (and how much) should be handled by a function
o
If we have covered validating
inputs using a function on Wed, then you need to do that (otherwise it is
optional)
o
Use a independent sub
procedure to clear textboxes for clear and reset capabilities
- Define numbers
(especially those that could change sometime in the futures) as named
constants
- After the user plays
the first time, set the textbox for their balance to be read only.
- We’re no longer going
to assume that the clerk enters valid and reasonable values. Ensure that
the user’s guess is positive and numeric. Ensure that the user’s balance
of points is positive and less than a million. Don’t try to calculate
anything if bad data has been entered (display a message). For
simplification don’t worry if balance is negative whether it is a user
error or if the user has just gone broke; the same message can be used.
- MAKE SURE YOUR PROGRAM
WORKS! (i.e. gets the correct answers). It doesn’t have to just run, it
needs to run correctly! It should run on any inputs (We are
now branching – so the program must be tested on more inputs to ensure
that all paths through the program code work!). For instance, does your
program still do the right thing no matter how many of the inputs are
invalid? Think up some different
examples to test the program on.
Miscellaneous
- You must turn on
Option Explicit and Option Strict.
- Put YOUR NAME, e-mail
address, date, and purpose of the program in comments at the beginning of
the program. The purpose should be what the program is supposed to do, not
the learning goals. Comments are indicated with a single quote (everything
after the single quote is only for humans)
- You MUST include
comments that explain your program in order to get full credit.
- Remember to use
meaningful variable names
- Remember to indent to
show the structure of the program (VB usually does this correctly).
- Name all textboxes and
buttons meaningfully, and use conventions for starting their names.
- Make textboxes that
user should never enter a value in (results / outputs) “Read Only”.
- Put your name on
the form as a Label or as part of the form title.
- Try to use good user
interface design. Make clear what user needs to do and what the answers
mean. Make error messages as clear and helpful as possible!