Presentation on theme: "EKT 120/4 : Computer Programming"— Presentation transcript:
1EKT 120/4 : Computer Programming By:Mr. Mohd. Nazrin Md. IsaContact me at :
2General Information Syllabus – refer handout Contributes 4 units: 2 hours - lectures4 hours – lab and tutorialMain Objective:Students can independently write a computer program to solve calculation problems, especially those related to engineering
3Overall Evaluation 4 main components: Assignments (30%) 1st & 2nd Test (15% +25%)Group Mini-project (30%)Assignments are individual labThe two tests are written testsProject : Max number of group member is 2
4ReferencesText 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 booksWWW
5NotesThis 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 environmentPlease do early readingDo not hesitate to ask during lecture sessions
6Outline General Problem Solving Concept The six Steps in Problem SolvingProblem Solving Concepts for the ComputerComputer FundamentalData - Constant and VariableData TypeProblem Solving ToolProblem Analysis ChartStructured ChartIPO ChartAlgorithmPseudocode and FlowchartSoftwareSystem SoftwareApplication Software
7General 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 youUnderstand the problemIdentify alternative ways to solve the problemSelect the best way to solve the problemList the instruction that enable you yo solve the problemEvaluate the solution
8Understand 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.
9Identify 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
10Select 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.
11List the InstructionsList 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.g1. go straight2. Will pass through round about3. Take 12 o’clock4. 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 turn9. Go further until you reach KWSP buildingEnd
12Evaluate the Solution Check the result: Correct or not. Satisfy the need of the person or notNote: the result may be correct but not satisfy the personE.gThe steps you have directed the person might be right, but the person does not drive.
13Example – 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 consideredSo 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.
14Continue … 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 problemVote 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.
15Types of ProblemsAlgorithmic 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.
16Problem 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.
17Problem Solving Concept with Computer Computer FundamentalCPU – where all the processing take placeMemory – store all data currently processed, before program can be execute, program must be loaded into memoryInput Device – Device use to input data to be processed into computerOutput Device – Device use to display processed data (output)Secondary Memory – Store permanent data (can be as output device.CPUOutput DeviceInput DeviceMain MemorySecondary Memory
18Problem Solving Concept For Computer Problem that can be solve with computers generally consist of three:Computational – problem with mathematical processingLogical – 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.
19Constant and Variable (Data) The most fundamental concept of problem solving for computerComputer 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
20Continue … Variable: Value of a variable may changed during processing Variable must have a nameProgrammer 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
21Example Constant And Variable Rule: Cannot be change.Example:Value:Named Constant: Cannot be changed after initially given a value. Storage Loacation has a nameExample: PiValueRule:Storage lacation given nameValues of the content can be change.Refered by name in the instruction.ExampleVariable Name – AgeVariable Name - Name25“selamat datang”20“Marina”
22(report/information) Data TypesData 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 processintoInfomationoutputinputOutput(report/information)Data(Unorganized fact)
23Data Types Continue … Numerical Data: include all type of numbers. The only data used for calculation. They are integers and real numbersCharacter Data – Alphanumeric DataConsist 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.Logicalconsist of two pieces of data in the data set, TRUE and FALSE.There are use in making yes-no decision
24Example of Data Types Data Data Type Explanation The price of item: 7.55, 12.99Numerical:RealWould be use in the calculationAn Account Number:“A444440”Character:StringConsist of alphanumeric or simply numbers, cannot use in calculationQuantityintegerUse in calculation, Integer because normally as a whole numberA date:10/07/06Date or Character stringIf date data type is available use date, unless use character stringAn answer to a question:True / FalseLogicalAn answer to question: Do you like coffee, is either yes or no, therefore use logical
25Organizing The Problem There are several organizational tool can be used in problem solvingProblem Analysis Chart – the beginning analysis of the problemStructured Chart – shows the overall layout or structure of the solutionIPO Chart – shows the input, the processing and the outputAlgorithm is the sequence of instructions comprising the solutionFlowcharts is the graphic representations of the algorithm.
26Problem Analysis Chart (PAC) Consist of 4 separate partsSection 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 DataRequired ResultHoursPay RateGross PayProcessing RequiredSolution AlternativeGross Pay = Hours * Pay RateDefine the hours worked and pay rate as constantDefine the hours worked and pay rate as input values
27Structured ChartDivide 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
28IPO (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 whatInputProcessingModule Reference NumberOutputAll input data (section 1 of PAC)All processing in steps (section 3 & 4 of PAC)Module Reference from structure chartAll output requirements (section 1 & 2 from PAC)InputProcessingModule Reference NumberOutputHours WorkPay rate1. Enter hours work2. Enter Pay rate3. Calculate Pay4. Print Pay5. End1000200030000000Gross Pay
29AlgorithmsOrganizing 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.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.
30Algorithm-Basic symbols of flowchart Flowchart SymbolExplanationFlow linesFlow of the directionStart / Stop (terminator)A start and an end of a module. For some end for a main module and exit for other moduleProcessingProcessing block, for the calculation, and other step of instructions.Input / Output (I/O)Input and output data to from the computer memory.DecisionUsually has one entrance and two exit.Process ModuleTask that process in different place, moduleAutomatic Counter loopThe number of loop execute will start with A, counter incremented by S, and until the end value BConnector on page off pageFlowchart can be sectioned, the connector will show where the section continuecounterABS
32SoftwareSoftware is a program of the solution for a specific task that programmer develop.In computer science software are classified into :System softwareApplication software
33SoftwareSystem software : software manages the computer and its peripheral devices (hardware)E.g. Operating systems(OS)Text editorPreprocessorLanguage translatorLinkerLoader
34Software Application software : performs specific tasks There are two types:Program to solve specific problemsProgram written by user to solve specified problemE.g word processor, desktop publishing software, spreadsheets, database, graphics, communication, program perform a specific task such as accounting, scientific, engineering, education etc
35Programming Languages Programming language is divided into three categories:Machine LanguageAssembly LanguageHigh-Level Language
36Machine Language Language understood by the computer Bunch of 0’s and 1’sProgram written in machine language can be executed without being translatedNevertheless, hard to learn because it is written in 0’s and 1’sProgram is too long to solve simple problemMachine-dependant and not portableE.g
37Assembly 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 elementSo easier to understand and writtenE.gLOAD rateMULT hourSTOR wages
38Assembly LanguageNevertheless, need language translator called Assembler to change Assembly Language to Machine Code for execution purposeAssembler is a type of system software, that we use to translate our assembly code into binary code (understand by computer.
39High-Level Language E.g. Grosspay := Hourswork * Payrate; Example of high level programming language are, PASCAL, C - Language, Java, Visual Basic etcOne 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.
40Thank you End of lecture #01 Any questions???The following exercises are to be completed during lab1) Exercise 12) Exercise 2