This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Problem Solving I George Mason University
IT108 Solving everyday problems
Phases include some or all of the following: •
1.
2.
3.
4. Analysis and Planning
Review the Plan
Implement the Plan
Evaluate and modify (if necessary) the
implementation Phase 1:Analysis and Planning
Determine the goal and what is needed to reach
the goal
Example: As you don’t have enough classes for the semester so
you will be trying to force add classes all day. Because of
this you won’t have time for lunch.
Items needed to reach goal Plan Bread
Peanut butter
Jelly 1.
2.
3.
4. Goal Take out bread
Open the peanut
butter and put on
bread
Open the jelly and
put on bread
Put sandwich in bag Make lunch to bring
with you Phase 2 and 3: Review and Implement
• Does the plan look like it will work?
Items needed to reach goal Plan Bread
Peanut butter
Jelly 1.
2.
3.
4. • Goal Take out bread
Open the peanut
butter and put on
bread
Open the jelly and
put on bread
Put sandwich in bag Make lunch to bring
with you Implement the plan
• Get the items and make the sandwich Phase 3: Evaluate and Modify
What
What problems occurred when we tried to
implement?
Items needed to reach goal Plan Bread
Peanut butter
Jelly
Knife
??
Bag
?? 1.
2.
3.
4. Modify the plan Goal Take out bread
Make lunch to bring
with you
Open the peanut
butter and put on on
??
bread using knife
Open the jelly and
jelly and put
on ?? o bread
putbreadnusing knife
Put sandwich in bag Analysis and Planning
Problem: Your overbooked professor must leave
immediately after class at the Fairfax campus
and go to the Prince William campus to teach his
next class. The professor is somewhat rattled by
the lack of time and wants to plan his trip. Analysis
Identify:
•
What is the goal
•
What is needed to accomplish the goal
•
How the goal will be accomplished Analysis
What is needed?
Car
Directions Algorithm
1.
2.
3. Goal Walk to parking garage Arrive at Prince William
Exit Fairfax campus
Campus
Follow directions to
Prince William campus Do you have parking permit?
NO Modifications after initial step
What is needed?
Car
Directions
Money Algorithm
1.
2.
3.
4. Goal Walk to car
Arrive at Prince William
Pay for parking
Campus
Exit Fairfax campus
Follow directions to
Prince William campus Solving Computer Problems
Phases include all of the following:
1.
2.
3.
4.
5.
6. Analysis of the Problem
Plan an algorithm to solve the Problem
Desk check the algorithm
Implement the algorithm by coding a program
Desk check the coded program
Evaluate and modify (if necessary) the coded
program Analyzing a Problem
Solving a problem using a computer requires a
thorough understanding of the underlying
problem specifics.
Much like you did in your high school Algebra
courses, you need to sift through all of the
‘words’ to identify the three important parts:
•
•
• Input
Process
Output Analysis
Often it is best to first identify the goal (aka:
output)
Next, determine what information will be
needed to arrive at that goal (aka: input)
Finally, identify the steps required to go from
the input to the output (aka: process) Gas Mileage
Your professor is teaching classes at both the Prince
William and Fairfax campuses this semester. He is
concerned about his commuting cost and wants to
determine the MPG his vehicle gets. He is able to
travel 425 miles on a full tank (17 gallons) of gas. Analysis
Analyze the problem looking for nouns and
adjectives that represent either input or output
Output should represent what the user should
‘see’ on the screen when the problem is solved
Input should be identified by the information
needed (e.g., in calculations) to determine the
output Analysis – Input and Output
Your professor is teaching classes at both the Prince
William and Fairfax campuses this semester. He is
concerned about his commuting cost and wants to
determine the MPG his vehicle gets. He is able to
travel 425 miles on a full tank (17 gallons) of gas. Planning  Algorithm
Input Process
1. Number of Miles
Number of Gallons
2.
3. Enter the number of
miles and the number
of gallons of gas
Calculate MPG
Display MPG Notice that the number of miles and
the number of gallons is left generic –
not specific to your professor! Output
Miles per Gallon Review
Look at your design:
•
• • Did you answer the ‘question’?
Did you include the information required to solve
the problem?
Did you avoid using specific numbers/words so
that your solution can be used in more than one
situation? Desk Checking
Make sure your logic works by ‘tracing’ through
your design with several permutations
Miles Driven Gallons Used MPG 420 15 28 425 17 25 Implementation
Concentrate on your algorithm (which identified
WHAT needed to be accomplished)
Using a flowchart (or pseudocode) determine
HOW the steps will be accomplished Flowcharting the MPG Problem
From the IPO Chart, use flowcharting symbols
to create a pathway for a solution to your
problem
Verify that your design is correct by tracing
through the flowchart with simulated data
Make any necessary modifications to your
design Flowcharting
Terminal
Start/Stop Process
Calculation
Assignment Decision
(yes/no) Input/Output Connector Flowchart for MPG
Start
Input miles
Input gallons mpg = miles/gallons
Display mpg
Stop Phase 1: Analysis of the Problem
• Like in everyday problems, the purpose of
analyzing the problem is to
•
• • Determine the goal
Determine the items needed to reach the goal Example: Your professor just made you aware of an extra
credit opportunity. If you attend all IT108 classes between
the midterm and the end of the semester, you will receive a
4% boost to your midterm grade. You earned a 41/48 on your
midterm which is a 85.4%. You would like to write a
program that will display on the screen your new midterm
grade (assuming you attend all the remaining classes). Phase 1: IPO Charts
• IPO: Input, Processing, Output
Helps programmers organize and summarize
the results of the analysis to the problem • Determining necessary output: • • Examine the problem to answer the following:
– • What output will the program print, display, or store the output
items? Determining necessary input:
• Examine the problem to answer to the following:
– What input will the program need to know to print,
display, or store the output items? Phase 1: IPO Chart with Input, Output
Phase 1 results
Input Processing Current midterm grade
Boost rate Note similarities to solving everyday problems:
•
Input is similar to ‘Items needed to reach goal’
•
Processing is similar to ‘Plan’
•
Output is similar to ‘Goal’ Output New midterm grade Determining Necessary Information
• If you are having difficulty determining which
information in a problem is necessary, try
going through each word in the problem
answering the following:
• • If I didn’t have this piece of information, could I
still solve the problem? Cross out any words/phrases that you
determine are unnecessary to solving the
problem Determining Necessary Information
Example: Your professor just made you aware of an extra credit
Your
opportunity. If you attend all IT108 classes between the
midterm and the end of the semester, you will receive a 4%
you
boost to your midterm grade. You earned a 41/48 on your
41/48
midterm which is a 85.4%. You would like to write a
85.4%. You
write
program that will display on the screen your new midterm
grade (assuming you attend all the remaining classes).
(assuming Is Necessary Information Missing?
Sometimes all the necessary input to solve the
problem is not stated
Example: You want to get an ‘A’ in IT108. You would like to
write a program that will display on the screen the grades you
need to get on the labs, exams, assignments, and projects to
make this happen. Phase 2: Plan an Algorithm
•
• Components:
Processing Item
• • Pseudocode
• • Any value used within the algorithm process that is needed
by the algorithm which is not provided by the input or part
of the output (in other words, an intermediate result)
A codelike representation of an algorithm and the steps
needed to solve a problem Flowchart
• A symbolic representation of all the components/
tasks (I, P, O) involved in solving a problem Phase 2: IPO Chart with Processing
Input Processing Output Current midterm grade
Boost rate Processing Items:
•
Grade boost
Pseudocode Algorithm:
1.
Enter the current
midterm grade and
boost rate
2.
Calculate the grade
boost by multiplying
the current midterm
grade by the boost rate
3.
Calculate the new
midterm grade by
adding the grade boost
to the current midterm
grade
4.
Display the new
midterm grade New midterm grade Flowcharting
• Start/stop symbol [rounded rectangle/oval]
• • Input/output symbol [parallelogram]
• • Denotes the input and output algorithmic
steps/tasks Process symbol [rectangles]
• • Denotes the beginning and end of the
problem Denotes process, calculation, and
assignment steps/tasks Flowlines
• Connect symbols Terminal
Start/Stop Input/Output Process
Calculation
Assignment Phase 2: IPO Chart with Flow Chart
Input Processing Output Current midterm grade
Boost rate Processing Items:
•
Grade boost
Flowchart: New midterm grade Start Enter current midterm
grade and boost rate
grade boost = current midterm
grade x boost rate
new midterm grade = grade boost
+ current midterm grade
Display the new
midterm grade
Stop Only algorithm to solve problem?
Often a problem can be solved more than one way
•
Inputs and Outputs stay the same
Is there another way to process this problem?
Input Processing Output Current midterm grade
Boost rate Processing Items:
•
NONE
Grade boost
Pseudocode Algorithm:
1.
Enter the current midterm
grade and boost rate
2.
Calculate the grade boost
by multiplying the current
midterm grade by the
boost rate and adding this
to the current new midterm
3.
Calculate the midterm
grade by adding the grade
grade
3.
Display
boost to the new midterm
current
grade
midterm grade
4.
Display the new midterm
grade New midterm grade Don’t reinvent the algorithmic wheel
Always keep a copy of your IPO charts with
pseudocode algorithms and flowcharts
• • When you have a new problem to solve, see if you have
solved a similar problem previously that can just be tweaked
If not, see if you have solved a similar part of the problem
previously which you could add to the new problem solution Phase 3: Desk Check the Algorithm
• While your approach to the problem is still
easy to visualize:
• • Make sure that your steps make sense in the order
they are
Make sure you are not missing any steps where
you assume people know what you mean
– • The computer only understands instructions… it
doesn’t make assumptions! Create a set of values to verify your
final program against Desk checking…
Current midterm grade Boost rate Grade boost New midterm grade 85 .04 3.4 88.4 72 .04 2.88 74.88 You probably will also want to add some scenarios with
different boost rates Example: Pay the phone bill
• You have in your bank account $150.
Compute the remaining balance in your bank
account after you will pay the phone bill for
the current month. Your monthly payment is
$99, and the tax rate is 5%. Phase 1: Analysis of the Problem
•
•
• • Determine the goal
Determine the items needed to reach the goal
Look for nouns and adjectives in the problem as
these often represent the input and output
Determining necessary output:
• • Determining necessary input:
• • What output will the program print, display, or store the
output items?
What input will the program need to know to print,
display, or store the output items? Cross out any words/phrases that you
determine are unnecessary to solving the
problem Phase 2: IPO Chart with Processing
Input Processing Output Current bank account
balance
Phone/internet/cable
monthly rate
Phone/internet/cable bill
tax rate Processing Items:
•
Phone/internet/cable tax
amount
Pseudocode Algorithm:
1.
Enter the current bank
balance, phone/internet
/cable monthly rate and tax
rate
2.
Calculate the
phone//internet/cable tax
amount by multiplying the
monthly rate by the tax
rate
3.
Subtract the
phone/internet/cable
monthly rate and tax
amount from the current
bank account balance
4.
Display the new bank
account balance New bank account
balance Phase 3: Desk Checked the Algorithm
Current
bank account
balance Phone/internet/
cable monthly
rate Phone/internet/
cable tax rate Phone/internet/ New bank
cable tax amount account 150 99 .05 4.95 46.05 200 109 .06 6.54 84.46 balance InClass Problem Solving Example
As an Undergraduate Peer Mentor for the AIT
department, students earn $10 per hour for
assisting professors. Typically a student works 5
hour per week. A proposal is submitted
suggesting a 15% pay raise. What would be the
change in average weekly gross pay for
students? IPO Chart
Input Processing Output InClass Problem Solving Example
Hiking boots at Timberland have a retail price of
$120. If the store has a sale where boots are
discounted by 20%, what is the new cost of the
boots? If there is an additional discount of 5%
when customers have a coupon, how much will
the boots cost? IPO Chart
Input Processing Output InClass Problem Solving Example
IT304 course requirements include a 200 point
midterm exam, a 400 point final exam and a 300
point project. If a student earns 150 points on
the midterm, 300 points on the final and 120
points on the project – what is their course
percentage? IPO Chart
Input Processing Output ...
View
Full
Document
This note was uploaded on 01/26/2012 for the course IT 108, 103, taught by Professor Bruno during the Spring '11 term at George Mason.
 Spring '11
 Bruno

Click to edit the document details