Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 EKT 120/4 : Computer Programming By: Mr. Mohd. Nazrin Md. Isa Contact me at :

Similar presentations


Presentation on theme: "1 EKT 120/4 : Computer Programming By: Mr. Mohd. Nazrin Md. Isa Contact me at :"— Presentation transcript:

1 1 EKT 120/4 : Computer Programming By: Mr. Mohd. Nazrin Md. Isa Contact me at :

2 2 General Information Syllabus – refer handout Syllabus – refer handout Contributes 4 units: Contributes 4 units:  2 hours - lectures  4 hours – lab and tutorial Main Objective: Main Objective:  Students can independently write a computer program to solve calculation problems, especially those related to engineering

3 3 Overall Evaluation 4 main components: 4 main components:  Assignments (30%)  1st & 2nd Test (15% +25%)  Group Mini-project (30%) Assignments are individual lab Assignments are individual lab The two tests are written tests The two tests are written tests Project : Max number of group member is 2 Project : Max number of group member is 2

4 4 References Text Book Text Book  “ C Programming for Engineering & Computer Science ” H.H.Tan and T.B.Orazio, Mc Graw Hill, References References  “C Programming”, Deitel & Deitel  “Problem Solving and Programming Concept”, Maureen Sprankle, 6 th Ed.  Any other C books  WWW

5 5 Notes This course is NOT about the language per se, it’s about problem solving / analytical skills & to apply C to solve problems. 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 Write C program in Linux environment Please do early reading Please do early reading Do not hesitate to ask during lecture sessions Do not hesitate to ask during lecture sessions

6 6 Outline General Problem Solving Concept General Problem Solving Concept  The six Steps in Problem Solving Problem Solving Concepts for the Computer Problem Solving Concepts for the Computer  Computer Fundamental  Data - Constant and Variable  Data Type Problem Solving Tool Problem Solving Tool  Problem Analysis Chart  Structured Chart  IPO Chart  Algorithm  Pseudocode and Flowchart Software Software  System Software  Application Software

7 7 General Problem Solving Concept People make decisions every day that affect their lives. 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) 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. 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

8 8 Understand the Problem Understand what is involved in the problem. Understand what is involved in the problem. knowledge base of the person or machine resources. 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.

9 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. 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 E.g. Direction to KWSP from Jejawi

10 10 Select the best way of the alternative solution Here need to identify and evaluate the pros and cons of each possible 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. 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. E.g. Which is the fastest and shortest way to KWSP from Jejawi.

11 11 List the Instructions List down the step-by-step numbered instruction enable to solve the problem using the selected solution. 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. All the instruction should be understand by the targeted person or the machine. E.g 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

12 12 Evaluate the Solution Check the result: 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.

13 13 Example – A problem What to do this evening Identify the problem: How do individual wish to spend the evening. Identify the problem: How do individual wish to spend the evening. Understand The problem: 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.

14 14 Continue … Identify alternative 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 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. Prepare the list of instruction. Evaluate the solution. Everybody satisfy with the solution. Are we having fun? Etc. Evaluate the solution. Everybody satisfy with the solution. Are we having fun? Etc.

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

16 16 Problem Solving with Computer Solution means the instructions that must follow to produce the best results. Solution means the instructions that must follow to produce the best results. Results mean the outcome or completed computer – assisted answer. 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. Program means the set of instructions that make up the solution after they have been coded into a particular computer language.

17 17 Problem Solving Concept with Computer Computer Fundamental 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

18 18 Problem Solving Concept For Computer Problem that can be solve with computers generally consist of three: 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.

19 19 Constant and Variable (Data) The most fundamental concept of problem solving for computer 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. Computer use constant and variable to solve problem. They are actually the data used in the processing. Constant: 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

20 20 Continue … Variable: 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

21 21 Example Constant And Variable ConstantVariable Rule: Cannot be change. Example:Value:Value: Named Constant: Cannot be changed after initially given a value. Storage Loacation has a name Example: Pi ValueRule: Storage lacation given name Values of the content can be change. Refered by name in the instruction. Example Variable Name – Age Variable Name - Name 25 “selamat datang” “Marina”

22 22 Data Types Data is unorganized facts, they go into computer as an input and are processed by the program. 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. 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. 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. 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. The most common data types are numerical, character (alphabetical), and logical. Computer Data process into Infomation Data (Unorganized fact) Output (report/information) input output

