08 Jun Chocolate Delights Candy Company manufactures several
Question
of candy. Design a fl owchart or pseudocode for the following:
a. A program that accepts a candy name (for example,
“chocolate-covered blueberries”), price per pound, and
number of pounds sold in the average month, and displays
the item’s data only if it is a best-selling item. Best-selling
items are those that sell more than 2000 pounds per
month.
Be sure to submit this in proper psuedocode and computer programming code format including all the required sections of psuedocode (housekeeping, main loop, end of job tasks). Present this assignment in a powerpoint flowchart with the computer code written as the sample diagrams (slide 41 example) are in the attached file. The final product should fit on either one or two powerpoint slides, with a similar format to slide 41 of the attached file.
The attached Powerpoint explains how to properly write all three sections of psuedocode, which is a requirement of this exercise.
This exercise is very simple in reality. The company is asking you to read an existing file containing the candy sales for a month. If a candy sells more than 2000 pounds, you are to print the candy name, price per pound, and pounds sold. It’s just that simple. Because it is a report, you also need a report headings plus column headings. Be sure to follow these requirements explicitly.
1. You are to be reading an existing file, therefore there is no “INPUT” command and no “QUIT” value to stop the process.
2. In reading an existing file, you must inlcude a DO WHILE NOT EOF command to read all the record in the file. Otherwise we only read the first data record.
3. When printing headings, which are necessary in any report so we know what data we are looking at, we put all three fields in one heading line. Everytime a PRINT command is executed, another line is printed, so we would say:
Heading2 = “Candy Name Price Per Pound Pounds Sold”
Print Heading2
4. Do not use an ELSE command as there is no action necessary if a data record does not meet the test condition of “if lbssold > 2000”. If it does not test true, we just skip that data record and read the next one.
Why use Pseudocode?
•
We have two design tools to help layout
our program logic
–
Flowcharts (pictorial representation)
–
Pseudocode (textual representation)
Parts of Pseudocode
•
Housekeeping (also called the declaration
or definition). This section is where we
declare our variables, set up our
headers,etc, and get the first record
String lname
String fname
String accountno
Num accountbal
String heading1 = “Low Threshhold Accounts”
String heading2 = “First Name Last Name Account
Main Loop
•
Main loop tasks that repeatedly execute
within the program. These tasks include
the instructions that are executed for every
record until you reach the end of the input
(eof)
Do while not (eof)
if accountbal < 100
print lname, fname, accountno, accountbal
endif
get lname, fname, accountno, accountbal
End of Job Tasks
•
•
In this section we would print any footers
and end the program
Stop
•
ALL three sections of pseudocode are
required
Chapter 5:
Making Decisions
Programming Logic and Design,
Third Edition Introductory
Objectives
•
•
After studying Chapter 5, you should be
able to:
Evaluate Boolean expressions to make
comparisons
•
Use the logical comparison operators
•
Understand AND logic
•
Understand OR logic
Programming Logic and
8
Objectives (continued)
•
•
Use selections within ranges
Understand precedence when combining
AND and OR selections
•
Understand the case structure
•
Use decision tables
Programming Logic and
9
•
Evaluating Boolean
Expressions to Make
The selection structure (sometimes
Comparisons
called a decision structure) is one of the
basic structures of structured
programming
Programming Logic and
10
•
Evaluating Boolean
Expressions to Make
A dual-alternative, or binary, selection:
Comparisonseach of two possible
(continued)
has an action associated with
–
outcomes
•
This selection structure is also called an
if-then-else structure because it fits the
statement:
if the answer to the question is
yes, then
do something
else
Programming Logic and
11
Evaluating Boolean Expressions
to Make Comparisons (continued)
•
A single-alternative, or unary, selection
–
•
•
action is required for only one outcome of the question
A Boolean expression is one that
represents only one of two states, usually
expressed as true or false
Every decision you make in a computer
program involves evaluating a Boolean
expression
Programming Logic and
12
Using the Logical Comparison
Operators
•
Usually, you can compare only values that
are of the same type:
–
–
•
compare numeric values to other numeric values
compare character values to other characters
You can ask every programming question
by using one of only three types of
comparison operators in a Boolean
expression
Programming Logic and
13
Using the Logical Comparison
Operators (continued)
•
For any two values that are the same
type, you can decide whether:
–
–
•
The first value is greater than the second value
–
•
The two values are equal
The first value is less than the second value
In any Boolean expression, the two
values used can be either variables or
constants
Each programming language supports
Programming Logic and
14
its own set of logical comparison
Using the Logical Comparison
Operators (continued)
•
•
Most languages allow you to use the
algebraic signs for greater than (>) and
less than (<) to make the corresponding
comparisons
Additionally, COBOL, which is very
similar to English, allows you to spell
out the comparisons in expressions like
dayPastDue is greater than
30? or packageWeight is less
Programming Logic and
15
than maximumWeightAllowed?
Using the Logical Comparison
Operators (continued)
•
•
Most programming languages also
provide for three additional comparisons
For any two values that are the same
type, you can decide whether:
–
–
The first is less than or equal to the second.
–
•
The first is greater than or equal to the second.
The two are not equal.
Any logical situation can be expressed using just three
types of comparisons: equal, greater than, and less than
Programming Logic and
16
Using the Logical Comparison
Operators (continued)
•
•
Comparing two amounts to decide if
they are not equal to each other is the
most confusing of all the comparisons
Using “not equal to” in decisions
involves thinking in double negatives,
which makes you prone to include
logical errors in your program
Programming Logic and
17
Using the Logical Comparison
Operators (continued)
Programming Logic and
18
•
Using the Logical Comparison
Operators (continued)
Besides being awkward to use, the “not
equal to” comparison operator is the one
most likely to be different in various
programming languages
–
–
–
COBOL allows you to write “not equal to”
Pascal uses a less-than sign followed immediately by a
greater-than sign (<>)
C#, C++, C and Java use an exclamation point followed
by an equal sign (!=)
Programming Logic and
19
Understanding AND Logic
•
•
•
Often, you need more than one
selection structure to determine whether
an action should take place
For example, suppose that your
employer wants a report that lists
workers who have registered for both
insurance plans offered by the
company: the medical plan and the
dental plan
Known as an AND decision because
Programming Logic and
20
Understanding AND Logic
(continued)
•
A
compound,
or AND,
decision
requires a
nested
decision, or
a nested if
—that is, a
decision
Programming Logic and
21
Writing Nested AND Decisions
for Efficiency
•
•
•
When you nest decisions because the
resulting action requires that two
conditions be true, you must decide
which of the two decisions to make first
Logically, either selection in an AND
decision can come first
However, when there are two
selections, you often can improve your
program’s performanceand making an
by
Programming Logic
22
Writing Nested AND Decisions
for Efficiency (continued)
•
In many AND decisions, you have no idea
which of two events is more likely to occur;
–
•
In that case, you can legitimately ask either question
first
In addition, even though you know the
probability of each of two conditions, the
two events might not be mutually exclusive
–
In other words, one might depend on the other
Programming Logic and
23
Combining Decisions in an AND
Selection
•
•
Most programming languages allow you to
ask two or more questions in a single
comparison by using a logical AND
operator
If the programming language you use
allows an AND operator, you still must
realize that
–
–
the question you place first is the question that will be
asked first
cases that are eliminated based on the first question will
Programming Logic and
24
Combining Decisions in an
AND Selection (continued)
•
The computer can ask only one
question at a time
Programming Logic and
25
Combining Decisions in an AND
Selection (continued)
Programming Logic and
26
Avoiding Common Errors in an
AND Selection
•
•
When you must satisfy two or more criteria
to initiate an event in a program, you must
make sure that the second decision is
made entirely within the first decision
Beginning programmers often make
another type of error when they must
make two comparisons on the same field
while using a logical AND operator
Programming Logic and
27
Understanding OR Logic
•
•
Sometimes, you want to take action
when one or the other of two conditions
is true
Called an OR decision because
–
–
•
either one condition must be met or
some other condition must be met, in order for an
event to take place
If someone asks you, “Are you free
Friday or Saturday?,” only one of the
two conditions has to be true in order
for the answer to the whole question to
Programming Logic and
28
be “yes”
Understanding OR Logic
(continued)
Programming Logic and
29
•
Incorrect Flowchart for
mainLoop()
This flowchart is not allowed because it
is not structured
Programming Logic and
30
Avoiding Common Errors in an
OR Selection
•
•
An additional source of error that is
specific to the OR selection stems from a
problem with language
The way we casually use English can
cause an error when a decision based on
a value falling within a range of values is
required
Programming Logic and
31
Writing OR Decisions for
Efficiency
•
You can write a program that creates a
report containing all employees who have
either the medical or dental insurance by
using the mainLoop()
Programming Logic and
32
Writing OR Decisions for
Efficiency (continued)
Programming Logic and
33
Writing OR Decisions for
Efficiency (continued)
Programming Logic and
34
Writing OR Decisions for
Efficiency (continued)
•
•
•
One of these selections is superior to the
other
Using either scenario, 950 employee
records appear on the list, but the logic
used in Figure 5-26 requires 1,100
decisions, whereas the logic used in
Figure 5-27 requires 1,500 decisions
The general rule is: In an OR decision,
Programming
35
first ask the question Logic and more likely to
that is
Combining Decisions in an OR
Selection
•
•
If you need to take action when either one
or the other of two conditions is met, you
can use two separate, nested selection
structures, as in the previous examples
However, most programming languages
allow you to ask two or more questions in
a single comparison by using a logical OR
operator
Programming Logic and
36
Using Selections Within Ranges
•
•
•
Business programs often need to make
selections based on a variable falling
within a range of values
When you use a range check, you
compare a variable to a series of values
between limits
To perform a range check, make
comparisons using either the lowest or
Programming Logic and
37
highest value in each range of values you
Common Errors Using Range
Checks
•
•
•
Two common errors that occur when
programmers perform range checks both
entail doing more work than is necessary
Figure 5-33 shows a range check in which
the programmer has asked one question
too many
Another error that programmers make
when writing the logic to perform a range
check involves asking unnecessary
Programming Logic and
38
Inefficient Range Selection
Including Unreachable Path
Programming Logic and
39
•
Understanding Precedence
When Combining AND and
Most programming languages allow you
OR Selections
to combine as many AND and OR
operators in an expression as needed
•
•
•
The logic becomes more complicated
when you combine AND and OR
operators within the same statement
When you combine AND and OR
operators, the AND operators take
precedence, meaning their Boolean
values are evaluated first
Programming Logic and
40
You can avoid the confusion of mixing
•
Understanding the Case
Structure
The Logic below is completely
structured
Programming Logic and
41
•
•
•
Understanding the Case
Structure (continued)
Writing the logic using a case structure,
as shown in Figure 5-37, might make it
easier to understand
The case structure provides a
convenient alternative to using a series
of decisions when you must make
choices based on the value stored in a
single variable
When usingProgramming Logic and
the case structure,42you test
Flowchart and Pseudocode of
Housing Model Using the Case
Structure
Programming Logic and
43
Using Decision Tables
•
A decision table is a problem-analysis
tool that consists of four parts:
–
–
–
–
Conditions
Possible combinations of Boolean values for the
conditions
Possible actions based on the conditions
The specific action that corresponds to each
Boolean value of each condition
Programming Logic and
44
Summary
•
•
Every decision you make in a computer
program involves evaluating a Boolean
expression
For any two values that are the same
type, you can use logical comparison
operators to decide whether
–
the two values are equal,
–
the first value is greater than the second value, or
–
the first value is less than the second value
Programming Logic and
45
Summary (continued)
•
•
Most programming languages allow you
to ask two or more questions in a single
comparison by using a logical AND
operator
An OR decision occurs when you want
to take action when one or the other of
two conditions is true
Programming Logic and
46
Summary (continued)
•
•
Most programming languages allow you
to ask two or more questions in a single
comparison by using a logical OR
operator
The case structure provides a
convenient alternative to using a series
of decisions when you must make
choices based on the value stored in a
single variable
Programming Logic and
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
