200 likes | 367 Views
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
E N D
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 Quratulain
What is computation? • Earlier computer were fixed program (Declarative) • E.g Calculator • Now, stored program computers(Imperative) • E.g Computers Quratulain
Computer System Quratulain
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
A Programming Language is . . . • a language with strict grammatical rules, symbols, and special words used to construct a computer program
Code is . . . • The product of translating an algorithm into a programming language • Instructions for a computer that are written in a programming language
Languages • High level vs Low level • General purpose vs Targeted • Interpreted vs Compiled • Synatxvs Semantics Quratulain
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
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
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
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
Programming Shortcut? PROBLEM-SOLVING PHASE Problem Algorithm Shortcut? Code TEST THINKING IMPLEMENTATION PHASE CODE
Programming Life Cycle Problem-Solving Analysis and Specification General Solution ( Algorithm ) Verify Implementation Concrete Solution ( Code ) Test Maintenance Use Maintain
Sample Problem • A programmer needs an algorithm to determine an employee’s weekly wages • How would the calculations be done by hand?
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
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
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