Chapter 2 - Problem Solving Techniques [Part2]I

  • Published on
    24-Jan-2016

  • View
    8

  • Download
    0

DESCRIPTION

Programming

Transcript

<ul><li><p>Prepared by Norhamreeza Abdul Hamid </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Computer </p><p>programmer </p><p>WHAT Program ?? </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Steps used to solve problem in computer programming </p><p>Also known as Software/ System </p><p>Development Life Cycle (SDLC) or software </p><p>process </p><p>A development of a software/computer </p><p>program product. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Specify problem </p><p>Analyze problem </p><p>Design algorithm </p><p>Implement algorithm </p><p>Test and verify program </p><p>Maintain and update program </p><p>Steps </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>STATE What problem to be solved? </p><p>What is the problem? </p><p>Is it possible to solve </p><p>the problem with </p><p>programming? </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>State the problem clearly Gain a clear </p><p>understanding of </p><p>what are </p><p>required for its </p><p>solution. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Given the value of x is 10 and a is 12, find the result of the following equation: </p><p> y = 2x + a - 6 </p><p>What is the problem? </p><p>Is it possible to </p><p>solve the problem </p><p>with </p><p>programming? </p><p>What to solve? </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Problem What is the value of y? </p><p>Data Given the value of x and a </p><p>Solution Solve the equation using the given values </p><p>State the problem clearly </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>IDENTIFY </p><p>Input Output </p><p>Process </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Given the value of x is 10 and a is 12, find the result of the following equation: </p><p> y = 2x + a - 6 </p><p>Input </p><p>Output </p><p>Process </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Input Value of x and a </p><p>Process Replace the value of x and a in the formula, y = 2x +a -6 </p><p>Output The value of the equation, y </p><p>Identify the problem </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Develop a list of steps </p><p>called algorithm </p><p>Verify that the algorithm </p><p>solves the problem </p><p>Solve Problem </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Convert algorithm into </p><p>programming </p><p>Writing program </p><p>Also known as </p><p>CODING </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Coding </p><p>General steps involved </p><p>Documentation </p><p>Compile </p><p>Execute/Run </p><p>Write program code with </p><p>specific programming language </p><p>in specific programming </p><p>tools/software Write explaination/description </p><p>for </p><p>each line of codes/comment for </p><p>future references </p><p>Using tool/software function to </p><p>check errors in program code </p><p>Using tool/software function </p><p>to display output of program </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>To verify the program can </p><p>works as desired </p><p>Testing program </p><p>Executing program to see if it </p><p>produce correct results.If not </p><p>do debugging. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Remove undetected errors </p><p>and keep up-to-date </p><p>Modifying program </p><p>USE and MODIFY the program </p><p>to meet changing requirements </p><p>or correct errors that show up </p><p>in using it </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Specify problem </p><p>Analyze problem </p><p>Design algorithm </p><p>Implement algorithm </p><p>Test and verify program </p><p>Maintain and update program </p><p>Steps </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Algorithm Pseudocode Flowchart Control </p><p>Structure </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the </p><p>computer to solve something for you. </p><p> Problem solving is the process of transforming the description of a problem into a solution by using our </p><p>knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving </p><p>strategies, techniques and tools. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Going to FSKTM from </p><p>FKAAS . </p><p>Making a delicious </p><p>chocolate cake. </p><p>Installing a software </p><p>into a pc. </p><p>Log into a system. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>How to make a delicious chocolate cake? </p><p>Prepare the ingredients. Beat the butter and the eggs. Mix with cake flour and sugar. Add chocolate to the mixture. Pour the mixture Put the mixture in the oven. Bake for 45 minutes. Wipe chocolate cream around the baked cake. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>How to install a software into a pc? </p><p>Put the software CD in the CD driver. Open the CD directory in pc. Click the installer file in the CD, install.exe. Follow the setup instructions for installation process. Or use Control Panel &gt; Add programs. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>How to log into an online system? </p><p>If you are a registered user, Enter your ID or username Enter your password Click on the submit button </p><p>If you are not registered, do the registration process by filling in the registration form. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>How to go to FSKTM from FKAAS? </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Withdraw money from ATM machine </p><p> Register subjects through online system </p><p> Buy cold drinks from vending machine </p><p> Calculate the monthly salary payment </p><p> Calculate car loan interest </p><p> Determine odd and even numbers </p><p> Count the total visitor of a Web </p><p> Determine air velocity in physic lab </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Writing computer program </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Algorithm is a sequence of a finite number of steps arranged in a specific logical order to produce the solution for a problem. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Steps in </p><p>Computer program </p><p>for computer </p><p>to do its job </p><p>Famous muslim scientist/ </p><p>mathematician </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Procedure or formula </p><p>for solving problem </p><p>Sequence set of </p><p>steps taken to </p><p>solve a problem </p><p>Instructions for actions to be executed by computer </p><p>(input/process/output) </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Algorithm Requirements </p><p>Must have input </p><p>Must produce output </p><p>Unambiguous </p><p>Generality Correctness </p><p>Finiteness </p><p>Efficiency </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Step 1: Go to the taxi stand. </p><p>Step 2: Get in a taxi. </p><p>Step 3: Give the taxi driver the destination </p><p>address. </p><p>Step 4: Once arrived, pay the taxi fare. </p><p>Step 5: Get out from the taxi. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Step 1: Go to the ATM machine. </p><p>Step 2: Insert ATM card. </p><p>Step 3: Select language. </p><p>Step 4: Enter pin number. </p><p>Step 5: Select withdrawal option from menu. </p><p>Step 6: Enter amount of money to withdraw. </p><p>Step 7: Take the money. </p><p>Step 8: Take the bank slip. </p><p>Example 2: Money withdrawal algorithm </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Do computer can really understand algorithm? </p><p>Algorithm is used by programmer to plan </p><p>the instructions to be written in the </p><p>computer program and executed by </p><p>computer </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Pseudocode is a semiformal, English-like language with limited vocabulary that can be used to design &amp; describe algorithms. </p><p> Purpose: to define the procedural logic of an algorithm in a simple, easy-to-understand for its readers. </p><p> Free of syntactical complications of programming language. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>A text-based design tool that helps programmers to develop algorithm </p><p>Using natural language (communication </p><p>language e.g: Malay/English) wording </p><p>phrase </p><p>Compact and informal </p><p>high level language description of a </p><p>computer programming </p><p>algorithm </p><p>Simple codes which </p><p>resembles program code that </p><p>will be written during </p><p>implementation phase </p><p>(program coding) </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>i. Consists of a statement of instructions in sequence. </p><p>ii. Every steps consists of keyword which explain the </p><p>actions/operation/process to be executed by </p><p>computers </p><p>iii. Every steps should be written in different steps, if </p><p>continued, the next row must be indented. </p><p>iv. Can use IF/ELSE for conditional statement and WHILE, </p><p>DO/WHILE and FOR repetition statement </p><p>v. Every steps should use clear statements and easy to </p><p>understand. </p><p>vi. Use START to represent the beginning of the operation and END to show the end of the operation. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>START </p><p>IF student's grade is greater than or equal to 40 </p><p> PRINT the statement "passed" </p><p>ELSE </p><p> PRINT the statement "failed" </p><p>ENDIF </p><p>END </p><p>Keyword? </p><p>print means display on the </p><p>screen monitor </p><p>START </p><p>IF credit card number is valid </p><p>execute transaction based on number and </p><p>order </p><p>ELSE </p><p> SHOW a generic failure message </p><p>ENDIF </p><p>END </p><p>show also means </p><p>display on the screen monitor </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>START </p><p>SET total to zero SET grade counter to one </p><p>WHILE grade counter is less than or equal to </p><p>ten </p><p> INPUT the next grade </p><p> ADD the grade into the total ENDWHILE </p><p>SET the class average to the total divided </p><p>by ten PRINT the class average. </p><p>END </p><p>set means assign the value,e.g: total = 0 </p><p>while is used whenever </p><p>the process is to be </p><p>continued </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Write the pseudo code based on the IPO (input/process/output) which you have identified during </p><p>the analyzing phase </p><p>Identify the keyword(s) based on the IPO </p><p>Did you remember the steps weve done in earlier? </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Input Value of x and a </p><p>Process Replace the value of x and a in the formula, y = 2x +a -6 </p><p>Output The value of the equation, y </p><p>Identify the problem </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Given the value of x is 10 and a is 12, find the result of the following equation: </p><p> y = 2x + a - 6 START </p><p>SET the value of x to 10 SET the value of a to 12 COMPUTE the value of y as y = 2x + a - 6 DISPLAY/PRINT the result (or the value of y) </p><p>END </p><p>Write a </p><p>program! </p><p>Keyword Keyword Keyword </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Uncle Rahman wants to buy 5 tins of paint from Marias shop. The price of each tin of the paint is RM 15.60. Calculate the price which Uncle Rahman have to pay for all the tin of paints he bought. </p><p>START SET the amount of paint to 5 SET the price per tin to 15.60 COMPUTE the total price as price per tin times by amount of paint DISPLAY/PRINT the result (or the total price) </p><p>END </p><p>Write a </p><p>program! </p><p>Keyword</p><p>? </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> START </p><p>READ the student mark IF mark is greater than 85 and mark is less than 100 set grade as A ENDIF DISPLAY/PRINT the grade </p><p>END </p><p>Keyword Keyword </p><p>Keyword </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>A box has height, width and length. Write the pseudo code to calculate the volume of a box. </p><p>Test your </p><p>understanding! </p><p>Write the pseudo code to calculate salary of an employee for a month. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> START </p><p>INPUT/READ height, width, length CALCULATE the volume = height * width * length PRINT/DISPLAY volume </p><p>END START </p><p>INPUT/READ salary per day CALCULATE the salary= salary per day*30 days PRINT/DISPLAY salary </p><p>END </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>START READ/INPUT pure volume, total rock CALCULATE porosity = (pure volume / total rock volume) x 100% DISPLAY porosity </p><p>END </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Flowchart is a graph of geometrical shapes that are connected by lines. </p><p> 2 important elements in flowchart: Geometrical shapes represent type of </p><p>statements in the algorithm. Flow line show the order in which the </p><p>statements of an algorithm are executed. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Schematic representation of an </p><p>algorithm or process </p><p> Helps to visualize the content/steps better or to find </p><p>flaws in process </p><p> Illustrate the steps in the process </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Start/End </p><p>The terminator symbol marks </p><p>the starting or ending point of </p><p>the system. It usually contains </p><p>the word "Start" or "End." </p><p>Action or Process </p><p>A box can represent a single </p><p>step ("add two cups of flour"), </p><p>or and entire sub-process </p><p>("make bread") within a larger </p><p>process. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Decision A decision or branching </p><p>point. Lines representing </p><p>different decisions emerge </p><p>from different points of the </p><p>diamond. </p><p>Input/Output Represents material or </p><p>information entering or </p><p>leaving the system, such as </p><p>customer order (input) or a </p><p>product (output). </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Flow Line </p><p>Lines indicate the sequence </p><p>of steps and the direction of </p><p>flow. </p><p>Connector </p><p>Indicates that the flow </p><p>continues where a matching </p><p>symbol (containing the same </p><p>letter) has been placed. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Off Page </p><p>Indicates that the process </p><p>continues off page. </p><p>Database </p><p>Indicates a list of information </p><p>with a standard structure that </p><p>allows for searching and </p><p>sorting. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>What software use </p><p>to draw flowchart? </p><p>You can use </p><p>Ms word &gt; </p><p>AutoShapes &gt; </p><p>Flowchart or </p><p>other flowchart </p><p>drawing tools </p><p>e.g: SmartDraw/Visio </p><p>Drawing,etc. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Given the value of x is 10 and a is 12, find the result of the following equation: </p><p> y = 2x + a - 6 START </p><p>SET the value of x to 10 SET the value of a to 12 compute the value of y as y = 2x + a -6 DISPLAY/PRINT the result (or the value of y) </p><p>END </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Start </p><p>End </p><p>y = 2x + a - 6 </p><p>Print y </p><p>Set x = 10 </p><p>Set a = 12 </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>START SET the amount of paint to 5 COMPUTE the total price as price per tin times by amount of paint DISPLAY/PRINT the result (or the total price) </p><p>END Convert to </p><p>flowchart </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Start </p><p> total price = amount of paint * price per tin </p><p>Display total price </p><p>End </p><p> Set amount of paint = 5 </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>A box has height, width and length. Write the pseudo code to calculate the volume of a box. </p><p>Write the pseudo code to calculate salary of an employee for a month. </p><p>Convert </p><p>to </p><p>flowchart </p><p>Convert </p><p>to </p><p>flowchart </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Given the following formula, write the pseudo code to calculate the porosity of rock: porosity = (pure volume /total rock volume) x 100% </p><p>Convert to </p><p>flowchart </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Start </p><p>Read height, width, </p><p>length </p><p>volume = height * width * length </p><p>Display volume </p><p>End </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Start </p><p>Read salary per day </p><p>salary = salary per day * 30 days </p><p>Display salary </p><p>End </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Start </p><p>Read pure volume, </p><p>total rock volume </p><p>porosity = (pure volume / total rock </p><p>volume) x 100% </p><p>Display porosity </p><p>End </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> Sequential Selection Repetition </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p>Sequence: A series of steps or statements that are executed in the order they are written in an algorithm. </p><p>Selection: Defines two courses of action depending on the outcome of a condition. A condition is an expression that is, when computed, evaluated to either true or false. </p><p>Repetition: Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> You may have more </p><p>than one control </p><p>structure in one program </p><p>in order to solve a </p><p>problem. </p></li><li><p>Prepared by Norhamreeza Abdul Hamid </p><p> A series of steps or statements that are executed in the order they are written in an algorithm. </p><p> The beginning and end of a block of statements can be opti...</p></li></ul>

Recommended

View more >