Documente Academic
Documente Profesional
Documente Cultură
COMPUTER PROGRAMMING
Introduction to Computer and
Computer Programming
• Contributes 3 units:
– 2 hours lectures (28 hours)
– 2 hours labs (28 hours)
• Main Objective:
– Students can independently write, read, compile, debug
and execute computer programs to solve problems,
especially engineering related problems.
COURSE OUTCOME
1. Ability to define and describe programming concepts and
principles.
2. Ability to apply GNU/Linux for coding, compiling,
executing and debugging computer programs.
3. Ability to analyze and solve engineering related problems
using computer programming techniques
4. Ability to evaluate programming techniques and tools to
design computer programs.
ASSESSMENT
• 4 main components:
– Theoretical Tests 20%
– Lab Assignments 20%
– Lab Test 10%
– Final Exam 50%
• Assignments are assessed individually (in lab assignment)
• Theoretical tests are written tests
• Attendances are compulsory!
REFERENCES
• Deitel & Deitel, “C How to Program”, International Edition,
Pearson-Prentice Hall, 2013.
• Cheng, H., “C for Engineers and Scientists”, McGraw Hill,
2010.
• Hanly, J.R. and Koffman, E.B., “C Program Design for
Engineers”, 2nd Ed., Addison-Wesley, 2001.
ISBN : 0321204174
NOTES
• This course is NOT about the language per se, it is
about analytical skills and to apply programming
to solve problems.
• Write C program in Linux environment/GNU
compiler applications
• Do early reading
• Do not hesitate to ask during lecture sessions
6
LECTURE OUTLINE
1. Introduction to Computer
2. Introduction to Computer Programming
3. Introduction to C Programming Language
7
A Brief Look At Computer
Computer
is a device that receives input, stores and processes data, and
provides output in a useful format.
Computers process data according to sets of instructions called
computer programs
Example: laptops, PCs, mainframes, mobile phones, washing-
machines, TV sets, cars contain computers
Hardware
Physical components of a computer
Example: Keyboard, screen, mouse, disks, memory, CD-ROM, and
processing units
Software
Programs that run on a computer
Example: Operating System such as windows XP -Vista -7, Word
processing packages such as MS Word, registration program
Computer Hardware
Exercise: Distinguishing between input-process
and output-storage
The scenario:
“At the end of each month, a clerk enters the employee name, number of days present
and absent, and the number of overtime done in the system. The system then calculates
the normal salary, the amount for overtime and the total salary. The clerk then saves the
information in the computer hard disk, and takes a backup on a cd. A report is produced
for the clerk to be shown to the manager. “
1. Input
2. Process(es)
3. Output
4. Storage
How Computer Processes Information?
Computers are NOT intelligent
Computers do what we tell them to do they don’t do anything by
themselves.
We must clearly tell a computer what to do in a step by step
manner using a programming language.
21
• To solve problem using algorithms, we have to:
– READ and understand the problem
– THINK about different solutions to the
problem
– DESIGN an approach that will solve the
If
needed
problem
– IMPLEMENT that design
– TEST to see if it works
22
• The constructs used to build algorithms can be
described in two different ways:
1. Pseudo code
2. Flowchart
23
• When the algorithm is written out as a well-thought
series of steps, it is called PSEUDO CODE
• It is written in easy to understand language (i.e.
ENGLISH)
• It is written very similar to the way that you would code
it into your 3rd Generation Language (i.e. C Language)
24
• Create a detailed set of instructions
(pseudo-code) that will tell us:
– How to eat a banana
25
1. Using your hand, get a yellow crescent-shaped fruit
called a “banana”
2. Peel the outer skin off the banana
3. Eat the banana
i. Put a small section of banana in your mouth
ii. Bite down on the banana
iii. Chew the banana by opening and closing your mouth
iv. Once the banana has been chewed, swallow the banana
v. Repeat until banana is finished
4. Throw out the used banana peel
26
WAKE UP MAK MINAH 1 WAKE UP MAK MINAH 2
• Get out of bed • Get out of bed
• Take off pyjamas • Take off pyjamas
• Take a shower • Get dressed The order of
actions are very
• Get dressed • Take a shower important!
• Eat breakfast • Eat breakfast
• Drive to school • Drive to school
RESULT RESULT
• Mak Minah arrives in a great • Mak Minah arrives in not too
mood ready to work great a mood since she’s
soaking wet
27
• The algorithm can also be written as a FLOW CHART
• The flow chart is a graphic organiser (a picture that
helps organize your thoughts)
• It uses a collection of basic symbols that are used to
organize your algorithm
• These symbols are connected by arrows that show
how the algorithm “flows”
28
• Flowchart: visual-form of an algorithm
Example:
Begin
Input Data
Output Result
End 29
• BASIC SYMBOLS IN FLOW CHART
TERMINAL: Start/End of a program
Flow direction
30
Example 1
• Write an algorithm that display a message to the screen as
“Hello World!”.
End
31
Example 2:
Write a flowchart that calculates and prints the SUM of
two integers A and B.
Pseudo Code Flow Chart
Begin
• Begin
• Input A and B Input A, B
• Calculate A + B
• Print result of SUM Calculate A + B
• End
Print SUM
End
32
1) Write an algorithm (pseudo code and flow chart)
to read input of 3 test marks, calculate the
average and display the final marks.
4) Hanly, J.R. and Koffman, E.B., “C Program Design for Engineers”, 2nd Ed.,
Addison-Wesley, 2001, ISBN : 0321204174