Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Introduction to Computers and Programming Essential feature of a computer is the separation of operations and data.

Similar presentations


Presentation on theme: "1 Introduction to Computers and Programming Essential feature of a computer is the separation of operations and data."— Presentation transcript:

1

2 1 Introduction to Computers and Programming Essential feature of a computer is the separation of operations and data.

3 2 Hardware Leibnizt 17 th Century (adding machine) Babbage 1835 Turing 1936 Post war: ENIAC 30 tons (needed external wiring) and EDSAC (first stored program) UK – based on Von Neumann Design Now similar design but speed in MIPS and BIBS rather than 6 – 10! The physical components  Accept input, Display output.  Store information.  Perform arithmetic and logical operations  Control sequence of system

4 3 The physical components INPUT OUTPUT Memory (RAM) Secondary Storage, Hard disk, Floppy, Zip, CD Arithmetic and logic unit (ALU) Control Central Processing Unit (CPU)

5 4 The Computer’s Core: CPU and Memory A collection of switches and relays Transforms information User provides input Computer follows instructions Returns output to user Each type understands specific instructions, Opcodes, (IBM or Mac) Communicates with the other parts of the computer.

6 5 RAM (Random Access Memory ) RAM most common type of primary storage RAM can store programs and data temporarily RAM has memory locations with unique addresses Computers can quickly retrieve from RAM RAM is volatile memory it is temporary and constantly changing. Power off — RAM is cleared, whether you saved it or not!, Save to secondary storage.

7 6 Addresses * 01010011 01000011 01001111 01100111 Imagine a stack of letter boxes. Each box has a unique address. Each box has can contain some information (a byte). Each byte has 8 bits which can be a 0 or 1. 0000 0001 3000 3001 3002 64000 : 63999 Low High MemoryMemory Address :

8 7 Computer Software The programs Systems Applications Like English, programs written in a programming language have their own syntax. Unlike English there are no irregular verbs and exceptions to be learnt

9 8 Programming Languages Over 200 languages Language depends upon task Assembly, COBOL, Logo, C++, Pascal, FORTRAN, BASIC.

10 9 Programming languages (Cont)  Machine languages 11000000 000000000001 000000000010  Add contents of memory location 1 to contents of memory location 2  Horrid to write programs! Assembly  ADD 12  Needs an assembler to translate to machine language Opcode

11 10 Programming Languages (cont) Levels of Computer Languages: Low (long way from English) machine language, assembly High (Closer to English) COBOL, Pascal, FORTRAN, Logo, Basic Mid-level? C, C++

12 11 Programming Languages (cont) Procedural languages focus on tasks. Breaks programs down into sub-procedures. Pascal, Fortran. Object-Oriented languages (OOP) focus on data, looks at data and operations that are performed on the data. Java, Smalltalk Special Languages (very high) Prolog, Lisp

13 12 However C ++, COBOL, FORTRAN, Pascal, BASIC, Prolog etc. Computer Can’t Understand English! OR Computer Understand Machine language.

14 13 Translation/Interpretation Translation to Machine Language Interpreter Compiler/linker Assembler

15 14 Compilation Creating and executable file with C++ source code compiler - h-files used object code linked to libraries.exe file

16 15 Developing/Constructing Programs

17 16 Problem Solution and Software Development Phase I: Analysis, Design and Development. Phase II: Documentation Phase III: Maintenance

18 17 A Close Look at Phase I 1. Analyse/Solve the problem 2. Develop/Design a solution produce an algorithm 3. Code the solution 4. Test/Verify the program

19 18 A Close Look at Phase I Problem analysis and Solution finding Need a process of solving a problem and then getting the solution onto a computer. Initially YOU need to know how to solve a problem in English, before you can get a computer to tackle the problem. The problem is that computers do not understand English. You need to get the solution into a form the computer understands.

20 19 Problem Solving: generalized problem-solving approach 1.Understand the problem 1.Roughly sketch out 2.Identify inputs/outputs unknowns, assumptions. 3.Notation: sketch out ideas for variable names and types. 4.Sketch out any equations/relations that you know or that might be useful. 2.Devise a plan 1.Write the plan down! 2. Check the plan 3.Implement the Plan 1.Check the implementation 4.Examine Solution

21 20 1. Understand The Problem Draw a figure. What is the data, Try to introduce suitable variables. What sort of variables should they be? What is the unknown? What is known? Are there any conditions that need satisfying?  e.g. A grading program will have different grades according to exam scores. Are the conditions sufficient to determine the unknown? Or is it insufficient? Or redundant? Or contradictory? If not, what do you need to determine the unknown? Can you write the conditions down?

22 21 Output of Step 1 One or more pages of rough work, nothing formal Good idea of problem requirements Good idea of inputs, outputs, constants, conditions, assumptions.

23 22 2. Devise a Plan Find the connection between the data and the unknown.  You might need to consider separate problems if you can’t find an intermediate connection. You should eventually come up with a plan of the solution. Have you seen the problem before? Have you seen the same problem in a slightly different form? Do you know a related problem? Do you know a theorem that could be useful?  Pythagoras?

