Professional Documents
Culture Documents
Programming
By:
Mr. Mohd. Nazrin Md. Isa
Contact me at :
04-9798410/nazrin@kukum.edu.my
1
General Information
Syllabus – refer handout
Contributes 4 units:
2 hours - lectures
Main Objective:
Students can independently write a computer
2
Overall Evaluation
4 main components:
Assignments (30%)
3
References
Text Book
“ C Programming for
Engineering & Computer Science
” H.H.Tan and T.B.Orazio, Mc
Graw Hill, 1999.
References
“C Programming”, Deitel &
Deitel
“Problem Solving and
Programming Concept”, Maureen
Sprankle, 6th Ed.
Any other C books
WWW
4
Notes
This course is NOT about the language per
se, it’s about problem solving / analytical
skills & to apply C to solve problems.
Write C program in Linux environment
Please do early reading
Do not hesitate to ask during lecture
sessions
5
Outline
General Problem Solving Concept
The six Steps in Problem Solving
Data Type
Structured Chart
IPO Chart
Algorithm
Software
System Software
Application Software
6
General Problem Solving
Concept
People make decisions every day that affect their lives.
Problems that we encounter every day may be important or not
so important (not so affected to our lives)
Generally there are six (6) steps in problem solving.
Identify the Problem: What is the problem – in the
7
Understand the Problem
Understand what is involved in the problem.
knowledge base of the person or machine
resources.
For e.g. if for a person, we must know what the
8
Identify Alternative way
Identify several way, how to solve the
problem, but all this alternative way might
suitable to some people but not to some
other people.
E.g. Direction to KWSP from Jejawi
9
Select the best way of the alternative
solution
Here need to identify and evaluate the pros
and cons of each possible solution.
Thus, we need to identify the criteria for the
evaluation as these criteria will serve as a
guidelines for the evaluation.
E.g. Which is the fastest and shortest way to
KWSP from Jejawi.
10
List the Instructions
List down the step-by-step numbered instruction enable to solve the problem
using the selected solution.
All the instruction should be understand by the targeted person or the machine.
E.g
1. go straight
3. Take 12 o’clock
4. Up further, Until you reach junction with traffic light (where a police
station on your right)
5. Take left.
End
11
Evaluate the Solution
Check the result:
Correct or not.
the person
E.g
12
Example – A problem What to do this
evening
Identify the problem: How do individual wish to
spend the evening.
Understand The problem:
Knowledge base of people involve must be
considered
So solution selected should be that everyone
13
Continue …
Identify alternative
Watch television, Invite friends over, Play games,
16
Problem Solving Concept with Computer
Computer Fundamental
CPU – where all the processing take place
CPU
Input Device Output Device
Main Memory
Secondary Memory
17
Problem Solving Concept For
Computer
Problem that can be solve with computers
generally consist of three:
Computational – problem with mathematical
processing
Logical – problem involving with relational or
18
Constant and Variable (Data)
The most fundamental concept of problem solving for computer
Computer use constant and variable to solve problem. They are
actually the data used in the processing.
Constant:
Value that never changes during the processing of all the
instructions.
Can be any type of data – numerical, alphabetical, or special
symbols.
constant is given a location in memory or a name.
19
Continue …
Variable:
Value of a variable may changed during
processing
Variable must have a name
20
Example Constant And Variable
Constant Variable
Rule: Cannot be change. Rule:
Example: 25 Storage lacation given name
Values of the content can be change.
Value:
“selamat datang” Refered by name in the instruction.
20
Value: Example
“Marina”
Variable Name – Age
Named Constant: Cannot be changed Variable Name - Name
after initially given a value. Storage
Loacation has a name
3.142857
Example: Pi
Value
21
Data Types
Data is unorganized facts, they go into computer as an input and are
processed by the program.
The outcome is the output or information in form of report or other
meaning full format to the user.
data uses are of many different types.
We need to tell the computer the type of data for each of the variable
used in the program.
The most common data types are numerical, character (alphabetical),
and logical.
Computer
input output
Data process Output
Data
(Unorganized fact)
into (report/information)
Infomation
22
Data Types Continue …
Numerical Data:
include all type of numbers. The only data used for calculation.
Logical
consist of two pieces of data in the data set, TRUE and FALSE.
23
Example of Data Types
Data Data Type Explanation
The price of item: Numerical: Would be use in the calculation
7.55, 12.99 Real
A date: Date or Character If date data type is available use date, unless use
10/07/06 string character string
25
Problem Analysis Chart (PAC)
Consist of 4 separate parts
Section 1 - The given data – Data given or provided by user, can be
known value or general name.
Section 2 - The required result – Requirement for the output report,
information needed and th format required.
Section 3 - The processing – List of processing required, include equation
or other type of processing, sort, searching and so forth.
Section 4 - A list of solution – List of ideas for solution of the problem.
Let consider Payroll problem calculating Gross Pay of a worker end of the
day.
Main: PAYROLL
0000
27
IPO (Input-Processing-Output)
Chart
IPO Extends and organizes the information in the problem analysis
chart.
Shows more detail what data items are inputs what processing takes
place on the data, and what
Input Processing Module Reference Output
Number
All input data (section 1 All processing in steps Module Reference from All output requirements
of PAC) (section 3 & 4 of PAC) structure chart (section 1 & 2 from
PAC)
29
Algorithm-Basic symbols of
flowchart
Flowchart Symbol Explanation
Start / Stop (terminator) A start and an end of a module. For some end for a main
module and exit for other module
Processing Processing block, for the calculation, and other step of
instructions.
Input / Output (I/O) Input and output data to from the computer memory.
Automatic Counter loop The number of loop execute will start with A, counter
incremented by S, and until the end value B
Connector on page off page Flowchart can be sectioned, the connector will show
where the section continue 30
Flowchart-(cont’d)
Algorithm Flowchart Algorithm Flowchart
Main Module start Read Module start
1. Repeat 1000
Process Read Read 1. Read Hours, Pay
rate Read
Process Calc Hours, Payrate
Calc 2. Exit
Process Print
Until no more
Print exit
employee
2. End false No more
employee
True
end
Algorithm Algorithm Flowchart
Calc Modul Print Module
start start
2000 3000
1. GrossPay = Hour 1. Print Pay
* payrate GrossPay = Hours * Payrate 2. Exit Print
2. Exit GrossPay
exit exit
31
Software
Software is a program of the solution for a
specific task that programmer develop.
In computer science software are classified
into :
System software
Application software
32
Software
System software : software manages the computer
and its peripheral devices (hardware)
E.g. Operating systems(OS)
Text editor
Preprocessor
Language translator
Linker
Loader
33
Software
Application software : performs specific tasks
There are two types:
Program to solve specific problems
problem
E.g word processor, desktop publishing software,
spreadsheets, database, graphics, communication,
program perform a specific task such as
accounting, scientific, engineering, education etc
34
Programming Languages
Programming language is divided into three
categories:
Machine Language
Assembly Language
High-Level Language
35
Machine Language
Language understood by the computer
Bunch of 0’s and 1’s
Program written in machine language can be
executed without being translated
Nevertheless, hard to learn because it is written in
0’s and 1’s
Program is too long to solve simple problem
Machine-dependant and not portable
E.g. 0101 1000 0101 1001 1100 0111
0101 0001 1100 0100 1011 1000
36
Assembly Language
It is a low level programming language.
To make it easier for the programmer, the
strings of 0’s and 1’s are replaced into
instructions which resembles English
language to represent computer operation
element
So easier to understand and written
LOAD rate
E.g MULT hour
STOR wages
37
Assembly Language
Nevertheless, need language translator
called Assembler to change Assembly
Language to Machine Code for execution
purpose
Assembler is a type of system software, that
we use to translate our assembly code into
binary code (understand by computer.
38
High-Level Language
Example of high level programming language are,
PASCAL, C - Language, Java, Visual Basic etc
One instruction of it, consist several instructions in
machine level or assembly language.
E.g. Grosspay := Hourswork * Payrate;
Before it can be executed by computer, the program must
be changed to machine code before executed. For high
level language compiler will translate the coding into
assembly code and binary code.
Compiler is a type of system software that we use to
compile our C code.
39
Thank you
End of lecture #01
Any questions???
The following exercises are to be
completed during lab
1) Exercise 1
2) Exercise 2
40