View
7
Download
0
Category
Preview:
Citation preview
1
Introduction to Programming
Concepts & Logic
CS002
2
- Programs are simply solutions to problems.
- To create a program we have to learn how to think in a different way, the way computers think.
CS002
Chapter 1
3
General Problem-Solving
Concepts
CS002
4
1. Identify the problem
◦ What is the specific problem?
(This means you should determine what is that
you want to change).
◦ Clearly define the goal that you want to
achieve. (What are you trying to achieve?).
◦ Determine what are the inputs and
outputs.
CS002
5
2. Understand the problem
◦ Gathering data relative to the problems which
your solution can be achieved.
◦ Do not automatically discard any information.
CS002
6
3. List possible solutions to the problem
◦ Generate as many potential solutions as
possible.
◦ List the features for each possible solution.
CS002
7
4. Select the best way to solve the problem
from the list of alternative solutions.
◦ Establish criteria to help when choosing the
solution
◦ Select the best solution.
CS002
8
5. List instructions that enable you to solve
the problem using the selected solution
(Do Stage).
◦ Planning:
Create a numbered, step-by-step set of
instructions
CS002
9
6. Evaluate the solution(Review and Revise)..
◦ Test the solution
Are the results accurate?
Does the solution solve the original problem?
Does it satisfy the needs of the user?
Is it acceptable to the user?
CS002
10
Now let’s put problem-solving into
action!
CS002
11
Problem description Steps Outcome. Eman is a doctor and she isn’t in regular contact with her old friends. She is getting caught up in the demands of work and family and she’s not setting aside time specifically for old friends.
Identify the problem. Problem: wanting to get contact to the old friends. Goal: get contact to the old friends.
Understand the problem. Facts: Searching for e-mail, telephone, home address…etc.
list possible solutions to the problem
1. Schedule a time e.g. every Sat. to contact by writing emails letters. (Cheap - long time to write a letter – no need to be at the same time available).
2. Buy plan tickets to visit them. (real contacts, costly, must have free time to do it) 1. Using phone call to contact.(real contact,
acceptable costs, need short free time ). Select the best solutions to
the problem. Criteria: 1- Time. 2-Cost. 3- Interactivity. So, phoning would be the best.
List instructions (Do Stage) Start calling tomorrow at launch time. Schedule every Sunday at 10 am for calling Write notes to remember on mirror and… Tell the friend in advance to be ready.
Evaluate the solution (Review and Revise).
Had great conversation but set a timer when she’s talking so that she will not spend more on the phone bill.
CS002
12
Problem
description
Steps Outcome.
Today is the final
day for Abeer in
high school, she &
her family
gathered to decide
which university
for here to attend.
Identify the problem. Problem: Enrolling in a university & department
Goal: Name university and department that she will
this year.
Understand the problem. Facts:
Searching for Universities available.
Knowing her grades, hobbies, specialties
and Gender.
list possible solutions to the
problem
go local university.(speed, not have desired
section, monthly reward)
go a broad.(trip expenses, have desired section,
free enrolment, monthly reward)
go private university.( trip expenses very
expensive , school I prefer, enrolment is not free )
Select the best solutions to
the problem.
Criteria:
1- enters high ranked university and
desired section.
2- Not expensive.
3- Free.
So, solution 2.
List instructions (Do Stage) 1. Send an enrol application to the university.
2. Wait for reply.
3. Pack your stuff, go to university.
4. Attend first day.
Evaluate the solution
(Review and Revise).
I felt lonely, grades were low.
So, must change solution(revaluate)
CS002
13
Algorithmic Solutions Steps involved in following a set of instructions. The solution will be the same each time the algorithm is
followed. Most computers use algorithmic types of problems.
Heuristic Solutions Solutions that can’t be reached by following a direct set of
steps. Created based on knowledge and experience…and by trial and
error.
The results may not produce the same results each time the algorithm is executed.
Artificial intelligence deals with heuristic types of problems.
CS002
14
The instructions that will result in the best
solution.
The result may be:
More Efficient
Faster
More Understandable
More Maintainable
Reusable
CS002
15
The outcome of the program
May take any form:
Printout
Updated files
Output to monitor, speakers, etc.
CS002
16
The set of instructions that make up the
solution after they have been coded into a
particular computer language.
Although we won’t be actually writing programs, at least not in any
specific language, this is what we will be working toward throughout
this course!
CS002
summary
CS002 17
There are 6 steps in problem solving
There are two types of problem solutions :
algorithmic and heuristic.
Algorithmic solutions reached step by step
Heuristic solutions through trial and error
Recommended