23 23 Data Types Continue … Numerical Data: Numerical Data:  include all type of numbers. The only data used for calculation. They are integers and real numbers Character Data – Alphanumeric Data 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 Logical  consist of two pieces of data in the data set, TRUE and FALSE.  There are use in making yes-no decision

24 24 Example of Data Types Data Data Type Explanation The price of item: 7.55, Numerical: Real Real Would be use in the calculation An Account Number: “A444440”Character: String String Consist of alphanumeric or simply numbers, cannot use in calculation QuantityNumerical: integer 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

25 25 Organizing The Problem There are several organizational tool can be used in problem solving 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 processing and the output Algorithm is the sequence of instructions comprising the solution Algorithm is the sequence of instructions comprising the solution Flowcharts is the graphic representations of the algorithm. Flowcharts is the graphic representations of the algorithm.

26 26 Problem Analysis Chart (PAC) Consist of 4 separate parts 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. Define the hours worked and pay rate as constant 2. Define the hours worked and pay rate as input values

27 27 Structured Chart Divide the problem into subtasks called modules or smaller subtasks. 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. 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 Use Top-Down Solution method Main: PAYROLL 0000 READ 1000 CALC 2000 PRINT 3000

28 28 IPO (Input-Processing-Output) Chart IPO Extends and organizes the information in the problem analysis 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 Shows more detail what data items are inputs what processing takes place on the data, and what InputProcessing 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) InputProcessing Module Reference Number Output Hours Work Pay rate 1. Enter hours work 2. Enter Pay rate 3. Calculate Pay 4. Print Pay 5. End Gross Pay

29 29 Algorithms Organizing the solution where programmer develop a set of instruction for the computer and this is call algorithm. Organizing the solution where programmer develop a set of instruction for the computer and this is call algorithm. Pseudo code may be use, it is close to the actual programming language that the programmer will used later. Pseudo code 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. To complete it, the programmer will write another separate set of instruction (coding/program) that will be understand by the computer. Instead of Pseudo code, we can also represent the set of instruction in term of Flowchart ( a graphic presentation of the algorithm. Instead of Pseudo code, we can also represent the set of instruction in term of Flowchart ( a graphic presentation of the algorithm.

30 30 Algorithm-Basic symbols of flowchart Flowchart Symbol Explanation Flow lines 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 counter AB S

31 31 Flowchart-(cont’d) AlgorithmFlowchartAlgorithmFlowchart Main Module 1. Repeat Process Read Process Read Process Calc Process Calc Process Print Process Print Until no more Until no more employee employee 2. End Read Module Read Hours, Pay rate 2. Exit AlgorithmAlgorithmFlowchart Calc Modul GrossPay = Hour * payrate 2. Exit Print Module Print Pay 2. Exit Read Calc Print No more employee end start True false start Read Hours, Payrate exit start GrossPay = Hours * Payrate exit start exit Print GrossPay

32 32 Software Software is a program of the solution for a specific task that programmer develop. Software is a program of the solution for a specific task that programmer develop. In computer science software are classified into : In computer science software are classified into :  System software  Application software

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

34 34 Software Application software : performs specific tasks Application software : performs specific tasks There are two types: 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 E.g word processor, desktop publishing software, spreadsheets, database, graphics, communication, program perform a specific task such as accounting, scientific, engineering, education etc

35 35 Programming Languages Programming language is divided into three categories: Programming language is divided into three categories:  Machine Language  Assembly Language  High-Level Language

36 36 Machine Language Language understood by the computer Language understood by the computer Bunch of 0’s and 1’s Bunch of 0’s and 1’s Program written in machine language can be executed without being translated 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 Nevertheless, hard to learn because it is written in 0’s and 1’s Program is too long to solve simple problem Program is too long to solve simple problem Machine-dependant and not portable Machine-dependant and not portable E.g E.g 

37 37 Assembly Language It is a low level programming 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 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 So easier to understand and written E.g E.g LOAD rate MULThour STORwages

38 38 Assembly Language Nevertheless, need language translator called Assembler to change Assembly Language to Machine Code for execution purpose 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. Assembler is a type of system software, that we use to translate our assembly code into binary code (understand by computer.

39 39 High-Level Language Example of high level programming language are, PASCAL, C - Language, Java, Visual Basic etc 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. 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. 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. Compiler is a type of system software that we use to compile our C code.

40 40 Thank you End of lecture #01 Any questions??? The following exercises are to be completed during lab 1) Exercise 1 2) Exercise 2


Download ppt "1 EKT 120/4 : Computer Programming By: Mr. Mohd. Nazrin Md. Isa Contact me at :"

Similar presentations


Ads by Google