Chapter One Problem Solving Objectives: 1- Understand what is “ Programming”? 2- Define “Problem” & “ Problem Solving”. 3- Identify the 5- Stages of Problem Solving. 4-Writing “ Algorithm” 5-Draw “ Flow Chart”
1- Understand what is “ Programming”? Eat a meal Cook that meal Buy A Robot Build A Robot Use a Game / Software Create yours with your OWN Criteria Programmer User Programming Languages : C , C++, Basic , Visual C , Visual Basic
2- Define “Problem” & “ Problem Solving”. Objectives Outputs Target/Aim/Goal - Sequence of Steps -Activities Specific Inputs Through Using Attain / Reach Problem Solving Problem
Define : 1- Problem. 2- Problem Solving . Class Activity: Using the Cards _ Group discussion Define : 1- Problem. 2- Problem Solving . Ex: 1- “ Blue Hole” / “Black or White Desert”/ “Cosmic Village” 2- Bake a Cake.
3- “ Problem Solving” Stages (5 Stages) : 1. Define the Problem: Outputs. Inputs. Executing Arithmetic or Logical Operations Example (1): 2 + 3 Example (2): A kid have 100 pounds, bought a dark choc. for 48 pounds & bottle of water for 4 pounds, So ??
3- “ Problem Solving” Stages (5 Stages) Cont. 2. Step by step instructions: Write an Algorithm الخوارزمي 2. Draw a Flow Chart Start Example (1): 2 + 3 Input 2 , 3 Start Inputs : 2, 3 Sum of 2 + 3 Output the Sum. End Sum = 2 + 3 Arrows are Must Output Sum End
Benefits of using Flowcharts: 1- Promotes / facilitate understanding the problem and shows the tasks when writing program codes. 2- Explains the program to others 3- Convenient tool for documenting the program.
The Algorithm is represented by drawing flowcharts. A Group of logically arranged procedures to be executed to attain an output using specific inputs. The Flow Chart is: It’ a diagram uses standard Graphical symbols or shapes to illustrate a sequence of steps required to solve the problem. The Algorithm is represented by drawing flowcharts.
3- “ Problem Solving” Stages (5 Stages) cont. 3. Design the Program: Writing the code Using a programming Language
During writing program code we can make mistake. 3- “ Problem Solving” Stages (5 Stages) cont. 4. Program Testing ( Debug): During writing program code we can make mistake. So, We have to check and enter the data and compare to check the errors and debug / Correct them. Start Inputs : 2, 3 Sum of 2 - 3 Output the Sum. End Example (1): 2 + 3
3- “ Problem Solving” Stages (5 Stages) cont. 5. Program Documentation: Is documenting : Given input – output – plan – for solving the problem – drawn flow chart – programming language – last date modification – people who contribute to the program development Process. WHY ??? To go back for feedback or correction
1 5 2 4 3 Problem Solving Stages Problem Definition Program Documenting -Writing all steps Taken to solve the problem - People Contributed Problem Solving Stages Input-Output-Solution 2 Step by step Instructions 4 Program Testing 3 -Writing Algorithm -Drawing a Flow Chart Program Design check and debug -Writing a code using a Programming Language
Flow Chart: Diagram that uses standard graphical symbols to illustrate: the sequence of steps required for solving a problem or specific question ( the algorithm)
The most commonly used Symbols: Significance (Terminal): Start & End ( Input / Output ) (Process): Arithmetic / Logical (Decision): Yes / No (Flow Lines): Directions
Example(1-1): Second : Algorithm First : Define the Problem Draw a flow chart that will calculate the sum of two numbers entered by the user and display the result: First : Define the Problem Outputs: The sum of Two Numbers Inputs: The 1st number is “A”, The 2nd number is “B” Solution: C = A+B , where C is the result Third : Flow Chart Second : Algorithm 1- Start 2- Enter The Number A and the Number B 3- Perform the SUM using : C=A+B , while C is the output 4- Print C 5- End Start Enter A and B C = A+ B Output C End
Note: Note: Key words Significance Read Input Get Enter Print Output
Example(1-2): First : Define the Problem Third : Flow Chart Draw a flow chart for a program that will compute the Average and the Product of three numbers: First : Define the Problem Outputs: The “Average” & the “Product” of three numbers Inputs: The 1st number is “X”, The 2nd number is “Y”, and the 3rd number is “Z” Solution: Average = (X*Y*Z)/3 and Product= X*Y*Z Third : Flow Chart Second : Algorithm 1- Start 2- Read the values X, Y, Z 3- Average = ( X+Y+Z)/3 and Product = X*Y*Z 4- Print Average and Product 5- End Start Read X, Y, Z Average= (X+Y+Z)/3 Product= X*Y*Z Print Average, Product End
Note In Any Equation: The Left side contains only one variable & it will be the output or the solution of the equation The Right side may contain values or arithmetic expressions that have one or more variables ( Inputs)
Example(1-3): First : Define the Problem Third : Flow Chart Draw a flow chart for solving a first degree equation Y= 3X+2 First : Define the Problem Output: The Value of “Y” Input: X Solution: Compute the value of “Y” from the Equation “ Y= 3X +2 “ Third : Flow Chart Second : Algorithm 1- Start 2- Read the value X 3- Calculate Y= (3*X+2) 4- Print value of Y 5- End Start Input X Y = 3*X+2 Print Y End
Area = L*W and Perimeter = 2*( L+W) Class Activity: 5 Minutes Activity (1-1) Write the Algorithm and Draw the flow chart to compute the area and perimeter of a rectangle, whose length and width are known. Area = L*W and Perimeter = 2*( L+W)
Third : Flow Chart Second : Algorithm First : Define the Problem Output: …………………………………………… Input : …………………………………………… Solution: …………………………………………… Third : Flow Chart Second : Algorithm
Third : Flow Chart Second : Algorithm First : Define the Problem Output: Perimeter , Area of a rectangle Input : L, Where “L” is length & W, where “W” is width Solution: Perimeter = 2*(L+W) , Area = L*W Third : Flow Chart Second : Algorithm 1- Start 2- Read the values: L & W 3- Calculate Perimeter = 2*(L+W) & Area = L*W 4- Print the values of Perimeter & Area 5- End Start Input L , W Perimeter = 2*(L+W) Area = L*W Print Perimeter & Area End
Class Activity: 5 Minutes Activity (1-2) Write the Algorithm and draw the Flow Chart to calculate the area of a cicle whose radius "R" is known Circle Area = 3.14 * R *R
Third : Flow Chart Second : Algorithm First : Define the Problem Output: …………………………………………… Input : …………………………………………… Solution: …………………………………………… Third : Flow Chart Second : Algorithm
Third : Flow Chart Second : Algorithm First : Define the Problem Output: Area of a Circle Input : R, Where “R” is the radius of the circle Solution: Area = 3.14 *R*R Third : Flow Chart Second : Algorithm 1- Start 2- Read the value: R 3- Calculate Area = 3.14 *R *R 4- Print the value Area 5- End Start Input R Area = 3.14 *R*R Print Area End
Homework: Activity (1-3) Write the Algorithm and draw the Flow Chart to calculate the number of years, bearing in mind that the number of months is Known