BASIC PROBLEM SOLVING CSC 111 Learning Objectives 2
BASIC PROBLEM SOLVING CSC 111
Learning Objectives 2 Ø In this lecture we will learn 1. Basic steps for designing computer program 2. Algorithm 3. Flow Chart Computer Programming -1
Solving Problems Stages 3 1. Problem Definition � 2. Define the main Problem Analysis � Determine the inputs, outputs, Arithmetic & logic operations Design Solution 3. � Identify the required step for computer to do Computer Programming -1
Problem Definition 4 Write a Program to Print the Sum of two integer Numbers Write a program to Print the Average of three integer numbers Write a program to print the volume of a cube and the sum of it’s surfaces’ areas Computer Programming -1
Problem Analysis 5 Write a Program to Print the Sum of two integer Numbers q Inputs : First Number Second Number Operations : Summation = first + second Output : The summation Computer Programming -1
Problem Analysis 6 Write a program to Print the Average of three integer numbers Inputs : First Number Second Number Third Number Operations : Average = (first + second + third ) / 3 Output : The Average Computer Programming -1
Problem Analysis 7 Write a program to print the volume of a cube and the sum of it’s surfaces’ areas Inputs : 1. Side Length Operations : � � Volume = side * side Surface area = ( side * side ) * 6 Output : 1. 2. The Volume The surface area Computer Programming -1
Solving Problems Stages 8 Problem Definition Algorithm Problem Analysis Solution Design a solution for the problem by writing an algorithm or drawing a flow chart Flow Chart Computer Programming -1
Basic steps for designing a solution 9 Read all the inputs Calculate operations Print the output Computer Programming -1
Algorithms 10 Write a Program to Print the Sum of two integer Numbers 1. 2. 3. 4. 5. 6. Start the program Read the first number and save in the variable ( N 1 ) Read the second number and save in the variable ( N 2 ) Sum the both numbers and save the result in the variable ( Sum ) Sum = N 1 + N 2 Print the variable ( Sum ) End the program Computer Programming -1
Algorithms 11 Write a program to Print the Average of three integer numbers 1. 2. 3. 4. 5. 6. 7. Start the program Read the first number and save in the variable ( num 1 ) Read the second number and save in the variable ( num 2 ) Read the third number and save in the variable ( num 3 ) Sum the three numbers and save the result in the variable ( result ) result = num 1 + num 2 + num 3 Divide the variable ( result ) by 3 and save the result in variable ( Average ) Average = result / 3 Computer Programming -1 Print the variable ( Average )
Algorithms 12 Write a program to print the volume of a cube and the sum of it’s surfaces’ areas Start the program 2. Read the length of the side and save in variable ( Length ) 3. Volume = Length * Length 4. Surface = ( Length * Length ) * 6 5. Print the variable ( Volume ) 6. Print the variable ( Surface ) 7. End the program 1. Computer Programming -1
13 Flow Chart Computer Programming -1
Flow chart’s Symbols End Print n 1 Start/End Read n 1 Read/Print N 2 = n 1+3 n 1 > 3 N 2 = 5 Arithmetic Operations Decision Loops Connectors arrows Connectors points 14 Java Programming: From Problem Analysis to Program Design, Third Edition // my name Comments
15 Simple Sequential Flow Charts start End Computer Programming -1
Write a Program to Print the Sum of two integer Numbers 16 start 1. 2. 3. 4. 5. 6. Start the program Read the first number and save in the variable ( N 1 ) Read the second number and save in the variable ( N 2 ) Sum the both numbers and save the result in the variable ( Sum ) Sum = N 1 + N 2 Print the variable ( Sum ) End the program Read N 1 Read N 2 Sum = N 1 + N 2 Print Sum End Computer Programming -1 16
17 Write a program to print the volume of a cube and the sum of it’s surfaces’ areas start Start the program 2. Read the length of the side and save in variable ( Length ) 3. Volume = Length * Length 4. Surface = ( Length * Length ) * 6 5. Print the variable ( Volume ) 6. Print the variable ( Surface ) 7. End the program 1. Read L Volume = L * L Surface = ( L * L ) * 6 Print Volume Print Surface End Computer Programming -1 17
Write a program to Print the Average of three integer numbers start 18 Read num 1 start Read num 2 Read num 1, num 2, num 3 Read num 3 result = num 1+num 2+num 3 Average = result/3 Print Average End Computer Programming -1 18
Write a program to Print the Average of three integer numbers 19 start Read num 1, num 2, num 3 Average = ( num 1+num 2+num 3 ) / 3 Print Average End Computer Programming -1 19
Write a program to Print the Average of three integer numbers 20 start Read num 3 result = num 1+num 2+num 3 Read num 1 Read num 2 result = num 1+num 2+num 3 Read num 3 Average = result/3 Print Average End Computer Programming -1 20
Write a program to Print the Average of three integer numbers 21 start Read num 1, num 2, num 3 result = num 1+num 2+num 3 Average = result/3 result = num 1+num 2+num 3 Print. Average result End Print result End Computer Programming -1 21
Summery 22 A problem-solving process for programming has five steps: analyze the problem, design an algorithm, implement the algorithm in a programming language, verify that the algorithm works, and maintain the program. An algorithm is a step-by-step problem-solving process in which a solution is arrived at in a finite amount of time. A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows. Computer Programming -1
- Slides: 22