Top Banner
CSC 111
23

CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Jan 18, 2016

Download

Documents

Erika McDaniel
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

CSC 111

Page 2: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Solving Problems with Computers

Page 3: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 3

Solving Problems Stages

1. Problem Definition Define the main Problem

Page 4: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 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

Page 5: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 5

Solving Problems Stages

1. Problem Definition Define the main Problem

2. Problem Analysis Determine the inputs, outputs,

Arithmetic & logic operations

Page 6: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 6

Problem Analysis Write a Program to Print the Sum of two integer

NumbersInputs :

1. First Number2. Second Number

Operations : Summation = first + second

Output :1. The summation

Page 7: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 7

Problem Analysis Write a program to Print the Average of three

integer numbers

Inputs :1. First Number

2. Second Number

3. Third Number

Operations : Average = (first + second + third ) / 3

Output :1. The Average

Page 8: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 8

Problem Analysis 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. The Volume

2. The surface area

Page 9: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 9

Solving Problems Stages

Problem Definition

Problem Analysis

Solution DesignDesign a solution for the problem by writing an algorithm or drawing a flow chart

Algorithm

Flow Chart

Page 10: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 10

Basic steps for designing a solution

Read all the inputs

Calculate operations

Print the output

Page 11: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 11

Algorithms Write a Program to Print the Sum of two integer Numbers

1. Start the program2. Read the first number and save in the variable ( N1 )3. Read the second number and save in the variable ( N2 )4. Sum the both numbers and save the result in the variable

( Sum ) Sum = N1 + N2 5. Print the variable ( Sum ) 6. End the program

Page 12: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 12

Algorithms Write a program to Print the Average of three integer

numbers

1. Start the program2. Read the first number and save in the variable ( num1 )3. Read the second number and save in the variable ( num2 )4. Read the third number and save in the variable ( num3 )5. Sum the three numbers and save the result in the variable

( result ) result = num1 + num2 + num3

Page 13: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 13

Algorithms Write a program to Print the Average of three

integer numbers

6. Divide the variable ( result ) by 3 and save the result in variable ( Average ) Average = result / 3

7. Print the variable ( Average )8. End the program

Page 14: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 14

Algorithms Write a program to print the volume of a cube and

the sum of it’s surfaces’ areas

1. Start the program2. Read the length of the side and save in variable ( Length )3. Volume = Length * Length * Length4. Surface = ( Length * Length ) * 65. Print the variable ( Volume ) 6. Print the variable ( Surface )7. End the program

Page 15: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 15

Flow Chart

Page 16: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 16

Loops

Start/End

Read/Print

Arithmetic Operations

Decision

Connectors arrows

Connectors points

Comments

Flow chart’s Symbols

Start

Read n1

N2 = 5

End

Print n1

N2 = n1+3

n1 > 3

//my name

Page 17: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Simple Sequential Flow Charts

start

End

Page 18: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 18

Write a Program to Print the Sum of two integer Numbers

1. Start the program2. Read the first number and save in

the variable ( N1 )3. Read the second number and save in

the variable ( N2 )4. Sum the both numbers and save the

result in the variable ( Sum ) Sum = N1 + N2

5. Print the variable ( Sum ) 6. End the program

start

Read N1

Read N2

Sum = N1 + N2

Print Sum

End

Page 19: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 19

Write a program to print the volume of a cube and the sum of it’s surfaces’ areas

1. Start the program2. Read the length of the side and save

in variable ( Length )3. Volume = Length * Length * Length4. Surface = ( Length * Length ) * 65. Print the variable ( Volume ) 6. Print the variable ( Surface )7. End the program

start

Read L

�ٍSurface = ( L * L ) * 6

Print Volume

End

Volume = L * L * L

Print Surface

Page 20: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 20

Write a program to Print the Average of three integer numbers

start

Read num1

Read num2

result = num1+num2+num3

Print Average

End

Read num3

Average = result/3

start

Read num1,num2,num3

result = num1+num2+num3

Print Average

End

Average = result/3

or

Page 21: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 21

Write a program to Print the Average of three integer numbers

start

Read num1,num2,num3

Average = ( num1+num2+num3 ) / 3

Print Average

End

or

Page 22: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 22

Write a program to Print the Average of three integer numbers

start

Read num1

Read num2

Print Average

End

Read num3

Average = result/3

result = num1+num2+num3

start

Read num3

Read num1

result = num1+num2+num3

Print Average

End

Read num2

Average = result/3

Page 23: CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.

Java Programming: From Problem Analysis to Program Design, Third Edition 23

Write a program to Print the Average of three integer numbers

start

Read num1,num2,num3

result = num1+num2+num3

Print result

End

Average = result/3

start

Read num1,num2,num3

Print result

End

Average = result/3

result = num1+num2+num3

Print Average