Week 1 Session 1 KUKUM Sem 1 0607

  • Slides: 40
Download presentation
Week 1 – Session 1 KUKUM Sem 1 -06/07 EKT 120: Computer Programming 1

Week 1 – Session 1 KUKUM Sem 1 -06/07 EKT 120: Computer Programming 1

General Information n n Syllabus – refer handout Contributes 4 units: n n n

General Information n n Syllabus – refer handout Contributes 4 units: n n n 2 hours - lectures 4 hours – lab and tutorial Main Objective: n Students can independently write a computer program to solve calculation problems, especially those related to engineering KUKUM Sem 1 -06/07 EKT 120: Computer Programming 2

Overall Evaluation n 4 main components: n n n Assignments (30%) 1 st &

Overall Evaluation n 4 main components: n n n Assignments (30%) 1 st & 2 nd 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 Sem 1 -06/07 EKT 120: Computer Programming 3

References n Text Book n “ C Programming for Engineering & Computer Science ”

References n Text Book n “ C Programming for Engineering & Computer Science ” H. H. Tan and T. B. Orazio, Mc Graw Hill, 1999. n References n n “C Programming”, Dietal & Dietal “Problem Solving and Programming Concept”, Maureen Sprankle, 6 th Ed. Any other C books WWW KUKUM Sem 1 -06/07 EKT 120: Computer Programming 4

Notes n n This course is NOT about the language per se, it’s about

Notes n n 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 Sem 1 -06/07 EKT 120: Computer Programming 5

Outline n General Problem Solving Concept n n Problem Solving Concepts for the Computer

Outline n General Problem Solving Concept n n Problem Solving Concepts for the Computer n n Computer Fundamental Data - Constant and Variable Data Type Problem Solving Tool n n n The six Steps in Problem Solving Problem Analysis Chart Structured Chart IPO Chart Algorithm Pseudocode and Flowchart Software n n System Software Application Software KUKUM Sem 1 -06/07 EKT 120: Computer Programming 6

General Problem Solving Concept n n n People make decisions every day that affect

General Problem Solving Concept n n n 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. n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 7

Understand the Problem n n Understand what is involved in the problem. knowledge base

Understand the Problem n n Understand what is involved in the problem. knowledge base of the person or machine resources. n n 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 Sem 1 -06/07 EKT 120: Computer Programming 8

Identify Alternative way n n Identify several way, how to solve the problem, but

Identify Alternative way n n 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 Sem 1 -06/07 EKT 120: Computer Programming 9

Select the best way of the alternative solution n Here need to identify and

Select the best way of the alternative solution n 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 Sem 1 -06/07 EKT 120: Computer Programming 10

List the Instructions n n n List down the step-by-step numbered instruction enable to

List the Instructions n n n 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 n n n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 11

Evaluate the Solution n Check the result: n n Correct or not. Satisfy the

Evaluate the Solution n Check the result: n n Correct or not. Satisfy the need of the person or not Note: the result may be correct but not satisfy the person E. g n The steps you have directed the person might be right, but the person does not drive. KUKUM Sem 1 -06/07 EKT 120: Computer Programming 12

Example – A problem What to do this evening n n Identify the problem:

Example – A problem What to do this evening n n Identify the problem: How do individual wish to spend the evening. Understand The problem: n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 13

Continue … n Identify alternative n n Select the best way to solve the

Continue … n Identify alternative n n Select the best way to solve the problem n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 14

Types of Problems n n Algorithmic Solution – problem can be solved with a

Types of Problems n n 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 Sem 1 -06/07 EKT 120: Computer Programming 15

Problem Solving with Computer n n n Solution means the instructions that must follow

Problem Solving with Computer n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 16

Problem Solving Concept with Computer n Computer Fundamental n n n CPU – where

Problem Solving Concept with Computer n Computer Fundamental n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 17

Problem Solving Concept For Computer n Problem that can be solve with computers generally

Problem Solving Concept For Computer n Problem that can be solve with computers generally consist of three: n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 18

Constant and Variable (Data) n n n The most fundamental concept of problem solving

Constant and Variable (Data) n n n 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: n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 19

Continue … n Variable: n n Value of a variable may changed during processing

Continue … n Variable: n n 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 Sem 1 -06/07 EKT 120: Computer Programming 20

Example Constant And Variable Constant Variable Rule: Cannot be change. Example: Value: 25 Rule:

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 Sem 1 -06/07 Storage lacation given name Values of the content can be change. Refered by name in the instruction. EKT 120: Computer Programming 21

Data Types n n n Data is unorganized facts, they go into computer as

