Problem Solving and Program Design 1
Problem Solving and Program Design 1
program design
Introduction to Computer Science and Programming
Programming = problem solving + implementation
• A typical programming task can be divided into two phases:
• Problem solving phase
- produce an ordered sequence of steps that describe solution of
problem.
- this sequence of steps is called an algorithm
• Implementation phase
-implement the program in some programming language
Software development method
1)Specify the problem requirements.
2)Analyze the problem.
3)Design the algorithm to solve the problem.
4)Implement the algorithm.
5)Test and verify the completed program.
6)Maintain and update the program.
Specify the problem requirements
State the problem clearly and unambiguously
●
The objective is to eliminate unimportant aspects and zero in on the root problem.
●
Specifications can include the
following:
- Does the problem require interaction with the user?
- Does the problem manipulate data?
What is the input data & how it is represented?
- Does the problem produce output? How the
results should be generated and formatted.
- What are the required formula for solution
- Is there any constraints on problem solution?
Analyse the problem
Analysing the problem involves identifying the problem:
●
Problem Statement:
Determine the total cost of apples given the number of kilos of apples
purchased and the cost per kilo of apples.
• Coding:
• - After verifying that the algorithm is correct,
• you can code it in any high-level programming
• language(C in our case)
• - The algorithm is now converted into a program
Test and verify the program
Pseudocode:
Write an algorithm and draw a flowchart that will read the two sides of a
rectangle and calculate its area.
Pseudocode
•Input the width (W) and Length (L) of a rectangle
•Calculate the area (A) by multiplying L with W
•Print A
Example 3
Example 4
•Write an algorithm and draw a flowchart that will calculate the roots of a
quadratic equation
●
You have just been hired by the city council to mark distances between major cities in Zimbabwe.
Unfortunately the current distances are measured in miles and some give distances in kilometres
You and your co-workers prefer to deal in metric measurements(Kilometres). Write a program that
performs the necessary conversion.