CS 150 Introduction to C++
Programming - Spring 1998
|
[ Home | Lecture Notes| WebTutor | WebTutor Site Map]
Commentary on Incremental Design
This frame contains commentary on the
developing incremental design shown in the right frame.
It is also used to move through the
developing design stages. You can always start over by clicking here.
When you are ready, click here to show the initial skeletal
design.
PIZZA Step 1:
Basically this is the skeletal C++ program
with comments indicating where certain parts of the C++
program should go.
- File documentation (first two lines)
- Place for including necessary libraries (almost
always needed)
- main function of the program and its beginning and
end braces around its body)
- place for constants (if any), Constants are highly
recommended for readability and changeability
- declarations of any variables need to store program
information
- statements which execute when the program is run and
which produce the results of the program
- return statement when the program is done
This program will compile and execute, but of course does
nothing.
Click here for PIZZA
step 2:
Many problems have three distinct parts:
- Get any input data
- Process the data to produce the results of the
program
- Output the results
Such problems have an Input/Process/Output (IPO)
structure.
So we have added some comments, which expand the executable
statements into these three parts.
Notice that adding the IPO comments expands, or refines, the
executable part of the previous design step.
This is also known as the process of SUCCESSIVE REFINEMENT
which will continue until we are satisfied with the design.
(for this and subsequent versions, we will show the new
part of the design in BOLD red
letters and the old part in italics)
Now let's give the specification for this case study: the
Monastery Pizza Problem:
| The new pizza company, The Monastery, requires
the development of an automated pricing and ordering
system. The company has a work place where the orders
are taken, one section for walkin ordering, and
another for phone ordering. These orders are then
given to the preparation section where the orders are
filled, baked, and boxed The company offers three
different shapes of pizza, round (either 12 or 16
inch), square (either 14 or 16 inch), and a 12 inch
by 24 inch rectangle. The company has decided to
price their pizza simply by considering the area of
each pizza and using that value to calculate the
overall cost of the delivered product. The cost per
square inch of pizza has been fixed at 2.5 cents.
Their pizza is prepared with any single topping
without cost, thus any pizza ordered with either
extra cheese or pepperoni, or sausage etc. has no
additional charge. For every topping after the one,
an additional charge of 0.3 cents per square inch of
pizza is added to the cost.
Prepare a proposed solution that could be used to
write a C++ program that would accept the order and
prepare the customer's bill. The bill should always
be rounded to the next highest increment of 50 cents
prior to the imposition of the state sales tax of 8%.
|
Click here for PIZZA
step 3:
You can work on any unfinished part to do the next
refinement.
But it is natural to work on the input since this also forces
us to think about what variables are need to remember the
input values.
Analyzing the problem specification, we can easily
identify several pieces of information which the user must
enter in order for the program to calculate the cost.
- Pizza Shape
- Pizza Size
- The number of kind of toppings
It is not important that you get everything at this point.
You can always add more later. For instance, a little
reflection on the problem might make you realize that you
should also include the customer's name (and maybe telephone
number - but let's stop with this).
So we have added several comments to the variable
declarations sections for these pieces of information.
Also we have added an executable statement comment which
indicates that we actually need to input this information.
Click here for PIZZA
step 4:
Since we are not yet comfortable with what it means to
process the input to produce results, we refine that part
now.
Basically we need to prepare the bill. This means calculating
how many square inches of pizza, calculating the cost,
rounding and taxing.
Click here for PIZZA
step 5:
Since computing the pizza cost is complicated by the
charge for toppings, we refine that step next.
Click here for PIZZA
step 6:
Now we refine the output part to produce an output label
to go on the pizza box.
So how do you know when to stop refining?
One criteria you could apply, is to stop when each step is
fairly obvious to you.
So what is next after refining the design?
Well it needs to be changed into a C++ program.
But we are not ready for that just yet. (however the skeleton
still should compile OK and do nothing very well).