Introduction To Programming Concept: Outline
Introduction To Programming Concept: Outline
Introduction To Programming Concept: Outline
Introduction
• We will learn
– The C programming language
– Structured programming and proper programming techniques
• This course is appropriate for
– Technically oriented people with little or no programming
experience
– Experienced programmers who want a deep and rigorous
treatment of the language
3
What is a Computer?
• Computer
– Device capable of performing computations and making
logical decisions
– Computers process data under the control of sets of
instructions called computer programs
• Hardware
– Various devices comprising a computer
– Keyboard, screen, mouse, disks, memory, CD-ROM, and
processing units
• Software
– Programs that run on a computer
4
Computer Organization
• Six logical units in every computer:
1. Input unit
• Obtains information from input devices (keyboard, mouse)
2. Output unit
• Outputs information (to screen, to printer, to control other
devices)
3. Memory unit
• Rapid access, low capacity, stores input information
4. Arithmetic and logic unit (ALU)
• Performs arithmetic calculations and logic decisions
5. Central processing unit (CPU)
• Supervises and coordinates the other sections of the computer
6. Secondary storage unit
• Cheap, long-term, high-capacity storage
• Stores inactive programs
5
History of C
• C
– Evolved by Ritchie from two previous programming
languages, BCPL and B
– Used to develop UNIX
– Used to write modern operating systems
– Hardware independent (portable)
– By late 1970's C had evolved to "Traditional C"
• Standardization
– Many slight variations of C existed, and were incompatible
– Committee formed to create a "unambiguous, machine-
independent" definition
– Standard created in 1989, updated in 1999
10
Structured Programming
• Structured programming
– Disciplined approach to writing programs
– Clear, easy to test and debug and easy to modify
• Multitasking
– Specifying that many activities run in parallel
16
Basics of a Typical C Program Development
Environment
Program is created in
• Phases of C Programs: Editor Dis
the editor and stored
on disk.
k
Preprocessor program
1. Edit Preprocessor Dis processes the code.
k
Compiler creates
2. Preprocess Compiler Dis object code and stores
k it on disk.
3. Compile Linker Dis Linker links the object
code with the libraries
Primary k
Memory
4. Link Loader
Loader puts program
5. Load Disk ..
in memory.
..
..
Hardware Trends
• Every year or two the following approximately
double:
– Amount of memory in which to execute programs
– Amount of secondary storage (such as disk storage)
• Used to hold programs and data over the longer term
– Processor speeds
• The speeds at which computers execute their programs
18
• We "just do"
• Guesswork-and-luck
• Trial-and-error
• Experience (possibly someone else's)
• "Scientifically"
23
Analysis
Problem
specification
Design
Algorithm
Implementation
Program
Compilation
Executable
(solution)
26
Algorithm
Algorithm –History
• Book on arithmetic:
– Hindu numeration, decimal numbers, use of zero, method for
finding square root
– Latin translation (c.1120 CE): “Algoritmi de numero Indorum”
• Book on algebra
– Hisab al-jabr w’al-muqabala
28
Algorithm -- Examples
• A cooking recipe
• Assembly instructions for a model
• The rules of how to play a game
• VCR instructions
• Directions for driving from A to B
• A knitting pattern
• A car repair manual
• Recipe for Almond and honey slice
30
Problem
Algorithm: A sequence
of instructions describing
how to do a task (or
process)
C, Java Program
33
Components of an Algorithm
• Variables and values
• Instructions
• Sequences
• Procedures
• Selections
• Repetitions
• Documentation
34
Values
Variables
10 cookies
This jar
50 grams of sugar
can contain
3 slices of cake
etc.
38
Restrictions on Variables
Components of an Algorithm
Instructions (Primitives)
• Some action that is simple...
• ...and unambiguous...
• ...that the system knows about...
• ...and should be able to actually do
41
Instructions – Examples
Instructions -- Application
Instructions (Primitives) --
Recommendations
Instruction (Primitives)
• WhenAwriting an algorithm,
“sequence” of make the instructions
simple and unambiguous.
simple instructions
• Example:
Cut chicken into pieces and brown Cut chicken into pieces.
the pieces on all sides in a Heat olive oil in a casserole dish.
casserole dish in hot olive oil.
Brown the chicken pieces in the
casserole dish.
45
Conclusion
• An algorithm must:
– Be lucid, precise and unambiguous
– Give the correct solution in all cases
– Eventually end.
46
Developing an algorithm
• To help the initial analysis, the problem
should be divided into 3 separate
components:
1. Input: a list of the source data provided to the
problem
2. Output: a list of the outputs required
3. Processing: a list of actions needed to produce the
required outputs.
47
Solution:
• Defining diagram
Number1 total
Number2
Number3
50
• Defining diagram
Step 1
• A program is required to prompt the
terminal operator for the maximum and
minimum temperature readings on a
particular day, accept those readings
as integers, and calculate and display
to the screen the average temperature,
calculated by (maximum temperature +
minimum temperature)/2.
55
• Defining diagram
Step 2
• A program is required to prompt the
terminal operator for the maximum and
minimum temperature readings on a
particular day, accept those readings
as integers, and calculate and display
to the screen the average temperature,
calculated by (maximum temperature +
minimum temperature)/2.
57
• Defining diagram
Assignment1.
Compute mowing time
• A program is required to read from the
screen the lenght and widht of a
rectangular house block, and the lenght
and width of the rectangular house that
has been built on the block. The
algorithm should then compute and
display the mowing time required to cut
the grass around the house, at the rate
of two square metres per minute.