Upload
kermit-stevenson
View
31
Download
0
Embed Size (px)
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
CSE:141 Introduction to Programming
Faculty of Computer Science, IBABS-I (Spring 2010)
Lecture 2
Quratulain 2
Lesson Plan
• Introduction to computation• Languages• Program life cycle
2/3/2010
Quratulain 3
What is computation?
• Earlier computer were fixed program (Declarative)– E.g Calculator
• Now, stored program computers(Imperative)– E.g Computers
2/3/2010
Quratulain 4
Computer System
2/3/2010
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.
2/3/2010
Address Memory Contents
…
50,000
50,001
50,002
50,003
50,004
50,005
…
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
Quratulain 8
Languages
• High level vs Low level• General purpose vs Targeted• Interpreted vs Compiled• Synatx vs Semantics
2/3/2010
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)
Programming Language Hierarchy
H ard w are
M ach in e L an g u ag e
A ssem b ly L an u ag e
H ig h -L eve l L an g u ag e (H L L )
Quratulain 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/2010
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
SourceCode
ObjectCode
Quratulain 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/2010
14
Programming Shortcut?
THINKINGCODE
TEST
PROBLEM-SOLVING PHASE
IMPLEMENTATION PHASE
Shortcut?
Algorithm
Code
Problem
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
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
If hours is over 40.0, thenwages = (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
Employee’s Weekly Wages
Objects: Employee, pay rate, hours worked, wagesAlgorithm: 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