chapter 1v012015 final

5
1/14/2015 1 Learning Outcomes Explain the concepts of problem-solving and structured programming. References: Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012. Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006. Contents Recognize 6 steps in problem solving 1 . Types of problem 1 . Difficulties with problem solving 1 Recognize 7 steps in program development process 2 . Pseudocode and developing an Algorithm 2 References: Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012. Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006. Problem Solving in Everyday Life Problem-solving process (6 steps) –Identify the problem –Understand the problem –Identify alternatives –Select the best way to solve the problem –List the instructions –Evaluate the solution What to do? Knowledge base required Other acceptable methods All steps required Check to see if result is correct Problem Solving in Everyday Life Example : You are doing assignment at home, and you are hungry Identify problem : you are hungry Understand the problem : you need food Identify Alternatives : 1.) look for mum 2.) go to kitchen and look for some food 3.) go to kitchen and prepare food yourself 4.) make a food delivery order 5.) go out to have a meal in restaurant / hawker center

Upload: allen-fourever

Post on 07-Dec-2015

214 views

Category:

Documents


1 download

DESCRIPTION

gsdfgsdg

TRANSCRIPT

Page 1: Chapter 1v012015 Final

1/14/2015

1

Learning Outcomes� Explain the concepts of problem-solving and structured

programming.

References:Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012.

Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006.

Contents� Recognize 6 steps in problem solving1.

� Types of problem1.

� Difficulties with problem solving 1

� Recognize 7 steps in program development process2.

� Pseudocode and developing an Algorithm2

References:

Problem Solving and Programming Concepts (9th Edition) . Maureen Sprankle, Jim Hubbard, Pearson Education Limited 2012.

Simple Program Design. A step by step approach (5th Edition). Lesley Anne Robertson. Cengage Learning 2006.

Problem Solving in Everyday Life� Problem-solving process (6 steps)

–Identify the problem

–Understand the problem

–Identify alternatives

–Select the best way to solve the problem

–List the instructions

–Evaluate the solution

What to do?

Knowledge base required

Other acceptable methods

All steps required

Check to see if result is correct

Problem Solving in Everyday Life� Example : You are doing assignment at home, and you

are hungry

� Identify problem : you are hungry

� Understand the problem : you need food

� Identify Alternatives :

� 1.) look for mum

� 2.) go to kitchen and look for some food

� 3.) go to kitchen and prepare food yourself

� 4.) make a food delivery order

� 5.) go out to have a meal in restaurant / hawker center

Page 2: Chapter 1v012015 Final

1/14/2015

2

Problem Solving in Everyday Life� Example (continued)

� Select the best way

� Method 1 : you aren’t kid anymore ☺

� Method 2 : might be a good idea

� Method 3 : you might not have time since you are doing assignment.

� Method 4 : might be expensive

� Method 5 : you might not have time since you are doing assignment.

After some consideration, let say you choose method 2

Problem Solving in Everyday Life� Example (continued)

� List out the instruction

� Go out from the room

� Go to kitchen

� Search the table, cabinet, refrigerator for food

� Consume the food

� evaluate the solution

� Is the solution help to solve the problem?

� Is the solution solve the problem efficiently?

� Should we follow the same solution next time?

Types of problem� Algorithmic solutions

� Can be solved with a series of actions (the algorithm)

� Log on to an e-mail account

� Withdraw cash from ATM machine

� Heuristic solutions (rule of thumb)

� Based on knowledge & experience

� Requires a process of trial and error

� Add Salt to food (during cooking)

� Buying the best stock

Types of problem – (cont)� 6-steps can be used for both problems

� But step 6 (for heuristic solutions)

� Correctness and appropriateness far less certain

� May need to iterate (repeat) many times

� Same solution may not work all the time

� Most problems require a combination of the two kinds of solutions

� Driving a vehicle

� Fix a malfunction computer

Problem solving with computers

