chapter 2 problem solving l.
Skip this Video
Loading SlideShow in 5 Seconds..
Chapter 2: Problem Solving PowerPoint Presentation
Download Presentation
Chapter 2: Problem Solving

Loading in 2 Seconds...

play fullscreen
1 / 26

Chapter 2: Problem Solving - PowerPoint PPT Presentation

  • Uploaded on

Chapter 2: Problem Solving. Software development method specification of needs problem analysis design and algorithmic representation implementation testing and verification documentation. Introduction to Problem Solving.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Chapter 2: Problem Solving' - christmas

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter 2 problem solving
Chapter 2: Problem Solving
  • Software development method
    • specification of needs
    • problem analysis
    • design and algorithmic representation
    • implementation
    • testing and verification
    • documentation
introduction to problem solving
Introduction to Problem Solving
  • Problem solving is a process of transforming the description of a problem into the solution of that problem by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies, techniques and tools.
  • Computers can be used to help us in doing problem solving.
specification of needs
Specification of Needs
  • To understand exactly:
    • what the problem is
    • what is needed to solve it
    • what the solution should provide
    • if there are constraints and special conditions.
problem analysis
Problem Analysis
  • In the analysis phase, we should identify the following:
    • Inputs to the problem, their form and the input media to be used
    • Outputs expected from the problem, their form and the output media to be used
    • Special constraints (if any)
    • Formulas or equations to be used
design and algorithmic representation
Design and Algorithmic Representation
  • An algorithm is a sequence of a finite number of steps arranged in a specific logical order which, when executed, produces the solution for a problem.
  • An algorithm must satisfy these requirements:
    • It must have an input
    • It must have an output
    • It should not be ambiguous (there should not be different interpretations to it)
It must be general (it can be used for different inputs)
    • It must be correct and it must solve the problem for which it is designed
    • It must execute and terminate in a finite amount of time
    • It must be efficient enough so that it can solve the intended problem using the resource currently available on the computer
  • An algorithm can be represented using pseudocodes or flowcharts.
  • A pseudocode is a semiformal, English-like language with limited vocabulary that can be used to design and describe algorithms.
  • Criteria of a good pseudocode:
    • Easy to understand, precise and clear
    • Gives the correct solution in all cases
    • Eventually ends
  • In 1966, two researchers, C. Bohn and G. Jacopini, demonstrated that any algorithm can be described using only 3 control structures: sequence, selection and repetition.
The sequence control structure
    • A series of steps or statements that are executed in the order they are written in an algorithm.
    • The beginning and end of a block of statements can be optionally marked with the keywords begin and end.
    • Example:


read birthDate

age = today’s date - birth date

print age


  • The selection control structure
    • Defines two courses of action depending on the outcome of a condition. A condition is an expression that is either true or false.
The keyword used are if and else.
    • Example:

if age > 55

print “sudah pencen”


print “kerja lagi”


  • The repetition control structure
    • Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied.
    • The keyword used is while.

while user still wants to play


Select either to play on network or play against computer

if play on network

create connection to remote machine

play game with connected computer


select mission

play game locally


Ask user whether he/she still wants to play



  • Flowcharts is a graph used to depict or show a step by step solution using symbols which represent a task.
  • The symbols used consist of geometrical shapes that are connected by flow lines.

Terminal symbol - indicates the beginning and

end points of an algorithm.

Process symbol - shows an instruction other than

input, output or selection.

Input-output symbol - shows an input or an output


Disk storage I/O symbol - indicates input from or

output to disk storage.

Printer output symbol - shows hardcopy printer



Selection symbol - shows a selection process

for two-way selection.

Off-page connector - provides continuation

of a logical path on another page.

On-page connector - provides continuation

of logical path at another point in the same


Flow lines - indicate the logical sequence of

execution steps in the algorithm.





Play on network?

Create connection

Select mission

Play game


Play game



Play again?



  • The process of implementing an algorithm by writing a computer program using a programming language (for example, using C language)
  • The output of the program must be the solution of the intended problem
testing and verification
Testing and Verification
  • Program testing is the process of executing a program to demonstrate its correctness
  • Program verification is the process of ensuring that a program meets user-requirement
  • After the program is compiled, we must run the program and test/verify it with different inputs before the program can be released to the public or other users (or to the instructor of this class)
  • Contains details produced at all stages of the program development cycle.
  • Can be done in 2 ways:
    • Writing comments between your line of codes
    • Creating a separate text file to explain the program
  • Important not only for other people to use or modify your program, but also for you to understand your own program after a long time (believe me, you will forget the details of your own program after sometime)
Although documentation is listed as the last stage of software development method, it is actually an on-going process which should be done from the very beginning of the software development process.
a very simple example
A Very Simple Example


You are required to develop a complete system which will enable the sum of two values to be calculated.

What do we have to do first?

calculating electricity bills
Calculating Electricity Bills

The unit for electricity usage is kWh. For domestic usage, the tariff used is tariff A. The monthly rate for tariff A is 21.8 cents/unit for the first 200 unit, 25.8 cents/unit for the next 800 units and 27.8 cents/unit for each additional units. Given the amount of electricity units (in kWh) used by a customer, compute and print the amount of money needs to be paid by the customer to TNB.

calculating electricity bills21
Calculating Electricity Bills


Print “Enter the usage (unit): ”

Read usage

if (usage > 200)

payment = 200 x 21.8

usage = usage – 200

if (usage > 800)

payment = payment + (800 x 25.8)

usage = usage - 800

payment = payment + (usage x 27.8)


payment = payment + (usage x 25.8)



payment = usage x 21.8


Print “Total payment is “, payment


calculating uniten tuition fee
Calculating Uniten Tuition Fee

This program will calculate the total tuition fee for a UNITEN student. The program ask for total number of subject registered. Then it will ask for the number of credit hours for each subject. The program will print out the total tuition fee in RM. Assume that tuition fee is RM300 per credit hour

calculating uniten tuition fee23
Calculating Uniten Tuition Fee

Print “Enter total number of subject: “

Read totalSubject

counter = 0

totalFee = 0

while (counter < totalSubject)

Print “Enter the number of credit of the subject: “

Read credit

totalFee = totalFee + (credit x 300)

counter = counter + 1


Print “The total fee is “, totalfee


1. Write pseudocode of a program that calculate the total sum of series starting from 1 to a number specified by user. Example, if user input 4, the result is 1+2+3+4=10.

2. Write pseudocode of a program that will print the net income of a salesman in ABC Bhd given the total sales of a month. The basic salary is RM500. The commission is 5% of the first RM50,000.00 sales, 10% for next RM200,000.00 sales and 20% for the remaining. A sum of 11% of the gross income will be deducted for KWSP contribution.




Print “Enter last number in the series: “

Read lastNumber

counter = 1

sum = 0

while (counter<=lastNumber) do

sum = sum + counter

counter = counter + 1


Print “The sum of the series is “, sum





Print “Enter monthly sales: “

Read sales

income = 500

if (sales>50000)

income = income + (0.05 x 50000)

sales = sales - 50000

if (sales>200000)

income = income + (0.1 x 200000)

sales = sales - 200000

income = income + (0.2 x sales)


income = income + (0.1 x sales)



income = income + (0.05 x sales)


income = income – (income x 0.11)

Print “The net income is “, income