prog design

4
Having a Bath Having a Bath Every task that you do can be broken down into main steps. Those steps can often be broken down into smaller steps. This is sometimes called Stepwise Refinement or writing an Algorithm. So a task like having a bath can be broken down into the main things you have to do. Each of those main things can be further broken down into smaller, more detailed steps. Each of these steps will form instructions for performing the task. Main Steps 3. Run the bath 4. Have a bath 5. Dry off Refinements 1.1 Run the hot and cold water 1.2 Add bubble bath 1.3 Check the temperature 1.4 Turn off water 2.1 Get in bath 2.2 Wash yourself 2.3 Pull the plug out 3.1 Get out of bath 3.2 Use towel to dry yourself 3.3 Get dressed

Upload: mrsmackenzie

Post on 09-Jul-2015

272 views

Category:

Education


2 download

DESCRIPTION

Programming Design

TRANSCRIPT

Page 1: Prog Design

Having a BathHaving a BathEvery task that you do can be broken down into main steps. Those steps can often be broken down into smaller steps. This is sometimes called Stepwise Refinement or writing an Algorithm.

So a task like having a bath can be broken down into the main things you have to do. Each of those main things can be further broken down into smaller, more detailed steps. Each of these steps will form instructions for performing the task.

Main Steps

3. Run the bath4. Have a bath5. Dry off

Refinements

1.1 Run the hot and cold water1.2 Add bubble bath1.3 Check the temperature1.4 Turn off water

2.1 Get in bath2.2 Wash yourself2.3 Pull the plug out

3.1 Get out of bath3.2 Use towel to dry yourself3.3 Get dressed

Page 2: Prog Design

Program DesignProgram Design

Before you can write a successful program you will first need to think about what you have been asked to do and how you are going to do it.

Analysis

This is where you think about what you have been asked to do.

You need to write down what the task is in your own words, and how you hope to solve the problem.

Design

This is where you need to think about how you are going to solve the problem.

You need to break the problem down into the main steps to solve it.

Then you need to see if you can break the main steps down into smaller steps.

The smaller steps are called refinements.

Page 3: Prog Design

Design - Algorithm

Main Steps4. Get numbers5. Calculate answer6. Display answer

Refinements1.1 Get first number1.2 Get second number

2.1 Answer = first number + second number

3.1 Display answer on the screen

Analysis

“I have been asked to write a program which will ask the user for two numbers, add them together and display the answer”.

ProblemProblemYou need to write a program which will calculate the sum of two numbers. You should ask the user to enter two numbers. The program should then work out the answer and then display the answer on the screen like this:

number1 + number2 = answer e.g. 3 + 4 =7

Page 4: Prog Design

ProblemProblemYou need to write a program which will ask the user what the answer to two numbers multiplied together is. The program should take in their answer and check if it is right. The program should display a message saying “Well done, Right answer!” If they got it right. It should say “Sorry, the answer is…” if they got it wrong.

Design - Algorithm

Main Steps4. Get answer5. Check answer6. Display message

Refinements1.1 Ask question1.2 Get answer

2.1 If answer is right then 2.2 message = “Well done, Right Answer!”2.3 If answer is wrong then 2.4 message = “Sorry, the right answer is 72”

3.1 Display message

Analysis

“I have been asked to write a program which will ask the user what the answer to 8 * 9 is. The program should read in their answer, check if it is right and display a message saying either “Well done” or displaying the correct answer. ”.