� Computers built for dealing with algorithmic solutions

� Write instruction step by step

� Heuristic solutions requires (Artificial) intelligence

� The program can make decision like human when for each situation base on previous solution

� Need to transform into algorithmic format

Difficulties with problem solving� Why?

� One or more steps in Problem solving process are not completed adequately.

� Problem-solving process requires time and practice

� Problem solving on the computer.

� Problem with writing the instruction

� E.g. List 5 numbers and pick the largest one.(Can you explain/list all the steps required?)

� The computer is a tool that will perform only tasks that the user can explain.

� All steps must be in proper order

Page 3: Chapter 1v012015 Final

1/14/2015

3

7 Steps of Program Development Process

� Programming can be defined as the development of a solution to an identified problem, and the setting up of a related series of instructions that will produce the desired resultsDefine the Problem

To help with initial analysis, the problem should be divided into three separate components:

• the inputs

• the outputs

• the processing steps to produce the required outputs

7 Steps of Program Development Process

1. Define the problem

2. Outline the solution

3. Develop an algorithm (based on the outline)

4. Test the algorithm (for correctness)

5. Code the algorithm (into a specific programming language)

6. Run the program (on the computer)

7. Document & Maintain the program

1 Define the Problem� To help with initial analysis, the problem should be

divided into three separate components:

• the inputs

• the outputs

• the processing steps to produce the required outputs

� Use IPO chart (Input Process Output chart)

1 Define the Problem� Example:

� Shop A is offering a 20% discount for all products. Calculate the payment for the customers.

� Input

� Discount rate, original price of the products

� Output

� payment

� Process

� Calculate payment

2 Outline the Solution� This initial outline is usually a rough draft of the

solution and may include:

• The major processing steps involved

• The major subtasks (if any)

• The user interface (if any)

• The major control structures (e.g. repetition loops)

• The major variables and record structures

• The mainline logic

2 Outline the Solution� Example (step by step to solve the problem) :

� Get the price of product purchase by the customer

� Get the discount rate

� Calculate the discount amount

� Calculate the payment after discount

� Display the payment amount to the customer

Page 4: Chapter 1v012015 Final

1/14/2015

4

3 Develop the Outline into an Algorithm

� The solution outline developed in Step 2 is 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

� Develop flow chart and pseudocode from IPO chart

4 Test the Algorithm for Correctness

� This step is one of the most important in the development

of a program, and yet it is the step most often forgotten

� The main purpose of desk checking (test the algorithm) is

to identify major logic errors early, so that they may be

easily corrected

� Early error identification is better because will save time

and cost

5 Code the Algorithm into a Specific

Programming Language

� Only after all design considerations have been met

should you actually start to code the program into your

chosen programming language (e.g c++, c , Java)

6 Run the Program on the Computer

� This step uses a program compiler and programmer-

designed test data to machine test the code for syntax

errors and logic errors

� Syntax error – any violation of rules of the language

results in syntax error

� Logic errors – these errors are related to logic of the

program execution

7 Document and Maintain the Program

� Program documentation should not be listed as the

last step in the program development process, as it is

really an ongoing task from the initial definition of the

problem to the final test result

� Documentation involves both external documentation

and internal documentation that may have been coded

in the program

Algorithms

� A program must be systematically and properly

designed before coding begins

� This design process results in the construction of an

algorithm

Page 5: Chapter 1v012015 Final

1/14/2015

5

What Is an Algorithm?� An algorithm is like a recipe: it lists the steps involved

in accomplishing a task

� It can be defined in programming terms as a set of

detailed, unambiguous and ordered instructions

developed to describe the process necessary to

produce the desired output from a given input

Tools to build algorithm� From algorithm, we also can uses:

� Pseudocode (more English-like)

� Flowcharts

� Nassi-Schneiderman diagrams

As all above are all popular ways of representing algorithms

Summary� The steps in program development were introduced

and briefly described below: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