Chapter 1

advertisement
DCT 1123
PROBLEM SOLVING
& ALGORITHMS
INTRODUCTION TO PROGRAMMING
CONTENTS
• COMPUTER PROGRAMMING
CONCEPTS
• PROBLEM SOLVING
OVERVIEW
• ALGORITHM OVERVIEW
(PSEUDOCODE &
FLOWCHART)
What is Computer Programming?
• Writing software, computer programs, is
describing how to do something.
• It is a lot like writing down the steps it
takes to do something - a process.
• So, writing a computer program can be like
composing music, like building a house,
like creating lots of stuff.
Programming Language
• Just like we have many different
languages in use throughout the
world for us humans to communicate
with, there are different languages
that we use to communicate with a
computer.
• Computer languages are used to tell
the computer what to do, you instruct
it.
Programming Language
• We need a language to communicate
with a computer.
• Computer languages are used to tell
the computer what to do, you instruct
it.
• Once it is written, the programmer
uses a compiler to turn it into a
language that the computer can
understand.
• Most software written today is using
high level language such as C++,
JAVA and etc.
Programming Language
Top Programming Language Rank
http://codeeval.com
History of Programming
History of Programming
History of Programming
History of Programming
History of Programming
History of Programming
History of Programming
What is Problem Solving ?
• The process of working through
details of a problem to reach a
solution.
• Problem solving may include
mathematical or systematic
operations and can be a gauge of an
individual's critical thinking skills.
14/08/14
Steps in Program Development
1. Define the problem
2. Outline the solution
3. Develop the outline into an algorithm
4. Test the algorithm for correctness
5. Code the algorithm into a specific
programming language
6. Run the program on the computer
7. Document and maintain the program
Steps 1: Define the Problem
• This steps involves carefully reading
and rereading the problem until you
understand completely what is
required
• The problem should be divided into
three (3) separate components:
– The inputs
– The outputs
– The processing steps to produce the required
output
Steps 2: Outline the Solution
• Once the problem defined, you may
decide to break it down into smaller
tasks or steps, and establish a solution
outline
–
–
–
–
The major processing steps involved
The major subtasks (if any)
The user interface (if any)
The major control structures (e.g. repetition
loop)
– The major variables and record structure
– The mainline logic
Steps 3: Outline into Algorithm
• The solution outline developed in
Steps 2 is then expanded into an
algorithm: a set of precise steps that
describe exactly the tasks to be
performed and the order in which they
are to be carried out
Steps 4: Test the Algorithm
• The main purpose of desk checking
the algorithm is to identify major logic
errors early, so that they may be
easily corrected
• Test data needs to be walked through
each step in the algorithm to check
that the instructions described in the
algorithm will actually do what they
are supposed to
Steps 5: Code the Algorithm
• Only after all design considerations in
the previous four steps have been met
should you actually start to code the
program into your chosen
programming language.
Steps 6: Run the program
• This step uses a programmer compiler
and programmer-designed test data to
machine test the code for syntax
errors
• This steps may need to be performed
several times until you are satisfied
that the program is running as
required.
Steps 7: Document and maintain
the program
• Documentation includes both external
documentation (such as hierarchy
charts, the solution algorithm and test
data result) and internal
documentation that may have been
coded in the program.
• Program maintenance refers to
changes that may need to be made to
a program throughout its life.
Algorithm Overview
• An algorithm is like a recipe; it lists
the steps involved in accomplishing a
task
• In a programming, it is a set of
detailed, unambiguous and ordered
instructions developed to describe the
processes necessary to produce
desired output
• Written in simple English
Important Properties of Algorithms
• Correct
– always returns the desired output for all
legal instances of the problem.
• Unambiguous
• Precise
• Efficient
– Can be measured in terms of
• Time
• Space
– Time tends to be more important
Algorithm Example
• For example, if you want to instruct
someone to add up a list of prices on a
pocket calculator, you might write:
– Turn on calculator
– Clear calculator
– Repeat the following instructions
•
•
•
•
Key in ringgit amount
Key in decimal point
Key in cents amount
Press addition (+) key
– Until all prices have been entered
– Write down total price
– Turn off calculator
14/08/14
Download