1 / 47

Introduction to Computers and Programming

Introduction to Computers and Programming. Essential feature of a computer is the separation of operations and data. Hardware. Leibnizt 17 th Century (adding machine) Babbage 1835 Turing 1936

halla-baker
Download Presentation

Introduction to Computers and Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Hardware • Leibnizt 17th 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

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

  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.

  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.

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

  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

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

  9. Opcode 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 1 2 • Needs an assembler to translate to machine language

  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++

  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

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

  13. Translation/Interpretation • Translation to Machine Language • Interpreter • Compiler/linker • Assembler

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

  15. Developing/Constructing Programs

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

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

  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.

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

  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?

  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.

  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?

  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.

  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

  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?

  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?

  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).

  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?

  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?

  30. Summary • 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).

  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

  32. Example of Top Down DesignMaking 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

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

  34. Example of Top Down DesignMaking Cups of Coffee Refinement 3 Repeat these tasks 10 times • Get mug out of cupboard • End Repeat • Get Coffee out of cupboard • Fill Kettle • Put Kettle on to boil • Repeat 10 times • Put Coffee in cup • If Kettle boiled put water in cup • If wanted Add milk • If wanted Add sugar • End repeat

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

  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

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

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

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

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

  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.

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

  43. Writing Down Solution Designs • Flowcharts • Pseudo-code • Structure Diagrams

  44. Pseudo-code/ PDL • 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

  45. Flowcharts display instructions get number Yes No is number even? continue Logical steps represented by standard symbols

  46. Structure Diagrams Inventory Control Program Enter data 1 Do Calculations 2 Display report 3

  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

More Related