Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PROBLEM SOLVING AND PROGRAM DESIGN

Steps in Problem Solving


Step 1 Define the problem (Problem Definition)
Step 2 Outline the solution (IPO Chart)
Step 3 Develop the algorithm (Algorithm) / Flow Chart
Step 4 Test the algorithm (Trace Table)

7 Steps in Programming
Step 1 Define the problem (Problem Definition)
Step 2 Outline the solution (IPO Chart)
Step 3 Develop the algorithm (Algorithm) / Flow Chart
Step 4 Test the algorithm (Trace Table)
Step 5 Code the algorithm (Code program)
Step 6 Run the program (Run on Compiler or Interpreter)
Step 7 Document and maintain the program (add comments, make changes)

Applying Steps 1 to 7 to problem below


(Q1) Write program that asks for two numbers, finds and prints the sum of the
numbers.

Step 1 Define the problem (Problem Definition)


Write program that reads two numbers, finds the sum and prints the sum.

Step 2 Outline the solution (IPO Chart)

Highlight input and output nouns in Problem Definition (Inputs and Outputs):
Write program that reads two numbers, finds the sum and prints the sum.
Highlight verb statements in Problem Definition (Process):
Write program that reads two numbers, finds the sum and prints the sum.

1
IPO Chart
INPUT PROCESS OUTPUT
num1 Read num1 sum
num2 Read num2
Find sum
Print sum

Stepwise Refinement
INPUT PROCESS OUTPUT
num1 Prompt for num1 sum
Read num1
num2 Prompt for num2
Read num2
sum = num1 + num2
Print sum

Step 3 Develop the algorithm (Algorithm) / Flow Chart


ALGORITHM name
VARIABLES
variable As Integer
variable As Float / Real / Single / Double
variable As String
variable As Char
variable As Boolean / bool
BEGIN
Process steps

END

2
ALGORITHM FindSum
VARIABLES
num1, num2, sum As Integer
BEGIN
Prompt for num1
Read num1
Prompt for num2
Read num2
sum = num1 + num2
Print sum
END

FLOW CHART

BEGIN

Prompt for num1

Read num1

Prompt for num2

Read num2

sum = num1 + num2

Print sum

END

3
Flow Chart Symbols

INPUT /
DECISION
OUTPUT
BEGIN

END PROCESS
CONNECTOR

FLOW

Step 4 Test the algorithm (Trace Table)


CODE num1 num2 sum
Prompt for num1 - - -
Read num1 5 - -
Prompt for num2 5 - -
Read num2 5 7 -
sum = num1 + num2 5 7 12
Print sum 5 7 12

4
Step 5 Code the algorithm (Code program)
using System;
class Program
{
static void Main() {
int num1, num2, sum;

Console.WriteLine("Please enter num 1 ");


num1 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Please enter num 2 ");


num2 = Convert.ToInt32(Console.ReadLine());

sum = num1 + num2;

Console.WriteLine("The sum is "+sum);


}
}
Step 6 Run the program (Run on Compiler or Interpreter)

5
Step 7 Document and maintain the program (add comments, make changes)
using System;
class Program
{
static void Main() {
int num1, num2, sum;
//User prompted below
Console.WriteLine("Please enter num 1 ");
num1 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Please enter num 2 ");


num2 = Convert.ToInt32(Console.ReadLine());

//sum calculated
sum = num1 + num2;

//answer printed
Console.WriteLine("The sum is "+sum);
}
}

You might also like