+ All Categories
Home > Documents > KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

Date post: 03-Jan-2016
Category:
Upload: linette-butler
View: 221 times
Download: 3 times
Share this document with a friend
Popular Tags:
40
KUKUM Sem1-06/07 EKT120: Computer Programm ing 1 Week 1 – Session 1
Transcript
Page 1: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

1

Week 1 – Session 1

Page 2: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

2

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

Page 3: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

3

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

Page 4: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

4

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

Page 5: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

5

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

Page 6: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

6

Outline General Problem Solving Concept

The six Steps in Problem Solving Problem Solving Concepts for the Computer

Computer Fundamental Data - Constant and Variable Data Type

Problem Solving Tool Problem Analysis Chart Structured Chart IPO Chart Algorithm Pseudocode and Flowchart

Software System Software Application Software

Page 7: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

7

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

Page 8: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

8

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.

Page 9: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

9

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

Page 10: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

10

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.

Page 11: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

11

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

Page 12: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

12

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.

Page 13: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

13

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.

Page 14: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

14

Continue …

Identify alternative Watch television, Invite friends over, Play

games, go outing. Complete the list until you can’t find any more alternatives.

Select the best way to solve the problem 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.

Page 15: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

15

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.

Page 16: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

16

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.

Page 17: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

17

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.

Input Device Output Device

Secondary Memory

CPU

Main Memory

Page 18: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

18

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.

Page 19: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

19

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

Page 20: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

20

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

Page 21: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

21

Example Constant And Variable

Constant Variable

Rule: Cannot be change.Example:Value:

Value:

Named Constant: Cannot be changed after initially given a value. Storage Loacation has a nameExample: Pi

Value

Rule: Storage lacation given nameValues of the content can be change.Refered by name in the instruction.

ExampleVariable Name – AgeVariable Name - Name

25

“selamat datang”

3.142857

20

“Marina”

Page 22: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

22

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.

ComputerData process

into Infomation

Data(Unorganized fact)

Output(report/information)

input output

Page 23: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

23

Data Types Continue …

Numerical Data: include all type of numbers. The only data used for

calculation. They are integers and real numbers Character Data – Alphanumeric Data

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

Page 24: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

24

Example of Data Types

Data Data Type ExplainationThe 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

Page 25: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

25

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.

Page 26: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

26

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

HoursPay Rate

Gross Pay

Processing Required Solution Alternative

Gross Pay = Hours * Pay Rate 1. Define the hours worked and pay rate as constant

2. Define the hours worked and pay rate as input values

Page 27: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

27

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: PAYROLL0000

READ1000

CALC2000

PRINT3000

Page 28: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

28

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 Number

Output

All input data (section 1 of PAC)

All processing in steps (section 3 & 4 of PAC)

Module Reference from structure chart

All output requirements (section 1 & 2 from PAC)

Input Processing Module Reference Number

Output

Hours WorkPay rate

1. Enter hours work2. Enter Pay rate3. Calculate Pay4. Print Pay5. End

10001000200030000000

Gross Pay

Page 29: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

29

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.

Page 30: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

30

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 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

counterA B

S

Page 31: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

31

Flowchart-(E.g from previous)

Algorithm Flowchart Algorithm Flowchart

Main Module1. Repeat Process Read Process Calc Process Print Until no more employee2. End

Read Module10001. Read Hours, Payrate2. Exit

Algorithm Algorithm Flowchart

Calc Modul 20001. GrossPay = Hour * payrate2. Exit

Print Module30001. Print Pay2. Exit

Read

Calc

Print

No moreemployee

end

start

True

false

start

Read Hours, Payrate

exit

start

GrossPay = Hours * Payrate

exit

start

exit

PrintGrossPay

Page 32: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

32

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

Page 33: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

33

Software

System software : software manages the computer and its peripheral devices (hardware) E.g. Operating systems(OS) Text editor Preprocessor Language translator Linker Loader

Page 34: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

34

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

Page 35: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

35

Programming Languages

Programming language is divided into three categories: Machine Language High-Level Language

Page 36: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

36

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

Page 37: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

37

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 rateMULT hourSTOR wages

Page 38: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

38

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.

Page 39: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

39

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.

Page 40: KUKUM Sem1-06/07EKT120: Computer Programming1 Week 1 – Session 1.

KUKUM Sem1-06/07

EKT120: Computer Programming

40

End Week 1 – Session 1

Q & A!


Recommended