Problemsolving with Computers Outline Computer System 5 Steps
Problem-solving with Computers
Outline Ø Computer System Ø 5 Steps for producing a computer program Ø Structured program and programming § 3 types of control structure Ø Algorithm § Tools for describing an algorithm § Examples of algorithm and programs 2
Computer System Ø A Computer system is a collection of hardware and software. Input Software Hardware Output 3
Computer System Ø Hardware § the electric, electronic, and mechanical equipment that makes up a computer Ø Software § the series of instructions that tells the hardware how to perform tasks 4
Computer System Ø Hardware : requires a series of instructions to carry out its processing function. Ø Software : a group of instructions (computer program) which command a computer to take action and to make decision. Ø Without software, hardware is useless; hardware needs the instructions provides by software to process data into information. 5
Computer Program (Software) Ø A program is a sequence of instructions suitable for processing by a computer Ø Programs are written § for controlling the computer hardware o Instructions in a program tell the hardware to perform a task § for solving problems. Without software, the hardware doesn’t know what to do !! 6
Computer System Ø Algorithm § describe the method in a sequence of steps to get a computer to perform a task. Ø An Algorithm must be translated into a program by coding in a programming language. 7
Computer Program (Software) Ø The activities of expressing an algorithm of a problem and translating the algorithm as a program is called programming. The most fundamental concepts of computer science is programming and algorithm. 8
5 Major Steps for Producing a Computer Program Ø Problem Definition § Understanding the problem Ø Problem Design § Proposing the solution Ø Problem Coding § Implementing the solution Ø Problem Testing § Testing the solution Ø Problem Documentation § Writing the document 9
Problem Definition Ø Have a clear understanding the problem Ø What we want to do § specify objectives § specify the desired input and output 10
Problem Design Ø Proposing the solution § Top-down design with modularity approach using hierarchy chart § Input/output and data structure design § Algorithm design with certain tools o Pseudocode o Flowchart 11
Problem Coding Ø Implementing the solution § Write (code) the program from algorithm by using selected programming language Program = Algorithm + Data Structure 12
Problem Testing Ø Testing the solution § Structured walk-through § Desk checking § Sample test data 13
Problem Documentation Ø Writing the document § User documentation § Program documentation Ø Program Maintenance 14
Structure Program and Programming Ø Technique for organizing and coding computer programs § Hierarchy of modules is used § Single entry § Single exit point § Control is passed downward through the structure without unconditional branches to higher levels of the structure 15
Structure Program and Programming Ø Module § A self-contained activities that contributes a specific subtask. Ø The overall task is done in a logical order of the hierarchy of the subtasks. 16
Example of Top-down Design (with Modularity approach using a hierarchy chart) Payroll System Input Payment Processing Compute Pay Regular Pay Overtime Pay Output Compute Payroll Deduction Tax Payroll Saving 17
Problem Solving with Computer Problem Difficult in solving big problem Problem solving phase Solution in a algorithm form Solution in a computer program Implementation 18 phase
Structure Program and Programming Ø 3 types of control flow (structure) § Sequence § Selection or branching § Iteration or looping Explain on the blackboard 19
Sequence Statement #1 Statement #2 Statement #3 Example Statement #1 Statement #2 Statement #3 read X read Y Z=X+Y print (“The sum of X and Y is ”, Z) 20
Selection if condition then Statement #1 else Statement #2 False Statement #2 condition True Statement #1 21
Selection if condition then Statement #1 else Statement #2 Example read X read Y if ( X > Y ) then print (“ X is greater than Y”) else print (“ Y is greater than X”) 22
Iteration (Repeat Loop) repeat Statements until condition Statements condition True False 23
Iteration (Repeat Loop) repeat Statements until condition Example read X read Y repeat print X X = X+1 until (X >Y) 24
Iteration (While Loop) while condition do Statements False condition True Statements 25
Iteration (While Loop) while condition do Statements Example read X read Y while (X<=Y) do print X X = X+1 26
Iteration (For Loop) for i = 1 to n do Statements 1 i i <= n False True Statements i=i+1 27
Iteration (For Loop) for i = 1 to n do Statements Example read X read Y for i = 1 to X do print (“The value of i is ”, i) 28
- Slides: 28