Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic problem solving CSC 111.

Similar presentations


Presentation on theme: "Basic problem solving CSC 111."— Presentation transcript:

1 Basic problem solving CSC 111

2 Learning Objectives In this lecture we will learn
Basic steps for designing computer program Algorithm Flow Chart Computer Programming -1

3 Solving Problems Stages
Problem Definition Define the main Problem Problem Analysis Determine the inputs, outputs, Arithmetic & logic operations Design Solution Identify the required step for computer to do Computer Programming -1

4 Problem Definition 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

5 Problem Analysis Write a Program to Print the Sum of two integer Numbers Inputs : First Number Second Number Operations : Summation = first + second Output : The summation Computer Programming -1

6 Problem Analysis 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

7 Problem Analysis Write a program to print the volume of a cube and the sum of it’s surfaces’ areas Inputs : Side Length Operations : Volume = side * side * side Surface area = ( side * side ) * 6 Output : The Volume The surface area Computer Programming -1

8 Solving Problems Stages
Problem Definition Algorithm Problem Analysis Solution Design Design a solution for the problem by writing an algorithm or drawing a flow chart Flow Chart Computer Programming -1

9 Basic steps for designing a solution
Read all the inputs Calculate operations Print the output Computer Programming -1

10 Algorithms Write a Program to Print the Sum of two integer Numbers
Start the program Read the first number and save in the variable ( N1 ) Read the second number and save in the variable ( N2 ) Sum the both numbers and save the result in the variable ( Sum )  Sum = N1 + N2 Print the variable ( Sum ) End the program Computer Programming -1

11 Algorithms Write a program to Print the Average of three integer numbers Start the program Read the first number and save in the variable ( num1 ) Read the second number and save in the variable ( num2 ) Read the third number and save in the variable ( num3 ) Sum the three numbers and save the result in the variable ( result )  result = num1 + num2 + num3 Divide the variable ( result ) by 3 and save the result in variable ( Average )  Average = result / 3 Print the variable ( Average ) End the program Computer Programming -1

12 Algorithms Write a program to print the volume of a cube and the sum of it’s surfaces’ areas Start the program Read the length of the side and save in variable ( Length ) Volume = Length * Length * Length Surface = ( Length * Length ) * 6 Print the variable ( Volume ) Print the variable ( Surface ) End the program Computer Programming -1

13 Flow Chart Computer Programming -1

14 Flow chart’s Symbols Start/End End Start Read/Print Print n1 Read n1
Arithmetic Operations N2 = n1+3 N2 = 5 Decision n1 > 3 Loops Connectors arrows Connectors points Comments Java Programming: From Problem Analysis to Program Design, Third Edition // my name

15 Simple Sequential Flow Charts
start End Computer Programming -1

16 Write a Program to Print the Sum of two integer Numbers
start Start the program Read the first number and save in the variable ( N1 ) Read the second number and save in the variable ( N2 ) Sum the both numbers and save the result in the variable ( Sum )  Sum = N1 + N2 Print the variable ( Sum ) End the program Read N1 Read N2 Sum = N1 + N2 Print Sum End Computer Programming -1

17 Computer Programming -1
Write a program to print the volume of a cube and the sum of it’s surfaces’ areas start Start the program Read the length of the side and save in variable ( Length ) Volume = Length * Length * Length Surface = ( Length * Length ) * 6 Print the variable ( Volume ) Print the variable ( Surface ) End the program Read L Volume = L * L * L ٍSurface = ( L * L ) * 6 Print Volume Print Surface End Computer Programming -1

18 Write a program to Print the Average of three integer numbers
start Read num1 start Read num2 Read num1,num2,num3 Read num3 result = num1+num2+num3 result = num1+num2+num3 Average = result/3 Average = result/3 Print Average Print Average End End Computer Programming -1

19 Write a program to Print the Average of three integer numbers
start Read num1,num2,num3 Average = ( num1+num2+num3 ) / 3 Print Average End Computer Programming -1

20 Write a program to Print the Average of three integer numbers
start start result = num1+num2+num3 Read num3 Read num1 Read num1 Read num2 Read num2 result = num1+num2+num3 Read num3 Average = result/3 Average = result/3 Print Average Print Average End End Computer Programming -1

21 Write a program to Print the Average of three integer numbers
start start Read num1, num2,num3 Read num1, num2,num3 result = num1+num2+num3 Average = result/3 Average = result/3 result = num1+num2+num3 Print result Print Average Print result End End Computer Programming -1

22 Summery 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


Download ppt "Basic problem solving CSC 111."

Similar presentations


Ads by Google