Week 1 - UniMAP Portal

Download Report

Transcript Week 1 - UniMAP Portal

Week 1 – Session 1
KUKUM Sem1-06/07
EKT120: Computer Programming
1
General Information


Syllabus – refer handout
Contributes 4 units:



2 hours - lectures
4 hours – lab and tutorial
Main Objective:

Students can independently write a computer
program to solve calculation problems, especially
those related to engineering
KUKUM Sem1-06/07
EKT120: Computer Programming
2
Overall Evaluation

4 main components:






Assignments (30%)
1st & 2nd Test (15% +25%)
Group Mini-project (30%)
Assignments are individual lab
The two tests are written tests
Project : Max number of group member
is 2
KUKUM Sem1-06/07
EKT120: Computer Programming
3
References

Text Book

“ C Programming for
Engineering & Computer
Science ” H.H.Tan and
T.B.Orazio, Mc Graw Hill, 1999.

References




“C Programming”, Dietal &
Dietal
“Problem Solving and
Programming Concept”,
Maureen Sprankle, 6th Ed.
Any other C books
WWW
KUKUM Sem1-06/07
EKT120: Computer Programming
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
KUKUM Sem1-06/07
EKT120: Computer Programming
5
Outline

General Problem Solving Concept


Problem Solving Concepts for the Computer




Computer Fundamental
Data - Constant and Variable
Data Type
Problem Solving Tool






The six Steps in Problem Solving
Problem Analysis Chart
Structured Chart
IPO Chart
Algorithm
Pseudocode and Flowchart
Software


System Software
Application Software
KUKUM Sem1-06/07
EKT120: Computer Programming
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
classroom usually problem is identified for you
Understand the problem
Identify alternative ways to solve the problem
Select the best way to solve the problem
List the instruction that enable you yo solve the problem
Evaluate the solution
KUKUM Sem1-06/07
EKT120: Computer Programming
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 person knows. Different set of
instruction need to be given for a different
person, depending on the knowledge base.
E.g Direction of a place.
KUKUM Sem1-06/07
EKT120: Computer Programming
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
KUKUM Sem1-06/07
EKT120: Computer Programming
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.
KUKUM Sem1-06/07
EKT120: Computer Programming
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
2. Will pass through round about
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.
6. You will reach another junction, and take right.
7. Go straight, you will see the KWSP building on your right.
8. Go up further untill you reach a round abou and make U turn
9. Go further until you reach KWSP building
End
KUKUM Sem1-06/07
EKT120: Computer Programming
11
Evaluate the Solution

Check the result:




Correct or not.
Satisfy the need of the person or not
Note: the result may be correct but not
satisfy the person
E.g

The steps you have directed the person might
be right, but the person does not drive.
KUKUM Sem1-06/07
EKT120: Computer Programming
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 involved would know haw to do.
E.g we select play chess might not possible
if the participants does not know how to
play chess.
KUKUM Sem1-06/07
EKT120: Computer Programming
13
Continue …

Identify alternative


Select the best way to solve the problem



Watch television, Invite friends over, Play games,
go outing. Complete the list until you can’t find
any more alternatives.
Vote out alternatives that are not suitable, such as
costly, do not interest one of individual involve etc.
Prepare the list of instruction.
Evaluate the solution. Everybody satisfy with
the solution. Are we having fun? Etc.
KUKUM Sem1-06/07
EKT120: Computer Programming
14
Types of Problems


Algorithmic Solution – problem can be solved
with a series of actions. So once we eliminate
the alternatives and have chosen one best
methods, these steps are called algorithm.
Heuristic Solution – Problem with solutions
require reasoning built on knowledge and
experience, and a process of trial and error.
Ussually use in the Artificial Intelligent
software or Expert system softwware.
KUKUM Sem1-06/07
EKT120: Computer Programming
15
Problem Solving with Computer



Solution means the instructions that
must follow to produce the best results.
Results mean the outcome or
completed computer – assisted answer.
Program means the set of instructions
that make up the solution after they
have been coded into a particular
computer language.
KUKUM Sem1-06/07
EKT120: Computer Programming
16
Problem Solving Concept with Computer

Computer Fundamental