Data Types n n n 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 Sem 1 -06/07 input Computer Data process output Output into (report/information) Infomation EKT 120: Computer Programming 22

Data Types Continue … n Numerical Data: n n Character Data – Alphanumeric Data

Data Types Continue … n Numerical Data: n n Character Data – Alphanumeric Data n n 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 n n consist of two pieces of data in the data set, TRUE and FALSE. There are use in making yes-no decision KUKUM Sem 1 -06/07 EKT 120: Computer Programming 23

Example of Data Types Data Type Explaination The price of item: 7. 55, 12.

Example of Data Types Data Type Explaination The price of item: 7. 55, 12. 99 Numerical: Real Would be use in the calculation An Account Number: “A 444440” 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 Sem 1 -06/07 EKT 120: Computer Programming 24

Organizing The Problem n There are several organizational tool can be used in problem

Organizing The Problem n There are several organizational tool can be used in problem solving n n n 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. n KUKUM Sem 1 -06/07 EKT 120: Computer Programming 25

Problem Analysis Chart (PAC) n Consist of 4 separate parts n n n Section

Problem Analysis Chart (PAC) n Consist of 4 separate parts n n n 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 Sem 1 -06/07 Define the hours worked and pay rate as constant Define the hours worked and pay rate as input values EKT 120: Computer Programming 26

Structured Chart n n n Divide the problem into subtasks called modules or smaller

Structured Chart n n n 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 Sem 1 -06/07 CALC 2000 EKT 120: Computer Programming PRINT 3000 27

IPO (Input-Processing-Output) Chart n n IPO Extends and organizes the information in the problem

IPO (Input-Processing-Output) Chart n n 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 Sem 1 -06/07 1. 2. 3. 4. 5. Enter hours work Enter Pay rate Calculate Pay Print Pay End Module Reference Number Module Reference from structure chart Module Reference Number 1000 2000 3000 0000 EKT 120: Computer Programming Output All output requirements (section 1 & 2 from PAC) Output Gross Pay 28

Algorithms n n Organizing the solution where programmer develop a set of instruction for

Algorithms n n 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 Sem 1 -06/07 EKT 120: Computer Programming 29

Algorithm-Basic symbols of flowchart Flowchart Symbol Explanation Flowlines Flow of the direction Start /

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 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 Sem 1 -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 EKT 120: Computer Programming 30

Flowchart-(E. g from previous) Algorithm Main Module 1. Repeat Process Read Process Calc Process

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. Gross. Pay = 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 Gross. Pay = Hours * Payrate Algorithm Print Module 3000 1. Print Pay 2. Exit exit KUKUM Sem 1 -06/07 Flowchart EKT 120: Computer Programming Flowchart start Print Gross. Pay exit 31

Software n n Software is a program of the solution for a specific task

Software n n Software is a program of the solution for a specific task that programmer develop. In computer science software classified into : n n System software Application software KUKUM Sem 1 -06/07 EKT 120: Computer Programming 32

Software n System software : software manages the computer and its peripheral devices (hardware)

Software n System software : software manages the computer and its peripheral devices (hardware) n n n E. g. Operating systems(OS) Text editor Preprocessor Language translator Linker Loader KUKUM Sem 1 -06/07 EKT 120: Computer Programming 33

Software n n Application software : performs specific tasks There are two types: n

Software n n Application software : performs specific tasks There are two types: n n n 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 Sem 1 -06/07 EKT 120: Computer Programming 34

Programming Languages n Programming language is divided into three categories: n n Machine Language

Programming Languages n Programming language is divided into three categories: n n Machine Language High-Level Language KUKUM Sem 1 -06/07 EKT 120: Computer Programming 35

Machine Language n n n n Language understood by the computer Bunch of 0’s

Machine Language n n n n 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 n 0101 0001 1100 0100 1011 1000 KUKUM Sem 1 -06/07 EKT 120: Computer Programming 36

Assembly Language n n It is a low level programming language. To make it

Assembly Language n n 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 written E. g LOAD rate MULT STOR KUKUM Sem 1 -06/07 hour wages EKT 120: Computer Programming 37

Assembly Language n n Nevertheless, need language translator called Assembler to change Assembly Language

Assembly Language n n 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 Sem 1 -06/07 EKT 120: Computer Programming 38

High-Level Language n n Example of high level programming language are, PASCAL, C -

High-Level Language n n 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. n 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 Sem 1 -06/07 EKT 120: Computer Programming 39

End Week 1 – Session 1 Q & A! KUKUM Sem 1 -06/07 EKT

End Week 1 – Session 1 Q & A! KUKUM Sem 1 -06/07 EKT 120: Computer Programming 40