CS 230 Fall 2009 Assignment
6 –Looping (Dreaded Canine Flu Pandemic Silly Simulation)
100 Assignment Points
Assigned: 10/12/2009
Due: 10/26/2009 at the start of class (no
class on Oct 19 and 20 due to fall break)
Pre-Lab (Do Before Lab): Bring materials – a way to
save a copy for you and a copy to turn in. Read through the whole assignment;
hints and details are spelled out throughout. Plan out tasks, objects, and
events needed for program. Think about the main button’s pseudocode / flow
chart.
Main Assignment Description:
You
are creating an extremely simplified simulation. Write a program that simulates
the spread of the newly discovered and dreaded Canine Flu, which has no known
vaccine against it. Get from the user the starting number of people with the
flu, severity level of the outbreak (1-10), and the number of weeks to
simulate. Display in a RichTextBox for each week elapsed, the number of weeks
elapsed to that point and the number of people that are infected. After the
given number of weeks, display in labels or read-only textboxes the final
number of currently infected people. NOTE – this task MUST be done with a loop
– I need to see the week by week results in the rich text box – and in order to
see that, you cannot do a single one-time calculation.
·
Provide
capabilities to simulate, clear (the inputs and outputs) to start again, and to
exit.
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 6).
Background Knowledge:
- Each person with the
flu passes it on to a certain number of people the next week depending on
the severity level of the outbreak. With severity level 1, they pass it on
to two other people, with severity level 2, the pass it on to three other
people, … with severity level 10, they pass it on to 11 other people (see
the pattern ?)
- 90% of the people with
the flu in a given week recover by the next week. It doesn’t matter what
medicine they take. There is no cure!!!
- Nobody dies!
- NOTE: It is very
important that you calculate BOTH the number of new people infected AND
the number of people recovering based on the same group of infected people.
E.g. if 10 people are infected by a severity 1 outbreak, 9 will have
recovered by the next week – but not before infecting 20 other people –
resulting in 21 infected people the next week
- There is no need to
worry about individuals; everybody is just a number!
- The number of infected
people and the severity level are both always whole numbers.
Task Details:
- We’re no longer going
to assume that the user enters valid and reasonable values, so ensure that
the starting number of infected people, the severity level, and the number
of weeks to simulate are numbers (and whole numbers for that matter), and have
valid values – let’s assume that the starting number of infected people
has to be positive, the severity level needs to be 1-10, and the number of
weeks is between 2 and 1000. Don’t try to calculate anything if bad data
has been entered (display a message).
- HINT: You can use a
ComboBox in the GUI for the user to specify the severity of the outbreak.
The Items property of a ComboBox allows you to specify the possible values
to choose from. The user’s selection is available as comboboxname.SelectedItem.ToString() which can then be TryParse’d into an
Integer. If that sounds like a hassle, note that it means that you can
guarantee valid user input without any validation code! You might alternatively
use the SelectedIndex property which gives which number item was selected
(be careful!)
- HINT: You (if you
think about this) do NOT have to nest all branches inside each other (e.g.
for validation) if you are careful!!! If you check one input thoroughly
and set a boolean (e.g. weeksOk), that boolean can be checked later to see
if it was previously found ok or not.
- When 90% of people
recover, a straight calculation of 90% could result in a non-whole number
of people (which is not possible). You must ROUND the result, however the
round method produces a double. Instead, I recommend using the Convert.ToInt32 method – which has as a parameter the value
to be converted to an integer and produces an integer – which is rounded!!
- To add items to the
rich text box, as discussed in class, use richtextboxname.AppendText( a string ). You can build a string out of pieces using
“concatenation” . E.g. “Week:
“ & week.toString() & … … & ControlChars.NewLine
(The
ControlChars.NewLine moves the next info after to a new line). To clear the
contents of a list box, use richtextboxname.Clear()
- Clear can set input values to defaults instead of
clearing, if desired.
- MAKE SURE YOUR PROGRAM
WORKS! (i.e. gets the correct answers) - it doesn’t have to just run, it
needs to run correctly! Now that our program is branching, we
need to try more examples to make sure that they work. We want all paths
through the program to work correctly. Think, “what different
possibilities need to be checked?”For instance, does your program do the
right thing no matter how many inputs are invalid?
Miscellaneous:
- You must turn on
Option Strict and Option Explicit
- 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.
- You MUST include
comments that explain your program in order to get full credit.
- Name all textboxes and
buttons meaningfully, and use conventions for ending their names. Also,
any labels referred to in code should also be named meaningfully.
- Any variables that you
declare should have meaningful names – descriptive of the data that they
hold.
- Make any textboxes
that user should never enter a value in “Read Only” (or use labels
instead!)
- 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.
Hand in:
- Compressed (zipped) folder with your entire project containing
all files related to the project, submitted to Blackboard. Please
name the zip file something along the lines of yournameAssignment5
- Print out of your code.