1 / 63

Week 1 Part II

Week 1 Part II. Kyle Dewey. Overview. Lab The art of programming Basic data types Variable declaration and initialization Data representation. Lab 1. The Art of Programming. General Advice. Top-down programming: Start with the big picture and get more specific

duy
Télécharger la présentation

Week 1 Part II

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. Week 1 Part II • Kyle Dewey

  2. Overview • Lab • The art of programming • Basic data types • Variable declaration and initialization • Data representation

  3. Lab 1

  4. The Art of Programming

  5. General Advice • Top-down programming: Start with the big picture and get more specific • Bottom-up programming: work up to the big picture by glueing together smaller, existing pieces • Divide and conquer: break a problem up into individual piecs

  6. Top-Down Programming • Start general and gradually become specific, filling in the details as you go along

  7. Top-Down Make Sandwich

  8. Top-Down Make Sandwich Put Meat on Bread Put Sides Together

  9. Top-Down Make Sandwich Put Meat on Bread Put Sides Together Get Meat from Fridge Get Bread from Cabinet

  10. Top-Down Make Sandwich Put Meat on Bread Put Sides Together Get Meat from Fridge Get Bread from Cabinet Open Fridge... Open Cabinet...

  11. Bottom-Up Programming • Glue preexisting pieces together to derive a solution

  12. Bottom-Up Handlebars Chain Frame Gears Wheels

  13. Bottom-Up Handlebars Chain Bolt Frame Gears Wheels

  14. Bottom-Up Handlebars Chain Bolt Frame Gears Bolt Wheels

  15. Bottom-Up Handlebars Chain Oil Bolt Frame Gears Bolt Wheels

  16. Bottom-Up Handlebars Chain Chain Tool Oil Bolt Frame Gears Bolt Wheels

  17. Combination • printf / scanf are generally written once (preexisting) • A middle ground

  18. Divide and Conquer • Really part of top-down and bottom-up • Break a problem down into distinct subproblems, solve them individually, and finally combine them

  19. Divide and Conquer Program Input Output

  20. Divide and Conquer Subprogram 1 Input Output / Input Subprogram 2 Output

  21. Divide and Conquer Subprogram A Input Subprogram B Output / Input Subprogram 2 Output

  22. General Five Step Process • Problem Statement • Input / Output Description • Hand Example • Algorithm Development • Testing

  23. General Five Step Process • Problem Statement • Input / Output Description • Hand Example • Algorithm Development • Testing

  24. Problem Statement • What are we trying to solve? • (Believe it or not, real software often goes astray here arguably more than anywhere else)

  25. General Five Step Process • Problem Statement • Input / Output Description • Hand Example • Algorithm Development • Testing

  26. Input / Output Description • What are the program inputs and what are the outputs? Output 1 Input I Program Output 2 Input 2 (A miracle occurs)

  27. General Five Step Process • Problem Statement • Input / Output Description • Hand Example • Algorithm Development • Testing

  28. Hand Example • Do the problem by hand • See if you actually understand what must be done

  29. General Five Step Process • Problem Statement • Input / Output Description • Hand Example • Algorithm Development • Testing

  30. Algorithm Development • Steps needed to solve the problem • Ultimately involves writing code • “Days of coding can save you hours of planning”

  31. General Five Step Process • Problem Statement • Input / Output Description • Hand Example • Algorithm Development • Testing

  32. Testing • See if solution actually works • Important step! • “50% of our code is tests”

  33. TDD • Test-driven development • Write tests before code • Wildly popular right now • The point: testing is important!

  34. C

  35. hello.c

  36. Running Code • Via make / gcc / cc (compilation) • Via ch (interpretation)

  37. Compilation • Code is ultimately converted to a form the machine understands directly • The result runs as fast as the machine • Certain interdependencies not handled

  38. Object Files 1: somethingFromHere(); 2: somethingFromElsewhere(); 3: somethingElseFromHere(); somethingFromHere somethingFromElsewhere somethingElseFromHere

  39. Linking • Technically separate from compilation, but the two often get conflated • Connects different pieces of code together

  40. Linking somethingFromElsewhere somethingFromHere somethingElseFromHere

  41. Linking somethingFromHere somethingFromElsewhere somethingElseFromHere

  42. Overall Process Linking Compilation Source Code File #1 Object File #1 Executable Source Code File #2 Object File #2

  43. Question • Why separate compilation and linking?

  44. Interpretation • As with ch • A program that understands the language runs it directly • Runs as fast as the interpreter

  45. Questions • Why compile versus interpret? • Why interpret versus compile?

  46. Types

  47. Types • All data in C has a type • Types determine: • What can be done with the data • How much space they take up (as with the sizeof operator)

  48. Basic Types • int: Integers (i.e. 1, 2, 3...) • Come in both signed and unsigned forms • double: floating point numbers (i.e. 5.1, 7.8, 2.93, ...) • char: A character (i.e. a, b, c,...)

  49. Variables • A container for a value • Must have a type

  50. Variable Declaration • Telling the compiler that a variable with a given name and type can be used int myInteger; double myFloatingPoint; char myCharacter;

More Related