Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE:141 Introduction to Programming Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 2.

Similar presentations


Presentation on theme: "CSE:141 Introduction to Programming Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 2."— 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 2/3/2010Quratulain2

3 What is computation? Earlier computer were fixed program (Declarative) – E.g Calculator Now, stored program computers(Imperative) – E.g Computers 2/3/2010Quratulain3

4 Computer System 2/3/2010Quratulain4

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. 2/3/2010Quratulain5 Address Memory Contents … 50,000 50,001 50,002 50,003 50,004 50,005 …

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

7 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 Synatx vs Semantics 2/3/2010Quratulain8

9 The high level vs low level 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)

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. 2/3/2010Quratulain11

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 Source Code Object Code

13 Synatx vs 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” 2/3/2010Quratulain13

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

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

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

17 17 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 40 x $ 24.75 = $ 990.00 12 x 1.5 x $ 24.75 = $ 445.50 ___________ $ 1435.50

18 18 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 Weekly Wages, in General

19 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


Download ppt "CSE:141 Introduction to Programming Faculty of Computer Science, IBA BS-I (Spring 2010) Lecture 2."

Similar presentations


Ads by Google