1 / 31

CMPE003 – Personal Computer Concepts

CMPE003 – Personal Computer Concepts. Hardware and Software Winter 2004 Instructor: Scott Cooper scooper@soe.ucsc.edu. Assignment 4. Budget spreadsheet. Chapter 15: Programming Languages. Telling the Computer What to Do. Programming.

dysis
Download Presentation

CMPE003 – Personal Computer Concepts

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. CMPE003 – Personal Computer Concepts Hardware and Software Winter 2004 Instructor: Scott Cooper scooper@soe.ucsc.edu

  2. Assignment 4 • Budget spreadsheet

  3. Chapter 15: Programming Languages Telling the Computer What to Do

  4. Programming • Creating the sequence of instructions that tells the computer what to do • Input data • Output data • Transform data

  5. Speaking the language • Programming languages • Different ways of describing the sequence of instructions • Formalized constructs for telling the computer what to do • Must be translated into machine language • CPU instructions

  6. Cooking up programs • Program code is like a recipe • Terms like “dice” and “sauté” stand for procedures described elsewhere • Order matters: you can’t cook the eggs first when making a custard

  7. Successive refinement • Computers are very exact and literal • Humans are very imprecise and vague • Translating human intention into precise code is done in stages called successive refinement

  8. Programming is hard “Adjusting to the requirement for perfection [is] the most difficult part of learning to program” Frederick P. Brooks, Jr., The Mythical Man-Month

  9. Define the problem • Step 1: Carefully describe what it is you want to accomplish • Input data • Output data • Processing • User Interface (UI) This description should be understandable to an informed, non-technical audience

  10. Describe the solution • Step 2: develop an algorithm – a detailed, step-by-step solution • May use mathematical techniques and reasoning • Desk checking: carrying out the steps by hand to verify the algorithm’s correctness

  11. Tools for algorithm design • Flow charts • Pseudocode • Various formal and informal diagrams

  12. Coding the solution • Step 3: Translate the algorithm to programming language source code • Must adhere to the syntax or grammar of the programming language • Errors must be corrected before the program can run • Can use a text editor or code editor to write source code

  13. Compile • Step 4: Compile or translate your program code into the CPU’s binary instructions • Compiler is a program itself • Input: source code • Output: object code (or error messages) • One more step: linking • Now we are ready for testing

  14. Testing • Step 5: Test the program • Run it on different inputs and check the output for correctness • Finding and correcting logical errors is called debugging

  15. Documenting programs • Very important for later debugging and maintenance • Design documents • Testing procedures • Program comments • Narrative description within the code • In HTML: <!– This is a comment -->

  16. Categorizing languages • High vs. low level • Low: closer to machine’s native 1s and 0s • High: more like human language • Compiled vs. interpreted • Compiled: translated in one step ahead of time • Interpreted: translated on-the-fly each time

  17. Five language generations • Machine language • Assembly language • High-level languages • Very high-level languages • Natural languages

  18. Machine language • Programs written directly in 1s and 0s • Usually with switches • Tedious and error-prone

  19. Assembly language • Short mnemonics substituted for 0s and 1s • A for add, C for compare • Names for registers: R1, R2, … • Can use names instead of memory addresses • Requires a translator called assembler • Can use names for branch targets

  20. High-level languages • Independent of CPU instructions • Languages focus on solving problems rather than controlling hardware for the first time • Programs can be written and debugged much more quickly • Requires a translator called a compiler • Each computer needs its own compiler for each language

  21. Very high-level languages • Also called 4GLs • Specify the results and the solution is created automatically • Programmers can be much more productive • Specialized for certain types of tasks

  22. Natural language • Make requests in natural syntax • “Just ask for what you want!” • Like 4GL, specialized for applications such as database queries

  23. Major languages • Fortran • COBOL

  24. Types of programming • Procedural programming • Subroutines break up program logic • Modular programming • Package related routines and data • Object-oriented programming • Data and operations bound together

  25. O-O terms • Object – entity containing data and associated actions • Method – action that can be performed on an object • Attribute – piece of information describing an object (also member)

  26. Object design • Objects defined in classes • Objects are instanced when they are actually used • Objects grouped in hierarchies by inheritance • Subclasses inherit the data and behavior of their parent • Can define new behavior or redefine existing methods

  27. Using objects • Create an instance • Send a message • Handled by methods • Polymorphism • Messages are handled differently by different types of objects

  28. O-O Languages • C++ • Java • Visual Basic .NET • C#

  29. Finding average • Find the average of n numbers • Input: n numbers in consecutive memory locations • Output: numerical average of all n numbers • Sum the numbers • Divide by n

  30. Average pseudocode total <- 0 for count <- 1 to n total <- total + numbers[count] average <- total / n

  31. Average in C float average(int numbers[], int n) { int count; float total; for (count=0; count<n; count++) total = total + numbers[count]; return total / n; }

More Related