dct 1123 problem solving & algorithms introduction to programming

28
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Upload: bryan-lambert-barber

Post on 25-Dec-2015

234 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

DCT 1123PROBLEM SOLVING &

ALGORITHMS

DCT 1123PROBLEM SOLVING &

ALGORITHMSINTRODUCTION TO PROGRAMMINGINTRODUCTION TO PROGRAMMING

Page 2: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

CONTENTSCONTENTS• COMPUTER PROGRAMMING CONCEPTS• PROBLEM SOLVING OVERVIEW• ALGORITHM OVERVIEW (PSEUDOCODE &

FLOWCHART)

Page 3: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

What is Computer Programming?

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. 

Page 4: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING
Page 5: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

• 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 LanguageProgramming Language

Page 6: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

• 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 LanguageProgramming Language

Page 7: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Programming LanguageProgramming Language

Page 8: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Top Programming Language Rank

Top Programming Language Rank

http://codeeval.com

Page 9: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 10: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 11: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 12: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 13: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 14: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 15: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

History of ProgrammingHistory of Programming

Page 16: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

What is Problem Solving ?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

Page 17: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps in Program Development

Steps in Program Development

1.Define the problem2.Outline the solution3.Develop the outline into an

algorithm4.Test the algorithm for correctness5.Code the algorithm into a specific

programming language6.Run the program on the computer7.Document and maintain the

program

Page 18: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 1: Define the ProblemSteps 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

Page 19: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 2: Outline the SolutionSteps 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

Page 20: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 3: Outline into Algorithm

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

Page 21: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 4: Test the AlgorithmSteps 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

Page 22: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 5: Code the AlgorithmSteps 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.

Page 23: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 6: Run the programSteps 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.

Page 24: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Steps 7: Document and maintain the program

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.

Page 25: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Algorithm OverviewAlgorithm 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

Page 26: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Important Properties of Algorithms

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

Page 27: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

Algorithm ExampleAlgorithm 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

Page 28: DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING

14/08/14