24 23 2. Devise a Plan Continued look at the unknown! And try to think of a familiar problem having the same or a similar unknown. Is there a problem related to yours and solved before. Can you use it? Can you use its method? Should you introduce some other element in order to make its use possible? Can you restate the problem? If you cannot solve the proposed problem, try to solve some related problem first. Can you solve a simplified form with particular conditions.

25 24 2. Devise a Plan Continued Can you imagine a more accessible related problem? A more general problem? A more special problem?  E.g. If you need to count the number of words in a file. Solve the sub-problem of counting the number of words on a line first. Can you solve a part of the problem? Keep only some of the conditions

26 25 2. Devise a plan continued Can you derive something useful from the data? Can you think of other data appropriate for determining the unknown? Can you change the unknown or the data, or both if necessary, so that the new unknown and the new data are nearer to each other? E.g. Change from one coordinate system to another, Did you use all the data? Did you use all the conditions?

27 26 Devise a plan continued Is there a different way of solving the problem. Can you use this to check your solution? is it better?

28 27 Output of Step 2 Top Down Design A formal written design. State inputs, outputs Write steps to process input unambiguously using a semi formal notation (PDL, Flowchart or structure diagram? Can you translate each step of the plan into C++ easily? No … Go back and refine Verification/testing procedures documented (A test table).

29 28 3. Coding the Solution Check code for each step Incrementally. Can you see clearly that the step is correct? Can you prove that it is correct? How would you prove it is correct? i.e. what are the tests you would use to prove your plan?

30 29 4. Examining the solution Check the result? Use tests identified in step 2. Can you use the solution, or the method, for some other problem?

31 30  So find a solution, write it down in English.  Write it down more formally in Pseudo-code (PDL), or as a structure diagram or a flow chart.  Start your programming environment and convert your pseudo-code to C++  Tell the computer to convert the C++ to machine language (compile)  Tell the computer to load the machine language into memory and execute (Run). Summary

32 31 Algorithms An algorithm is simply the technical word for your solution/Plan. It is the step by step sequence of instructions to complete a task it will consist of: Sequences Selection Iteration Invocation

33 32 Example of Top Down Design Making Cups of Coffee Problem: Make 10 cups of coffee Initial (Top) Plan Make 10 cups of coffee Refinement 1 Repeat 10 times Make a cup of Coffee End repeat

34 33 Example of Top Down Design Making Cups of Coffee Refinement 2 Repeat 10 times Put coffee in Cup Put boiling water in Cup End repeat

35 34 Example of Top Down Design Making Cups of Coffee Refinement 3 Repeat these tasks 10 times 1. Get mug out of cupboard 1. End Repeat 2. Get Coffee out of cupboard 3. Fill Kettle 4. Put Kettle on to boil 5. Repeat 10 times 1. Put Coffee in cup 2. If Kettle boiled put water in cup 3. If wanted Add milk 4. If wanted Add sugar 6. End repeat

36 35 Another Example Linear Search Problem: Find the largest number in a list of numbers.

37 36 Design Example Linear Search PDL call the 1st number largest call the 2nd number current 1 while we are not finished 2 if current > largest 4 label current as largest 5 call next number in the list current 6 repeat the while 7 output the largest

38 37 Linear Search Flowchart largest = first No Current = Second No Largest = Current Current > Largest? Current = Next No Any more numbers? Display largest No Yes Start Stop

39 38 Phase II Documentation Improve readability You remember Others understand Enables easy maintenance

40 39 What is documentation Your formal design paperwork. Should be detailed enough for any programmer to implement Comments (annotations) actually written into the code.

41 40 Phase III Maintenance Correction of problems after delivery Add features Adapt to changing needs. E.g. Y2K problem Needs good documentation!

42 41 What we are aiming for is Structured Programming Advantages Not one giant step, but breaks in to smaller and smaller chunks. Programmer concentrates on details Easy to do in teams Easy to keep track of development Creates more reliable and robust programs. Makes more possible reuse and extensibility.

43 42 Structured Programming Errors isolated Design written in code Improves reliability Minimizes risk of Failure Faster development Full documentation Maintainability

44 43 Writing Down Solution Designs Flowcharts Pseudo-code Structure Diagrams

45 44 Logical steps Written in English Language independent Labels Indenting for logical structures 1. begin game 1.1 display instructions 1.2 pick a number between 1 and 100 2. repeat turn until number is guessed or seven turns are completed 2.1 input guess from user 2.2 respond to guess 3. end repeat 4. end game 4.1 display end message Pseudo-code/ PDL

46 45 Logical steps represented by standard symbols display instructions get number is number even? YesNo continue Flowcharts

47 46 Structure Diagrams Inventory Control Program Enter dataDo Calculations Display report 123

48 47 Summary No Magic Bullet Adopt good practice (structured programming) Apply Three Phases Phase I – analyse, develop algorithm, code test Phase II – Document Phase III - Maintain


Download ppt "1 Introduction to Computers and Programming Essential feature of a computer is the separation of operations and data."

Similar presentations


Ads by Google