1 / 19

CSE:141 Introduction to Programming

CSE:141 Introduction to Programming. Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 2. Lesson Plan. Introduction to computation Languages Program life cycle. What is computation?. Earlier computer were fixed program (Declarative) E.g Calculator

Download Presentation

CSE:141 Introduction to 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. CSE:141 Introduction to Programming Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 2

  2. Lesson Plan • Introduction to computation • Languages • Program life cycle Quratulain

  3. What is computation? • Earlier computer were fixed program (Declarative) • E.g Calculator • Now, stored program computers(Imperative) • E.g Computers Quratulain

  4. Computer System Quratulain

  5. Memory Addressing • The capacity (size) of memory is described in terms of number of bytes. • RAM capacities in a typical computer range from 512 MB (megabyte) to 3 GB (gigabyte). • RAM is volatile – data is lost when power is turned off. • Computers don't understand the alphabet. They only understand 0’s and 1’s. • So computers map each alphabet character to a series of sixteen 0's and 1's. For example, the letter E is 00000000 01000101. • And each of the eight-bit groupings is a byte. Quratulain

  6. A Programming Language is . . . • a language with strict grammatical rules, symbols, and special words used to construct a computer program

  7. Code is . . . • The product of translating an algorithm into a programming language • Instructions for a computer that are written in a programming language

  8. Languages • High level vs Low level • General purpose vs Targeted • Interpreted vs Compiled • Synatxvs Semantics Quratulain

  9. High-Level Language (HLL) closest to natural language words, numbers, and math symbols not directly understood by hardware “portable” source code (hardware independent) Java, C, C++, COBOL, FORTRAN, BASIC, Lisp, Ada, etc. Machine Language (lowest level) least natural language for humans, most natural language for hardware just 0s and 1s directly understood by hardware not portable (hardware dependent) The high level vs low level

  10. Programming Language Hierarchy

  11. General purpose vs Targeted Languages • A "general purpose programming language" theoretically should be usable in multiple domains, but not specialized for any of them. • A Targeted/Specific purpose programming language. Quratulain

  12. Compilers vs. Assemblers vs. Interpreters • Compilers and Assemblers • translation is a separate user step • translation is “off-line,” i.e. not at run time • Interpreters - another way to translate source to object code • interpretation (from source to object code) is not a separate user step • translation is “on-line,” i.e. at run time Compiler, Assembler, or Interpreter Object Code Source Code

  13. Synatxvs Semantics • Semantics • Grammatical rules for assigning meaning to a sentence. • Syntax • Grammatical rules for specifying correct word order and inflectional structure in a sentence. • Example • “Baby milk drinks“ not correct syntactically but can extract meaning “Baby drinks milk” Quratulain

  14. Programming Shortcut? PROBLEM-SOLVING PHASE Problem Algorithm Shortcut? Code TEST THINKING IMPLEMENTATION PHASE CODE

  15. Programming Life Cycle Problem-Solving Analysis and Specification General Solution ( Algorithm ) Verify Implementation Concrete Solution ( Code ) Test Maintenance Use Maintain

  16. Sample Problem • A programmer needs an algorithm to determine an employee’s weekly wages • How would the calculations be done by hand?

  17. 40 x $ 24.75 = $ 990.00 12 x 1.5 x $ 24.75 = $ 445.50 ___________ $ 1435.50 One Employee’s Wages • During one week an employee works 52 hours at the hourly pay rate $24.75 • How much is the employee’s wages? • Assume a 40.0 hour normal work week • Assume an overtime pay rate factor of 1.5

  18. Weekly Wages, in General If hours is over 40.0, then wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate otherwise, wages = hours * payRate RECALL EXAMPLE ( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) =$1435.50

  19. Employee’s Weekly Wages Objects: Employee, pay rate, hours worked, wages Algorithm: 1. Get the employee’s hourly pay rate 2. Get the hours worked this week 3. Calculate this week’s regular wages 4. Calculate this week’s overtime wages (if any) 5. Add the regular wages to overtime wages (if any) to determine total wages for the week

More Related