Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving.

Similar presentations


Presentation on theme: "School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving."— Presentation transcript:

1 School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving

2 School of Computing Science CMT1000 © Ed Currie Middlesex University 2 Problem Solving Programming is all about solving problems. A program is just a set of instructions that describe how to solve a particular problem: –written in a language that a computer can understand.

3 School of Computing Science CMT1000 © Ed Currie Middlesex University 3 Problem Solving There are 4 steps to solving a problem: UNDERSTAND THE PROBLEM WORK OUT A PLAN SORT OUT THE DETAILS TEST AND EVALUATE The same applies to writing a program too!

4 School of Computing Science CMT1000 © Ed Currie Middlesex University 4 Understand the Problem Most important step! What information do we know? What do we want to happen? How can one lead to the other? In programming –this involves talking to customers –what do they want?

5 School of Computing Science CMT1000 © Ed Currie Middlesex University 5 Understanding a Programming Problem For the programming exercises do you understand what you are required to do do you understand the programming constructs you will need to use –(if not make sure you understand them before you start) do not start to write a program until you have understood the problem

6 School of Computing Science CMT1000 © Ed Currie Middlesex University 6 Different Solutions I want to eat Pizza –… I have lots of options Go to a Pizza Restaurant Phone a Pizza delivery place Cook a frozen one Make one myself

7 School of Computing Science CMT1000 © Ed Currie Middlesex University 7 Same Plans - Different Details Pizza Restaurant –Pizza Express v Pizza Hut –Leicester Square v local Frozen –buy one with toppings –add your own toppings Make your own –different recipes for base

8 School of Computing Science CMT1000 © Ed Currie Middlesex University 8 Different Solutions There are many different ways to achieve a task Trade-off between advantages and disadvantages of each What is best depends on the situation Given a plan –still different ways to do it Programming is about devising plans –the above all apply

9 School of Computing Science CMT1000 © Ed Currie Middlesex University 9 Algorithms A plan for solving a problem by following a sequence of rules is called an algorithm An algorithm should be (at least) –complete (i.e. cover all the parts) –unambiguous (no doubt about what it does) –deterministic (only 1 possible result) –finite (it should finish) Exercise: Decide whether the noughts and crosses solution is an algorithm.

10 School of Computing Science CMT1000 © Ed Currie Middlesex University 10 First write the algorithm  First write the algorithm......Writing a program from it will then be easy!  It is easier to write a set of rules for playing noughts and crosses than writing a program to do it. The former is one step on the way to writing a program.

11 School of Computing Science CMT1000 © Ed Currie Middlesex University 11 Breaking A Problem Down You can probably execute some pizza plans without further instruction eg heat up a frozen pizza  Others need to be broken down into smaller steps  eg make your own pizza or go to a Pizza Hut Go to restaurant Order Pizza Eat Pizza Pay Bill Go home

12 School of Computing Science CMT1000 © Ed Currie Middlesex University 12 Sub-tasks “Go to restaurant” may need to be broken down even further. Go to restaurant: –Go to Leicester Square Tube Station –Turn right out of tube –Go about 300 m –Its on the right, on the corner

13 School of Computing Science CMT1000 © Ed Currie Middlesex University 13 Subtasks Break down each plan until you get to steps you know how to do Programs are written in the same way –you must break the task down into steps the computer can execute –there are different ways of doing it

14 School of Computing Science CMT1000 © Ed Currie Middlesex University 14 Test And Evaluate Step through the solution Make necessary changes Check the results –are they valid –is it a solution to problem –is it what was wanted

15 School of Computing Science CMT1000 © Ed Currie Middlesex University 15 Testing Programs step through on paper ("DRY RUN") then run on computer try lots of different test cases

16 School of Computing Science CMT1000 © Ed Currie Middlesex University 16 Summary We solve a problem with a computer by devising a plan (an algorithm) We break the plan down into steps the computer can do (a program) There are many plans and many ways of breaking them down Which is best will depend on the situation


Download ppt "School of Computing Science CMT1000 © Ed Currie Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 1B: Problem Solving."

Similar presentations


Ads by Google