CPU – where all the processing take place
Memory – store all data currently processed, before program
can be execute, program must be loaded into memory
Input Device – Device use to input data to be processed into
computer
Output Device – Device use to display processed data
(output)
Secondary Memory – Store permanent data (can be as
output device.
CPU
Output Device
Input Device
Main Memory
Secondary Memory
KUKUM Sem1-06/07
EKT120: Computer Programming
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 logical processing. This is kind of
processing involve in decision making.
Repetitive – problem involving repeating a
set of mathematical or logical instructions.
KUKUM Sem1-06/07
EKT120: Computer Programming
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.
During the execution of the instructions (a program) this
constant is given a value and then is referred to by its name.
Once the constant is given a value it cannot be changed
during the execution of the program.
Example Pi = 3.14
KUKUM Sem1-06/07
EKT120: Computer Programming
19
Continue …

Variable:




Value of a variable may changed during
processing
Variable must have a name
Programmer uses the variable name as a
reference name for a specific value of a
variable.
the computer uses the name as a
reference to access that value in the
computer memory
KUKUM Sem1-06/07
EKT120: Computer Programming
20
Example Constant And Variable
Constant
Variable
Rule: Cannot be change.
Example:
Value: 25
Rule:
Value: “selamat datang”
Example
Variable Name – Age
20
Variable Name - Name “Marina”
Named Constant: Cannot be
changed after initially given a value.
Storage Loacation has a name
Example:
Pi
3.142857
Value
KUKUM Sem1-06/07
Storage lacation given name
Values of the content can be change.
Refered by name in the instruction.
EKT120: Computer Programming
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.
Data
(Unorganized fact)
KUKUM Sem1-06/07
input
Computer
Data process output
Output
into
(report/information)
Infomation
EKT120: Computer Programming
22
Data Types Continue …

Numerical Data:


Character Data – Alphanumeric Data




include all type of numbers. The only data used for
calculation. They are integers and real numbers
Consist of all single digit, letters, and special characters
available to the computer, e.g. a to z, A to Z, 3, #, & etc,
placed within quotation marks.
Uppercase letter is different from the lowercase letter.
can be compared and arranged in alphabetical order.
Logical


consist of two pieces of data in the data set, TRUE and
FALSE.
There are use in making yes-no decision
KUKUM Sem1-06/07
EKT120: Computer Programming
23
Example of Data Types
Data
Data Type
Explaination
The price of
item:
7.55, 12.99
Numerical:
Real
Would be use in the calculation
An Account
Number:
“A444440”
Character:
String
Consist of alphanumeric or simply numbers,
cannot use in calculation
Quantity
Numerical:
integer
Use in calculation, Integer because normally
as a whole number
A date:
10/07/06
Date or
Character string
If date data type is available use date, unless
use character string
An answer to a
question:
True / False
Logical
An answer to question: Do you like coffee, is
either yes or no, therefore use logical
KUKUM Sem1-06/07
EKT120: Computer Programming
24
Organizing The Problem

There are several organizational tool can be
used in problem solving





Problem Analysis Chart – the beginning analysis of
the problem
Structured Chart – shows the overall layout or
structure of the solution
IPO Chart – shows the input, the procrssing and
the output
Algorithm is the sequence of instructions
comprising the solution
Flowcharts is the graphic representations of
the algorithm.

KUKUM Sem1-06/07
EKT120: Computer Programming
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.
Given Data
Required Result
Hours
Pay Rate
Gross Pay
Processing Required
Solution Alternative
Gross Pay = Hours * Pay Rate
1.
2.
KUKUM Sem1-06/07
Define the hours worked and pay rate
as constant
Define the hours worked and pay rate
as input values
EKT120: Computer Programming
26
Structured Chart



Divide the problem into subtasks called modules or
smaller subtasks.
This breakdown enable you to view complex
problems. It only shows you what will happen and
not how its happen.
Use Top-Down Solution method
Main: PAYROLL
0000
READ
1000
KUKUM Sem1-06/07
CALC
2000
EKT120: Computer Programming
PRINT
3000
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
All input data (section
1 of PAC)
All processing in steps
(section 3 & 4 of PAC)
Input
Processing
Hours Work
Pay rate
KUKUM Sem1-06/07
1. Enter hours work
2. Enter Pay rate
3. Calculate Pay
4. Print Pay
5. End
Module Reference
Number
Module Reference
from structure chart
Module Reference
Number
1000
1000
2000
3000
0000
EKT120: Computer Programming
Output
All output
requirements (section
1 & 2 from PAC)
Output
Gross Pay
28
Algorithms




Organizing the solution where programmer develop
a set of instruction for the computer and this is call
algorithm.
Pseudocode may be use, it is close to the actual
programming language that the programmer will
used later.
To complete it, the programmer will write another
separate set of instruction (coding/program) that
will be understand by the computer.
Instead of Pseudocode, we can also represent the
set of instruction in term of Flowchart ( a graphic
presentation of the algorithm.
KUKUM Sem1-06/07
EKT120: Computer Programming
29
Algorithm-Basic symbols of flowchart
Flowchart Symbol
Explanation
Flowlines
Flow of the direction
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.
Decision
Usually has one entrance and two exit.
Process Module
Task that process in different place, module
Automatic Counter loop
A
Connector
on page
KUKUM Sem1-06/07
counter
S
B
off page
The number of loop execute will start with A,
counter incremented by S, and until the end value
B
Flowchart can be sectioned, the connector will
show where the section continue
EKT120: Computer Programming
30
Flowchart-(E.g from previous)
Algorithm
Main Module
1. Repeat
Process Read
Process Calc
Process Print
Until no more
employee
2. End
Algorithm
Calc Modul
2000
1. GrossPay =
Hour * payrate
2. Exit
Flowchart
Algorithm
start
Read
Calc
Read Module
1000
1. Read Hours,
Payrate
2. Exit
Print
false
start
Read
Hours, Payrate
exit
No more
employee
True
end
start
GrossPay = Hours * Payrate
Algorithm
Print Module
3000
1. Print Pay
2. Exit
exit
KUKUM Sem1-06/07
Flowchart
EKT120: Computer Programming
Flowchart
start
Print
GrossPay
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
KUKUM Sem1-06/07
EKT120: Computer Programming
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
KUKUM Sem1-06/07
EKT120: Computer Programming
33
Software


Application software : performs specific tasks
There are two types:



Program to solve specific problems
Program written by user to solve specified
problem
E.g word processor, desktop publishing
software, spreadsheets, database, graphics,
communication, program perform a specific
task such as accounting, scientific,
engineering, education etc
KUKUM Sem1-06/07
EKT120: Computer Programming
34
Programming Languages

Programming language is divided into
three categories:


Machine Language
High-Level Language
KUKUM Sem1-06/07
EKT120: Computer Programming
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
KUKUM Sem1-06/07
EKT120: Computer Programming
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
E.g LOAD rate
MULT
STOR
KUKUM Sem1-06/07
hour
wages
EKT120: Computer Programming
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.
KUKUM Sem1-06/07
EKT120: Computer Programming
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.
KUKUM Sem1-06/07
EKT120: Computer Programming
39
End Week 1 – Session 1
Q & A!
KUKUM Sem1-06/07
EKT120: Computer Programming
40