Procedural Programming Lecture 1 - Summer Semester 2016 & Joachim Zumbrägel Faculty of Engineering Institute of Computer Engineering Organizational Issues & Learning Targets 1
Course Organization consists of 6 Lectures 6 Exercises with 6 Homeworkd 8 Practical Trainings provides you with basic knowledge about programming (what an engineer should know) has no exam is passed when you got 96 points from 114 (18 from homework, 96 from the practical training) 3 Exercise We have 6 exercises We discuss topics of the lecture We discuss exercises and their solutions We discuss home exercises. You get points for your home exercise. (3 points per solved homework, all together 18) Home exercises are announced at the end of the exercise and must be solved within 1 week, only hand written solutions accepted 4 2
Practical Training We have 8 different practical trainings Each practical training takes 90 minutes Each practical training consists of - homework (3 points) - a test in the beginning of each practical training (3 points) - the practical training itself (6 points) => 12 points per practical training 96 POINTS FOR ALL PRACTICAL TRAININGS 5 Practical Training (expected Schedule) R EGISTRATION within next 7 days, until Tuesday the 19 th of April 2016 http://ti.uni-due.de/ti/en/education/ i d /ti/ / d ti /teaching/ss16/pp/lab/registration/index.php /l i t ti /i h Time schedule and group list will be announced after registration deadline Tuesday, starting at 12:00 Wednesday, starting at 15:45 6 3
Schedule Date Le. (2h) Ex. (2h) P (2h) Topic of the practical training Tu 12.04.16 L1 Tu 19.04.16 L2 Tu 26.04.16 E1 Tu 03.05.16 E2 Tu 10.05.16 L3 Tu 17.05.16 Pfingstferien Tu 24.05.16 L4 P1 Variables, Data Types, Statements, Hello World Tu 31.05.16 L5 P2 Boolean expressions, Conditional Executions Nested Tu 07.06.16 E3 P3 Finite and Infinite Loops, Break and Continue Tu 14.06.16 L6 P4 Functions: Parameters and Arguments, Void Tu 21.06.16 E4 P5 Arrays Tu 28.06.16 E5 P6 Addressing: Direct and Indirect Addressing to Pointers Tu 05.07.16 E6 P7 Strings and Files Tu 12.07.16 P8 Math Functions, Linked Lists, and Binary Trees Tu 19.07.16 RT Repetition Date for P1 P8, used for missed labs 7 Learning Targets (1/2) After completion of this course, the student: is able to understand and analyze a logical problem. This comprises a clear definition of the problem, and a statement on where the core of the problem lies, is furthermore able to propose a potential way, method or approach that promises to lead to a solution, e.g. understands and is able to apply standard problem solution approaches like reduction, 8 4
Learning Targets (2/2) can formalise the proposed problem solving in a generally accepted (algorithmic) manner, by cutting it down into atomic elements of procedures and represent these in pseudo-code or in form of a flowchart, understands the terminology involved in this subject, and can explain relevant terms like computer, program, algorithm, structure, sequence and selection and repetition, operator and operand, function, iteration, recursion, etc. 9 Literature 5
Literature V. Anton Spraul (2012) Think like a programmer, an introduction to creative problem solving, no starch press. Arthur Whimbley, Jack Lochhead (1986) Problem Solving & Comprehension, Lawrence Erlbaum Associates, Inc. Nell Dale, Michael McMillan, Chip Weems, Mark A. Headington (2002) Programming and Problem Solving with Visual Basic.NET, Jones & Bartlett Learning. Wolfgang P. Kowalk (1996) System, Modell, Programm. Vom GOTO zur objektorientierten Programmierung, Spektrum Akademischer Verlag. Dietrich Boles (2007) Programmieren spielend gelernt mit dem Java-Hamster-Modell, Vieweg+Teubner Verlag. 11 What is programming (good for)? 6
Writing a computer program is only one step in the Program Development Process 13 Implementation is the second step in the Program Development Process Programming or Coding is the process of writing a program for a computer in order to solve a problem. Procedural programming is a programming paradigm, where a number of Simple (only one part of the solution), Independent (separation of concerns), and reusable (by procedure calls) program pieces (modules) constitute a program as a whole. 14 7
Programming requires background knowledge, experience, creativity and a problem-solving stance How does a computer execute a program? How to code a program that implements an algorithm? How to design an algorithm giving instructions for solving a problem? How to handle problems such that a computer can assist in solving it? 15 Mind the gap! (1/2) Computers allow for computing concrete models of real systems + System in Reality Component Characteristic Degree of abstraction Characteristic Manipulation AbstractedModel Attribute / Element Value Method By abstraction we simplify the complexity of a system reducing it to a model, which considers only relevant parts of the problem to be solved. 16 8
Mind the gap! (2/2) The state of a model is the total of its actual values, which gives us information. We make use of this information to derive knowledge about systems, which helps us to understand and to solve problems. Wisdom Knowledge Information Data Data is information in a form that a computer can use it. It comes in many forms such as: letters, words, number, etc. 17 Problem-Solution (1/3) Changing the model state involves changing its attribute values (data). An algorithm gives a sequence of instructions to change attribute values, which results a state-changing flow of the model. Procedural modelling is based on the classic algorithm concept. Problem-solving techniques and strategies can be applied to cope with a model s complexity. 18 9
Problem-Solution (2/3) Algorithm isa logical sequence of instructions for solving a problem in a finite amount of time using a finite amount of information. Recipe Construction Manual Wording of a law 19 Problem-Solution (3/3) An algorithm is executed by a processor, which can be a human or a computer depending on its representation (language). Program Data and instructions written in a programming language for carrying out operations that are used by a computer to solve a problem. Programming is the act of reformulating a problem solving approach (an algorithm) in a programming language (as a program). Compiler and Interpreter are tools to translate a program written in a high-level programming language to machine code (binaries), thereby the gap between different levels of abstraction. 20 10
Computer as program processor Computer one that computes. It is a programmable device that can manipulate data. In 1945, John von Neumann published a conception for constructing universal computer systems, the von Neumann Computer. These computer architectures were successors of the ENIAC system. Institute for Advanced Study in Princeton Founder of Computer Architecture 21 Components of Von Neumann Architecture 1. Input unit: accepts data to be processed from environment. 2. Control unit: controls the other components so that instructions (program) are executed in correct sequence. 3. Main memory (programs and data): an ordered sequence of equaly sized storage cells with a distinct address, each capable of holding a piece of data. 4. Arithmetic logic unit: performes arithmetic (addition, division, etc.) and logical operations (comparing two values). 5. Output unit: presents results of processing to environment. 22 11
The fetch-execute cycle Central Processing Unit (CPU) is made up of ALU and Control Unit. It executes the instructions (program) stored in the memory. 1. The Control Unit retrieves (fetches) the next code instruction (as indicated by program counter) from memory. DATA and INSTRUCTIONS 2. The Instruction is translated into control signals. 3. The control signals tell the appropriate unit (ALU, Memory, I/O) to perform (execute) the instruction. PROGRAM COUNTER 4. The sequence repeats from Step 1. 23 Example of A := B+C in 3-address-code (3AC) Address Content of storage cell Comments 00000 adr 00008 := con 7 Assignment of cell B with value 7 00001 adr 00009 := con 5 Assignment of cell C with value 5 00002 adr 00007 := val 00008 + val 00009 Arithmetic operation add... 00007 12 Storage cell for variable A 00008 7 7 7 Storage cell for variable B 00009 5 5 Storage cell for variable C Program Counter state: 00000 00001 00002... 24 12
Role of Man and Machine in Problem-Solving Computer is a powerful tool that performs: Faster More reliable With greater memory* then we could do by hand. But, the computer is NOT intelligent. WE specify what to do and how by conducting a relatively mechanic act named programming. Solving problems is a creative task, which requires development of proper solution approaches to complex and sufficiently understood problems. * Human working memory is 7 +/-2 pieces of information 25 1.1 Problem Analysis 13
How to cope with problems From Problem to Solution The human-way Problem Comprehension Problem Solving Techniques Think like a programmer Transition to algorithmic i solutions Algorithmic solutions by step wise refinement 27 Kinds of problems Problems in-the-large : Engineering task Follows a process, is well developed Problems in-the-small : Puzzle Heuristic approaches Getting started with problems o EASY: see the answer o MEDIUM: see the answer once you engage o HARD: need strategies to come with a potential solution, sometimes for even getting started 28 14
Example Problem Connect each box with its same-letter mate without letting the lines cross or leaving the large box. 29 Approaches this problem (1/3) Avoidance No positive attitude as required for a programmer. Overcoming hesitation & delay, even if a solution to the problem is not obvious. 30 15
Approaches to this problem (2/3) Cheat Captain Kirk s approach to the Kobayashi Maru test Change problem conditions: reorder boxes 31 Approaches to this problem (3/3) Engage Experiment: Make a drawing Consider extreme cases: If direct connection does not work, what else could be possible... Collaborate 32 16
Example Problem Its solution 33 Problem Comprehension -- Characteristics of Effective Problem Solvers Inaccuracy in Reading Collect all relevant facts of the problem Checking them, concern for accuracy to avoid simple mistakes Inaccuray in Thinking Restate the problem, focus on really comprehending the problem Avoid guessing and jumping to conclusion Weakness in Problem Analysis; Inactiveness Approach problem in a step by step manner look for things that are familar (make analogies), reuse them and merging a solution Divide/reduce the problem, break the problem into parts Have a plan Lack of perseverance Do not get frustrated, take positive attitute Avoid mental block: the fear of starting, overcoming procrastination Failure to Think Aloud Communicate, Ask questions, team work (pair programming), ask for support 34 17
Problem-Solving Techniques & Strategies Abstraction, Reduction, Means-End Analysis Analogy, Find a pattern, Adapt different point of view Brainstorming, Research, Experiment, Try-and-Error Top-Down (Divide-and-conquer approach): Hierachical structuring Bottom-Up (Building-block approach): Working Backwards Proof, Logical reasoning 35 Another Problem: How to cross the river? The fox, the goose, and the sack of corn. The boat can carry one item at a time. The fox cannot be left on the same shore as the goose, and the goose cannot be left on the same shore as the sack of corn. 36 18
END of 1st Lecture 19