1 / 26

Introduction to Logic

Introduction to Logic. CS104 8/31/11. Agenda. Quiz Discuss Assignment #1 (due 9/7) Finish Bits and Bytes Discussion Searching Discuss basic computer components and terminology Introduce procedural logic BYOB Scratch Please complete College Board survey.

kara
Download Presentation

Introduction to Logic

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 Logic CS104 8/31/11

  2. Agenda • Quiz • Discuss Assignment #1 (due 9/7) • Finish Bits and Bytes Discussion • Searching • Discuss basic computer components and terminology • Introduce procedural logic • BYOB Scratch • Please complete College Board survey

  3. Next Week • No class on Monday! • No quiz next Wednesday! • HW 1 due next Wednesday ;) • More on logic and programming in the context of BYOB Scratch • If you have a laptop, please consider installing BYOB Scratch and bringing your laptop to class • Those without laptops may want to buddy with someone in class during lecture, or capture notes

  4. Computer Components • Hardware: Physical components • Software: Instructions • Without specific instructions, or programs, the physical components would not function • Specialists, programmers, are needed to write these programs, which can be used for entertainment (facebook) or function (operating systems)

  5. Software • Written in a programming language • Every language has a specific syntax dictating the structure of the language • The instructions must be very specific; this is the logic of a program • The code is then translated via a compiler or interpreter into machine language to allow the circuitry of the computer to understand the instructions • Once translated, the code can be run (or executed)

  6. Inside the Computer • Input Devices: mouse, keyboard, joystick • Processing: motherboard • Output Devices: monitor, printer • Memory • Internal Storage: memory • Random Access Memory (RAM): volatile • Read-Only Memory (ROM): non-volatile • External Storage: memory stored outside the computer (USB drive)

  7. Programming Process Four basic steps • Understand • Design • Write the code • Test the program

  8. Understand • Most difficult part of the process • Users don’t always know what they need • Descriptions are usually vague • The programmer has to ask questions to fully understand the problem, which means working closely with the user

  9. Design • Just as an architect uses blueprints to design a building, programmers use flowcharts or pseudocode to design a program • These tools help layout the flow of the program in English • An advantage of planning the program in detail using these tools is that these tools can be presented to the user to ensure the programmer fully understands the problem and can allow the programmer to avoid scope creep.

  10. Importance of Planning • Some very experienced programmers can successfully combine the logic planning and the actual instruction writing, or coding of the program, in one step; however, this is usually only true for small programs. For really useful programs, even professional programmers must go through all of these phases. • A good term paper needs planning before writing, and so do most programs • The following are examples of what happens from poor planning

  11. Poor Engineering leads to ad-hoc structure! Winchester Mystery House: http://www.winchestermysteryhouse.com/ The result of continuous building without any thought toward design. Result: Stairs leading to ceiling; Windows in the middle of room; Doors opening to wall; Non-intuitive floor plan!.

  12. Poor Engineering leads to ad-hoc structure! • The result of continuous building without any thought toward design. • Problems: • How would you maintain this if something went wrong? • How would you extend this to add more connections or features?

  13. Poor Engineering Has Disastrous Consequences! Aerodynamic phenomena in suspension bridges were not adequately understood in the profession nor had they been addressed in this design. New research was necessary to understand and predict these forces. The remains, located on the bottom of the Sound, are a permanent record of man's capacity to build structures without fully understanding the implications of the design. http://www.nwrain.net/~newtsuit/recoveries/narrows/narrows.htm

  14. Poor Engineering Has Disastrous Consequences!$7 Billion Fire Works – One Bug, One Crash On 4 June 1996, the maiden flight of the Ariane 5 launcher ended in a failure. Only about 40 seconds after initiation of the flight sequence, at an altitude of about 3700 m, the launcher veered off its flight path, broke up and exploded. The failure of the Ariane 501 was caused by the complete loss of guidance and attitude information 37 seconds after start of the main engine ignition sequence (30 seconds after lift- off). This loss of information was due to specification and design errors in the software of the inertial reference system. The launcher started to disintegrate at about H0 + 39 seconds because of high aerodynamic loads due to an angle of attack of more than 20 degrees that led to separation of the boosters from the main stage, in turn triggering the self-destruct system of the launcher. This angle of attack was caused by full nozzle deflections of the solid boosters and the Vulcain main engine. These nozzle deflections were commanded by the On-Board Computer (OBC) software on the basis of data transmitted by the active Inertial Reference System (SRI 2). Part of these data at that time did not contain proper flight data, but showed a diagnostic bit pattern of the computer of the SRI 2, which was interpreted as flight data. The reason why the active SRI 2 did not send correct attitude data was that the unit had declared a failure due to a software exception. The OBC could not switch to the back-up SRI 1 because that unit had already ceased to function during the previous data cycle (72 milliseconds period) for the same reason as SRI 2. The internal SRI software exception was caused during execution of a data conversion from 64-bit floating point to 16-bit signed integer value. The floating point number which was converted had a value greater than what could be represented by a 16-bit signed integer. This resulted in an Operand Error. The data conversion instructions (in Ada code) were not protected from causing an Operand Error, although other conversions of comparable variables in the same place in the code were protected. The error occurred in a part of the software that only performs alignment of the strap-down inertial platform. This software module computes meaningful results only before lift-off. As soon as the launcher lifts off, this function serves no purpose. The alignment function is operative for 50 seconds after starting of the Flight Mode of the SRIs which occurs at H0 - 3 seconds for Ariane 5. Consequently, when lift-off occurs, the function continues for approx. 40 seconds of flight. This time sequence is based on a requirement of Ariane 4 and is not required for Ariane 5. The Operand Error occurred due to an unexpected high value of an internal alignment function result called BH, Horizontal Bias, related to the horizontal velocity sensed by the platform. This value is calculated as an indicator for alignment precision over time. The value of BH was much higher than expected because the early part of the trajectory of Ariane 5 differs from that of Ariane 4 and results in considerably higher horizontal velocity values. http://java.sun.com/people/jag/Ariane5.html http://www.around.com/ariane.html http://archive.eiffel.com/doc/manuals/technology/contract/ariane/page.htm l

  15. Code the Problem • Once the problem is understood and the design is completed, the programmer can begin writing code • There are numerous programming languages to choose from (Ada, C++, Java, C#, PHP, FORTRAN, etc.), and each language has advantages/disadvantages for use in each problem • Programmers also have tools available to aid in the coding process such as editors and debuggers

  16. Test the Program • Two types of errors: • syntax errors: similar to a grammatical error • logical errors: putting on shoes before socks • Run-time error: special type of logical error, which may cause the computer to “crash”

  17. Flowchart Symbols and Pseudocode • The shape denotes the function of the code block • Start/End • Input/Output • Processing • The text inside the shape, written in pseudocode, represents the logic

  18. Example • Consider the following problem: • I want to build a program that will double any number the user provides and print the product to the screen.

  19. Example Start Get inputNumber from user product = inputNumber * 2 Print product to screen End

  20. Variables • Variables are memory locations used to store a designated value type • The term “variable” is important as the values stored can vary, which is the purpose • inputNumber is user input • The user may enter a different number each time the program is executed

  21. Naming Variables • Variables must have a name (or identifier) • Variable names must follow only two rules: • Must be one word • Have some appropriate meaning • Convention dictates that variables start with a lowercase letter

  22. Basic Data Types • Numbers: • Integer – whole number • Double – decimal number • Text: • Character – single letter • String – phrases of letters (words)

  23. Assigning Values to Variables • What does the following statement really mean? product = inputNumber * 2 • This line achieves two goals • Calculation: inputNumber * 2 is computed • Storage: The computation of inputNumber * 2 is stored in a new variable called “product” • The equal sign represents the Assignment Operator • Note: the variable on the left of the assignment operator is always the variable storing the data

  24. Your turn • How would you average three numbers? (Pseudocode or flowchart)

  25. Solution Start get inputNumber1 from user get inputNumber2 from user get inputNumber2 from user compute: sum = inputNumber1 + inputNumber2 + inputNumber3 compute: average = sum / 3 print average End

  26. BYOB Scratch Installation • Direct your browser to http://byob.berkeley.edu/. • Click on “Download.” Notice you can access tutorials from this site as well. • Click on the appropriate link for your operating system. If you are a Windows user, click on “installer” and choose “Save File.” Once the file has downloaded, double-click the file and follow the wizard.

More Related