Beruflich Dokumente
Kultur Dokumente
Introduction:
Below, youll find the problem statement repeated from the instruction document,
my solution, and any additional notes I may have for you. In my solution, I talk
about how I broke down the problem to read the clues to help me find the solution.
These are the techniques you learned in the problem solving unit. Please note, this
is just one way to solve the problem there may be others.
The Problem:
The Austin Widget Manufacturing Company wants to reward the employees who
have increased their production of widgets this year over last years production.
These employees will receive a certificate of commendation and a bonus.
Write a program design using pseudocode that allows the user to input the
employees first name, employees last name, number of widgets produced this year,
and number of widgets produced last year. Calculate any bonus, if appropriate, and
display the employees name (first and last) and the calculated bonus.
For an employee, if this years production is greater than last years production,
calculate any bonus as follows:
A NOTE ABOUT THE INTERFACE: You have the freedom to include what you
wish, but, as a minimum, use appropriate heading(s), input prompts and output
prompts. Assume input from the keyboard and output to the screen.
NOTE: do not ask the user to make any calculations. The program should make all
calculations. Write your design for a single customer. The design must include all
IO prompts and/or headings. You may choose to include an interface storyboard(s)
It is required that you use the simple sequence and selection (if) structures. DO
NOT use the repetition structure, arrays, or modules.
MY Solution:
NOTE: again, this is just one way the problem could be solved. My solution is based
on the examples Ive given you in the lectures. In my design, any comments to help
you see the logic of my solution are highlighted in yellow.
Before I begin actually writing the design, I make some notes as I read the
problem. I define what needs to be input into the program and what needs to be
output. For example, as I read the problem statement, I determine that the Input
items are:
Next, I read the problem for what needs to be output. Again, as I read the
problem statement, I determine that the Output items are:
Also, I look for any heading information as I read the problem statement and see
that it would be helpful to have report headings. Ive chosen to use the following.
Report Heading
Heading Line 1 = Austin Widget Manufacturing Company
Heading Line 2 = Employee Bonuses
Notice there isnt any real logic and the above notes are NOT clear enough to be
considered the design of the program. Im simply getting my ducks in a row so I
The Design:
To write the introduction, I need to understand the problem. Simply copying the
problem from the assignment instructions doesnt insure that I understand the
problem. Also, a statement such as Write a design to input stuff, calculate results
and output those results is so ambiguous its of no benefit whatsoever.
Output the employees name (first and last) and the bonus.
VARIABLE LIST:
As you read through the following detail plan, please notice the indentation and the
EXPLICIT beginning and ending of the structures. This is done to make the plan as
easy to read as possible. Remember, your goal here is to be as clear as you possibly
can. DO NOT leave any room for assumption.
DETAIL PLAN (without storyboards this means Ive included screen prompts in
my detail plan):
Start
Declare variables NOTE: you can put the variable list under this
statement, if you wish. YOU DO NOT HAVE TO
DO BOTH.
Write heading1
Write heading2
Write blank line
Write Enter the Employees First Name:
Read First
Write Enter the Employees Last Name:
Read Last
Write Enter the number of widgets produced this year:
Read This
Write Enter the number of widgets produced last year:
Read Last
NOTE: I put all of the input statements in one place for claritys sake. Also
note that the prompts are listed in a write statement and separate from
the read statements the reads represent statements to the
programmer to accept data from some outside source to be used later in
the program.
Notice the Stop statement. This is so the programmer will know that Ive ended
the program design without any doubt. Next, Ive written the storyboard(s) and
have redone the detail plan to remove the prompts. Either way you choose to do
this, is fine by me.
Storyboard:
Start
Declare variables NOTE: you can put the variable list under this
statement, if you wish. YOU DO NOT HAVE TO
DO BOTH.
Read First
Read Last
Read This
Read Last
Notes to students:
The above design makes up the full requirements listed in the instructions and is
presented in the requested order. The requirements include an introduction, a
variable list (also called a data dictionary), and a main start/stop algorithm. The
examples in the book show you that you can include the variable list in the main
algorithm indented under the declare variables statement. I will accept that as
well. You dont need to do both.
The book also DOES NOT include the declare variables statement. I think using
such a statement is clearer and gives the reader an understanding of the variable
declaration statements at the beginning of the designs presented in the book.
This design utilizes both the simple sequence and selection structures and they are
written using structured programming. In fact, the main start/stop algorithm is
also structured (single entry, single exit, using combinations of three structures).
When we talk about program flow or logical flow, we mean the presentation of
commands (or statements) one after the other in a top-down approach. That is the
way the computer will process this program once its written in a programming
language and present to the computer. The computer will read and process the
statements IN THE ORDER GIVEN IN THE DESIGN.
Do you also see that this algorithm is for a SINGLE employee bonus? If I want to
process multiple employee bonuses, then I have to add a loop (THATS RIGHT, the
IF statement isnt a loop). Where to add that loop is really something to think
about.
With all loops, regardless of the type, you have to have to take care of three
situations:
To add a loop to this algorithm, you have to think about how youre going to control
it. Since the input is coming from the keyboard, we cant control it with an EOF-
controlled loop, so well need to think of another way. How about asking our user a
question, such as Do you wish to continue? This way, we can use their answer to
control the loop.
First, we need to add a variable to the variable list; a variable to use to control (the
relational expression) the loop:
VARIABLE LIST:
Before we continue, lets talk about the input. The variables First, Last, This and
Last represent the input for a complete employee. We can call that a data set or
record. When we think about a loop, we want to process a complete employee bonus
before we repeat the next employee bonus. That means, in this case, we want to
input the data set, calculate the bonus and display the output BEFORE we read in
the next data set or record.
Heres the algorithm with the loop (I used the storyboard version since its the
simplest to read). I highlighted the required loop components:
Start
Declare variables
Write Do you wish to continue? (Y/N) NOTE: Step 2, set initial control
Read ans value
REMINDER: you want to include all statements inside the loop that you want
repeated. Do you recognize the order of events in the loop body?
Because the loop is properly controlled, these three events will be executed in the
above order EACH TIME THE LOOP REPEATS.
Do you also recognize what keeps the loop repeating? Thats right, the users ans.
If its upper case Y or lower case y, then the loop keeps repeating, allowing another
employees information to be processed. If the users ans is ANY OTHER VALUE
THAN an upper or lower case y, the loop will STOP and program control will
continue to the next statement AFTER the end loop (in this case Stop).