CAPE Computer Science Unit 1 Module 2 - Problem Solving With Computers January 7, 2022
CAPE Computer Science Unit 1 Module 2 - Problem Solving With Computers January 7, 2022
CAPE Computer Science Unit 1 Module 2 - Problem Solving With Computers January 7, 2022
1) Problem Definition.
(2) Problem Analysis.
(3) Generating possible Solutions.
(4) Analyzing the Solutions.
(5) Selecting and Justify Solutions.
1. Problem Definition The process for solving a problem will initially involve defining the
problem (1) you want to solve. You need to decide what you want to achieve and write it down.
The first part of the process not only involves writing down the problem to solve, but also
checking that you are answering the right problem (1). It is a check-step to ensure that you do not
answer a side issue or only solve the part of the problem that is most easy to solve. People use
the most immediate solution to the first problem definition that they find without spending time
checking the problem is the right one to answer (1).
2. Problem Analysis This step involves determining what are the inputs (1), what processing is
involved (1) and what are the outputs (1). The next step in this process is used to check where we
are and what is the current situation. Also determine how the data and information or results will
be stored temporarily or for future use.
Input and Storage instructions
The input and storage instructions allow information or dats to be accepted by the computer. The
input is information that is needed by the computer to solve the problem. Words such as “Enter”,
“Input” and “Read” within problem statements usually indicate what data the computer requires.
Example 1
What are the input and storage instructions here?
1. Read the price of an item and calculate the discount of 10%.
2. Enter the name and year of birth of a person and calculate the person’s age.
3. Input the length of a side of a square tile and find the area.
Processing Instructions
These instructions manipulate the input data. They involve calculations, that is, mathematical
operations (e.g. addition, subtraction, multiplication and division), repeating instructions,
selecting instructions and comparison instructions. They also include commands and constructs.
A command is a word that instructs the computer as to what must be done to accomplish a
specific task. Commands are specific to a particular language: for example, WRITE, PRINT,
READ, INPUT, etc.
A construct is a group of instructions that work together with commands to accomplish a
specific task. An example is the IF-ELSE construct:
Problem statements that contain the words ‘calculate’, ‘compute’, ‘convert’, ‘add’, ‘sum’,
‘subtract’, ‘minus’, ‘multiply’, ‘divide’, ‘percentage’, ‘average’, indicate what needs to be done.
Problem statements can also imply what needs to be processed by looking at what results are
required for output; for example: ‘Print the area of the room’.
Example 2
What are the processing instructions here?
1. Read the price of an item and calculate the new price after a 10% discount.
2. Enter the temperature in degrees Celsius and convert it to degrees Fahrenheit.
3. Input the name and year of birth and compute and print the age of a person.
Output Instructions
These instructions allow information to be displayed on the screen. Problem statements that
include key words like ‘print’, ‘output’, ‘display’, ‘return’ and ‘write’ indicate what data should
be output to the screen.
Example 3
What are the output statements here?
1. Enter the name and year of birth of a person and compute and display the age of the
person.
2. Write an algorithm to print a conversion table of degrees Celsius to degrees Fahrenheit,
10 0C to 20 0C inclusive.
Let’s analyze these instructions to determine what we need to output.
1. Display the age of the person
2. Print a conversion table
In order to analyze any given problem, we use a IPO table. This is the Input-Processing-Output
table.
Example 4
Write a program to enter the base and height of a triangle and find and print the area.
Input and Storage Processing Output
Base Calculate Area Area
Height Area = (Base*Height)/2
Example 5
Write a program to read the temperature in degrees Celsius(C) and convert it to degrees
Fahrenheit(F) where F = 32+(9C/5). Output the temperature in degrees Celsius and Fahrenheit.
Input and Storage Processing Output
C F = 32 +(9C/5) C, F
Example 6
Write a program to read the answer to the product of 10*20, return the comment “Correct” if the
answer is right and “Incorrect” if the answer is wrong.
Input and Storage Processing Output
Answer If Answer = 120 then “Correct”
Print “Correct” else Or
Print “Incorrect” “Incorrect”
Example 7
Write a program that reads the result of 10 games played by a team and find the percentage of
games won by the team. Output the percentage of games won.
Input and Processing Output
Storage
GameResult Repeat 10 times PercentageWins
PercentageWins = (TotalWins/10)x100
Example 8
A school has a house system implemented. Points are awarded to a house based on the
performance of its members. 1st place- 4 points, 2nd place – 3 points, 3rd place – 2 points, 4th place
1 point and last place – no points. Read the names of 10 members of the Aripo house and the
place they came in the events; calculate the total points awarded to the house.
3. Generating possible Solutions In this stage you concentrate on generating many solutions (1)
and not evaluate them at all (1). Very often an idea, which would have been discarded
immediately, when evaluated properly, can be developed into a superb solution. At this stage,
you should not pre-judge any potential solutions (1) but should treat each idea as a new idea in
its own right and worthy of consideration.
4. Analyzing the Solutions This section of the problem solving process is where you investigate
the various factors about each of the potential solutions (1). You note down the good and bad
points and other things which are relevant to each solution (1). Even at this stage you are not
evaluating the solution because if you do so then you could decide not to write down the valid
good points about it because overall you think it will not work. However you might discover that
by writing down its advantages that it has a totally unique advantage (1).
5. Selecting and Justify Solutions This is the section where you look through the various
influencing factors (1) for each possible and decide which solutions to keep (1) and which to
disregard (1). You look at the solution as a whole and use your judgement as to whether to use
the solution or not. Sometimes pure facts and figures dictate which ideas will work and which
will not.
Algorithm
An algorithm is a set of clearly defined, unambiguous finite steps used to solve a problem. An
algorithm is written using special rules and statements.
Characteristics of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the following
characteristics −
Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one meaning.
Input − An algorithm should have 0 or more well-defined inputs.
Output − An algorithm should have 1 or more well-defined outputs, and should match
the desired output.
Finiteness − Algorithms must terminate after a finite number of steps.
Feasibility − Should be feasible with the available resources.
Independent − An algorithm should have step-by-step directions, which should be
independent of any programming code.
There are no well-defined standards for writing algorithms. Rather, it is problem and resource
dependent. Algorithms are never written to support a particular programming code.
As we know that all programming languages share basic code constructs like loops (do, for,
while), flow-control (if-else), etc. These common constructs can be used to write an algorithm.
We write algorithms in a step-by-step manner, but it is not always the case. Algorithm writing is
a process and is executed after the problem domain is well-defined. That is, we should know the
problem domain, for which we are designing a solution.
Example
Flowchart
A flowchart is a diagrammatic representation of an algorithm. It uses the following symbols to
show the processes of a program.
Write an algorithm and flowchart for the following:
1. Write an algorithm to calculate the simple interest using the formula.
2. Area of Triangle: Write an algorithm to find the area of the triangle.
3. Write an algorithm to find the largest of three numbers X, Y and Z.
4. Write down an algorithm to find the largest data value of a set of given data values.
5. Write an algorithm which will test whether a given integer value is prime or not.