Download week-2-lec1ch1problemsolving

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Algorithm wikipedia , lookup

Simplex algorithm wikipedia , lookup

Theoretical computer science wikipedia , lookup

Transcript
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
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

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 * 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
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 ( 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
Algorithms
11
Write a program to Print the Average of three
integer numbers
1.
2.
3.
4.
5.
6.
7.
8.
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 )
Computer Programming -1
End the program
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 * 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 n1
Start
Start/End
Read n1
Read/Print
N2 = n1+3
n1 > 3
N2 = 5
Arithmetic Operations
Decision
Loops
Connectors arrows
Connectors points
14
Java Programming: From Problem Analysis to Program Design, Third
Edition
// my name
Comments
Simple Sequential Flow Charts
15
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 ( 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
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 * 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 * 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 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
18
Write a program to Print the Average of three
integer numbers
19
start
Read num1,num2,num3
Average = ( num1+num2+num3 ) / 3
Print Average
End
Computer Programming -1
19
Write a program to Print the Average of three integer
numbers
20
start
start
Read num3
result = num1+num2+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
20
Write a program to Print the Average of three integer
numbers
21
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
PrintAverage
result
Print result
End
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