SlideShare une entreprise Scribd logo
1  sur  21
1 | P a g e
FEDERAL UNIVERSITY, NDUFU-ALIKE IKWO
(FUNAI)
FACULTY OF SCIENCE
DEPARTMENT OF MATHEMATICS/COMPUTER
SCIENCE/STATISTICS/INFORMATICS
CSC 102: INTRODUCTION TO PROBLEM
SOLVING
(LECTURE NOTE)
PROGRAM TEAM MEMBERS
Chizoba C. Nnamene (Course Coordinator)
Ikenna Ezea
2 | P a g e
COURSE DESCRIPTION
This course is designed to equip the student with the skills needed to solve problem in a broad
range of fields. It lays more emphases on the appropriate problem solving skills a computer
scientist or a programmer may need for the execution of variable range of tasks.
After the completion of this course, the student is expected to know the following problems solving
concepts:
 Problem solving strategies
 Role of algorithm in problem solving process
 Implementation strategies
 Concepts of algorithm
 Properties of algorithm
Prerequisite: A background in CSC 101: Introduction to computer science or any other related
course(s) is essential.
The course description at a glance
Course content Section
Problem solving strategies See section 1.1
Concepts of algorithm See section 1.2
Properties of algorithm See section 1.2.2
Role of algorithm in problem solving process See section 1.2.3
Implementation strategies See section 2.1
3 | P a g e
CONTENTS
1.0 Introduction 4
1.1. General Problem Solving Strategies 4
1.2. Concepts of Algorithm 5
1.2.1. Major Components of Algorithm 6
1.2.2. Properties of Algorithm 6
1.2.3. Role of Algorithm in Problem Solving 7
1.2.4. Ways of expressing Algorithm 7
1.2.5. Algorithm Development Methodologies 8
1.2.5.1. Top-Down Design 8
1.2.5.2. Object Oriented Design 9
2.1 Implementations strategies 9
2.1.1. Specify the problem requirements (Requirement Specification). 10
2.1.2. Analyze the problem (Analysis) 10
2.1.3. Design the algorithm to solve the problem (Design). 11
2.1.4. Implement the algorithm (Implementation). 11
2.1.5. Test and verify the completed program (Testing). 11
2.1.6. Maintain and update the program (Maintenance). 11
2.2. Applications of Software Development Methods in Problem Solving 12
CASE STUDY I: Temperature conversion 12
USE CASE II: Volume calculation 16
Summary 19
Exercises 20
References 21
4 | P a g e
1.0. Introduction
Problem solving is a compound word that is composed of two words, “Problem” and
“Solving”. For us to give a definition we need to take the words into context. Depending
on the context, problem has been defined in a number of ways. The dictionary definition
holds that problem is a question raised for inquiry, consideration or solution, in
mathematics problem has been defined as a situation that is to be resolved using well-
defined mathematical principles. Solving on the other hand can be defined as a means of
finding solution to a problem.
Based on the above definitions we can formally define problem solving as the act of
finding a solution to perplexing, distressing, vexing or unsettled question. Though the
definition of problems cited in the first paragraph suits this definition, some of them are
not suitable in the context of computing. This is because computers are limited in its
problem solving capabilities. Computers cannot be used in solving problems involving
physical activities or emotions. Such as resolving marital problems, providing solutions to
the age long problems between Catholics and Protestants, squeezing passengers in an
overloaded bus, or the religious conflict between Muslims and Christians in Nigeria. A
computer can be considered as an unintelligent device in that it cannot act unless when
instructed to do so. It cannot analyze and proffer a solution to a problem without the
programmer performing the analysis and providing the instructions in form of a program,
which is fed into the computer in other to carry out the designated task.
However, once a problem has been analyzed and instruction translated into program the
computer has the ability to carry out the processing in a very fast, repeated and consistent
manner for different data entry and variable situations. Computer helps people in the
computation of repeated and boring tasks, thereby saving time and effort required to carry
out the tasks. Computers can be used for registration of courses, administering of
examinations and marking of scripts, financial management and budgeting, etc.
1.1. General Problem Solving Strategies
To solve a problem one has to understand the problem domain and the situation to avoid
mistakes or incorrect assumptions. To be a better problem solver we need to have a good
understanding of the general problem-solving framework. One of the frameworks is the
one outlined by Polya in his book “How to solve it”. This problem solving approach even
though was written for mathematical problem solving it has been widely adopted in
computing and many other problem solving domains. The four Polya’s problem solving
strategies are:
1. Understanding the problem: Carefully read the problem to understand what needs to
be accomplished. Assess your background skills in the area under consideration to
know if you have to acquire more skills in other to solve the problem. Visualize the
final-result and use it as a guide in determining the validity of your solution and the
result that will be obtained. Identify the known and the unknown (variables). Check the
data and the conditions that needs to be satisfied. Check to know if the condition is
5 | P a g e
sufficient to determine the unknown. Split the problem into parts and write down the
parts.
2. Device a plan: Check to see if there is a link between the data and the unknown
(variable), if there is no link then try using auxiliary problem. Check if a similar
problem exists so you can adapt the solution instead of reinventing the wheel. After all,
the outcome of this phase is the plan of the solution.
3. Carrying out the plan: In carrying out the plan, you have to go through the steps to
know if they are correct, ascertain if there is any missing link. Check if the correctness
of the plan can be proved. If the plan does not work correctly, discard it and try another
plan.
4. Looking Back: This is the moment of reflection. This is the phase that you can
crosscheck what you have done to arrive at the present stage. In this phase, you can
ascertain what worked and what did not work. This is the time your argument and
results are verified for correctness and consistency. In this phase, you can check if the
solution can be applied in other problems. At this point, you can also ascertain if you
can still get the same result using different methods.
1.2. Concepts of Algorithm
Problem solving as we have seen involves the abstraction and decomposition of large
amount of problem into smaller manageable subtasks that can be handled independently.
An algorithm is important in the planning and execution of a problem solution since it
specifies the sequence of steps needed to carry out the instructions that will lead to the
overall result. An algorithm can be defined as a sequential set of instructions that are
followed in other to solve a problem using a finite amount of data in a finite amount of
time. More than one algorithm can be written for a particular problem (see figure 1.0) but
the choice of selecting a particular algorithm in place of the other is dependent on the
following factors: reliability, accuracy, ease of modification and time required for the
execution when converted to a high-level language.
Figure 1.0: Relationship between Problem, Algorithms and Programs
6 | P a g e
1.2.1. Major Components of Algorithm
Most of the algorithms used in solving program related problems consist of three major
sections: the input, processing and output. That is the summary of most if not all the
activities undertaken by most algorithm in other to produce a result. To execute a task
the algorithm requires some data (i.e. input), it performs some computation on the data
(i.e. processing) then it produces result (i.e. output). The processing comprises of any
or all of the following: computation, selection, iteration, etc. Figure 1.1. Shows the
three major sections of an algorithm.
Figure 1.1: The three major sections of an Algorithm
Input: This represent the data that is to be sent for processing in the system. Most
algorithms provides some variables and the description of the data that the variable will
handle.
Processing: This is the action performed on data in other to produce the desired result.
Such actions like computation, selection, iteration, etc.
Output: This is the result produced after the data has been processed. When the algorithm
has been converted to programs, the data is usually displayed through the output device,
for example the monitor.
1.2.2. Properties of Algorithm
a. Finiteness: An algorithm should be able to terminate after a finite number of
instructions must have been processed. That means it does not have to take forever to
process a set of instructions.
b. Definiteness: The algorithm should be developed in a form that each step will be
precise and easy to understand.
c. Effectiveness: This means that the algorithm should be in a form that will be easy to
convert to a programming statement in a finite amount of time.
d. Generality: The algorithm should be able to produce the same output when given
different type of valid data (i.e. data taking from a specified domain).
e. Input/output: The algorithm should be able to produce output value(s) when given a
set of specified input value(s). There should be a relationship between the input and the
output produced by the algorithm.
7 | P a g e
1.2.3. Role of Algorithm in Problem Solving
a. Algorithm helps in the evaluation of a problem to know if it can be solved using a
computer. Once an algorithm can be written for a problem then the problem can be
solved using computational means.
b. Algorithm helps in the identification of the various steps, major decision points and the
variables needed to solve a problem. This are the concepts that are needed for the
development of a computer program.
c. Algorithm helps in the decomposition of a large task into small manageable subtasks.
The decomposition helps in reducing the complexity of the problem and make it
solvable.
d. The atomic nature of the tasks/subtasks of the algorithm makes the decision making
process more rational in nature, since the subtasks are supported by facts.
e. Given different tasks, one algorithm can be applied in performing all the tasks. This
enhances the consistency and reliability of the problem solving process.
1.2.4. Ways of expressing Algorithm
The expression of algorithm can come in three major ways. They are:
 Natural Language: This is a method of expressing algorithm using our day-to-day
language, like English or other languages. This has been found to be
disadvantageous as it is very wordy and confusing.
Example 1.1: Write an algorithm in natural language to calculate the area of a
triangle (area = ½ * base * height)
Solution
Step 1: Start
Step 2: Select from the triangle the values for base and height
Step 3: Calculate the product of the values (i.e. base and height)
Step 4: Divide the product of base and height by 2
Step 5: The area is the result gotten after dividing base and height
by 2
Step 6: Stop
 Pseudo Code: This type of expression has a form that is closely related to a
programming language though there is no restriction on the syntax. It is not
ambiguous like the natural language.
Example 1.2: Write a pseudo code to calculate the area of a triangle
Solution:
Step 1: Start
Step 2: Read base and height
Step 3: Product = base x height
Step 4: Area = product/2
Step 5: Print Area
Step 6: Stop
8 | P a g e
 Flow chart: Uses symbols to represent the sequence of instructions. It is not
ambiguous like the natural language, but the modification is done using a
specialized tool. In addition, the implementation uses a standard rules.
Example 1.1: Draw a flowchart to calculate the area of a triangle (area = ½ * base
* height)
Solution:
1.2.5. Algorithm Development Methodologies
Algorithm development can be approached using the following methodologies: Top-
Down Design (functional decomposition) and Object Oriented Design. We will
proceed with the explanation of top-down design in the next section, after that we will
explain Object Oriented Design.
1.2.5.1. Top-Down Design
The most common problem solving approach that is used among humans is divide and
conquer, which means dividing a large problem into smaller parts that can be solved
independently. This is the concept used in Top-Down Design. Top-down design,
which is also called functional decomposition, is a problem solving methodology that
involves splitting a large problem into smaller manageable parts that can be solved
independently and integrated to form the overall solution. The problems in a top-down
design are arranged in a hierarchical tree structure (structured chart), consisting of
problems or sub problems called modules. A module is a self-contained set of steps
needed for the solution of a problem. The modules are arranged in a hierarchy from top
to the bottom in a structure chart. The module at the top is the main problem while the
once at the bottom is a sub division of the problem. The modules are numbered
according to their position in the hierarchy; those in the same level are given the same
number. The numbering starts from top, which is usually zero, down to the bottom,
which can be any finite number, depending on the problem.
The reason for the division of the problems into modules, parts, or segments is to reduce
the complexity of the problem by sub dividing them into smaller manageable
independent parts. In the context of computer science, the responsibility of the module
9 | P a g e
depends on the requirement of the problem. Some of the module(s) could be
responsible for data input, some may perform processing of data, this may involve;
mathematical, logical or relational operation, while some may be responsible for the
output.
As an example, let us refer to figure 2.1. The figure is a hierarchical tree structure
(structured chart) that consist of three levels (level 0, 1, 2, and 3) the top level or level
0 describes the function of the overall problem. It is the abstract step because the
problems at this level can further be decomposed into smaller sub problems in the levels
that follows. The last module at the bottom (i.e. the module at level 3), that cannot be
decomposed any further is called the concrete step. Refer to case study II to see a
detailed example of dot-down design methodology.
Figure 2.1: An illustration of top-down design using a structured chart
1.2.5.2. Object Oriented Design
2.1 Implementations strategies
In section 1.1, we introduced general problem solving strategies using Polya’s approach.
In this section, we are going to limit our conversation to computer-based problem solving
strategy. Problem solving is an activity undertaken in every programming or software
development environment, so it is an indispensable knowledge needed by every
programmer or software developer. Problem solving is not just limited to computer
scientists, or programmers, it is also used by business students, engineers and scientists
though in a different way. In business studies, students use systems approach, while in
engineering and science, the engineers and scientists use engineering and scientific method
respectively, the programmers on the other hand use software development approach, and
10 | P a g e
that is going to be our topic of discussion in this section. The software development
methods are as follows:
2.1.1.Specify the problem requirements (Requirement Specification).
This involves a critical examination of the posed problem so, as to get a better
understanding of the requirement needed to solve the problem. The problem is restated and
every unimportant aspects are eliminated at this point. This is to help in presenting the
problem in a clear and unambiguous form.
2.1.2.Analyze the problem (Analysis)
The identification of the input variables (i.e. the data) needed for the implementation of the
problem is done at this point. The expected output (i.e. the result) that is to be obtained
after the execution of the input data and the formats (example a table with heading, rows
and columns) of presenting the result are also identified. The use of formulas or other
methods as a means of expressing the relationship that exists with the variables in the
problem is strongly encouraged. It is important to note that if the first step and this second
step is not carried out properly, it will lead to error or failure in the solution. See example
2.1 for explanation of this phase.
Example 2.1:
Given the three sides and height of a triangle, calculate in centimeter the area and perimeter
of the triangle.
 Problem Input
Three sides (side 1, side 2, side 3) of the triangle (in centimeter)
Height (h) of the triangle (in centimeter)
 Problem Output
Area of the triangle
Perimeter of the triangle
 Formula to identify the relationship between the input and output
Once we have been able to determine the input and output of the problem, then we can
establish a relationship between the input and output variables using formula(s).
Let the base = side3;
Perimeter = side1+side2+side3;
Area = ½ * base * h;
When solving a problem we extract those variables and relationship that are of interest
to us. The process of modelling a problem by extracting relevant information is known
as abstraction.
11 | P a g e
2.1.3. Design the algorithm to solve the problem (Design).
This phase involves developing the sequence of steps called an algorithm that will be
followed in other to solve a given problem, and after all, a verification will be made to
know if the steps taken was able to solve the problem. It is usually advisable that top-down
design (or divide and conquer) approach be adopted in carrying out this task of algorithm
design and development. Using top-down design implies that the overall solution of the
problem will be realized by unifying all the steps followed and solutions obtained from the
sub modules. Some steps taken at each module might need to be expanded so that the
required details will be provided to adequately, solve the problem. This approach of
expanding the steps by providing additional detailed steps to a particular step is called
stepwise refinement. Let us examine how a lecturer develop his lecture note, he take up a
topic, break it down into sub topics (or course outline), then for each of the sub topics he
fills in some additional details that will enhance the understanding of the course. This
process of providing some additional details into a sub topic or course outline is an example
of stepwise refinement in top down design process.
After all the instructions and steps have been identified, it is important that we simulate the
computer execution process by going through the instructions step-by-step to verify that
all the steps in the design is behaving as intended. This process of simulating the computer
execution process by going through the algorithm step-by-step to detect and correct errors
is known as desk checking. Desk checking helps to detect error early during the algorithm
design. This will alleviate the overhead involved in detecting and correcting error later in
the program development or implementation phase.
2.1.4. Implement the algorithm (Implementation).
After the algorithm has been developed, the next step, which is the implementation of the
algorithm, is to convert every step in the algorithm to an equivalent statement in a
programming language. One algorithm can be implemented using one or more
programming language(s).
2.1.5. Test and verify the completed program (Testing).
Testing and verification involves executing the program in the computer to know if it is
producing the desired result. Testing phase is a very tedious task, as the program has to be
tested given different circumstances and data.
2.1.6. Maintain and update the program (Maintenance).
After the program has been tested, certified and put into productive use, it will be made to
work under different hardware, operating system, geographic locations, security
conditions, etc. and will be expected to deliver its task effectively and uninterruptedly. In
addition, the software is to adapt to changes in government/organizational policies. When
all these start happening the program starts malfunctioning, thereby deviating from the
originally intended task. So based on these there is need for regular or periodic maintenance
and update. This update will continue for a period of five years or more depending on the
organizational policies. During this time, the original developers may have left the
12 | P a g e
company thereby entrusting the responsibility of the software maintenance on may not
have a good understanding of the software and can only be guided by the software
documentation. So based on this for the maintenance and update of a program to be
effective there is need for proper documentation at every point of software development
and maintenance. Maintenance and update is a means through which software are released
at interval to be installed in already existing software to improve its functionality, correct
faults, improve performance or address some security challenges.
2.2. Applications of Software Development Methods in Problem
Solving
In this section, we will be demonstrating how we can apply software development method
to problem solving.
CASE STUDY I: Temperature conversion
THE PROBLEM
You have been entrusted with the job of weather forecasting, and you have a device that
can only read temperature in Celsius and you are expected to report in Fahrenheit. Write a
program to convert every Celsius temperature reading recorded by your device to
Fahrenheit.
ANALYSIS
The first thing to do is to understand what is expected of you in the problem. The problem
says that you will be getting the Celsius temperature from your device, which will be
converted to Fahrenheit. Therefore, the input is Celsius and the output is Fahrenheit. In
this phase, we equally need to ascertain the relationship between the input and the output.
This can be established using the formula.
DATA REQUIREMENT
 Required Input
Celsius /* the temperature in degree Celsius */
Product /* the result obtained after multiplying Celsius by 9/5 */
o Constants
SCALERATE = 9.0/5.0;
TEMPSCALE = 32;
13 | P a g e
 Required Output
Fahrenheit /* the temperature in degree Fahrenheit */
 Required Formulas
Fahrenheit = (Celsius * 9/5) + 32
By substituting the constants SCALERATE for 9/5 and TEMPSCALE for 32 we
have
Fahrenheit = (Celsius * SCALERATE) + TEMPSCALE
DESIGN
The next step will be to formulate the algorithm by listing the sequence of steps needed to
execute the problem. Such steps are listed below:
ALGORITHM
Step 1: Start
Step 2: Read Celsius Temperature
Step 3: Convert Celsius to Fahrenheit
Step 4: Print Fahrenheit
Step 5: Stop
It is time to decide which step needs to be extended further so, as to convey more meaning
and enhance a better clarity. Step 1, 4 and 5 needs no refinement since it is just to start,
read Celsius temperature and display the temperature in Fahrenheit, but step 1 and 2 needs
more refinement like we will see shortly.
o Step 1 refinement
Step 1: Read Celsius Temperature
1.1: Write “Enter Celsius Temperature”
1.2: Read Celsius temperature
1.3: Press return key
o Step 2 refinement
Step 2: Convert Celsius to Fahrenheit
2.1: Fahrenheit = (Celsius * 9/2) + 32
ALGORITHM WITH REFINEMENT
Step 1: Start
Step 2: Read Celsius Temperature
2.1: Write “Enter Celsius temperature value”
14 | P a g e
2.2: Press return key
2.3: Read Celsius temperature
Step 3: Convert Celsius to Fahrenheit
3.1: Fahrenheit = (Celsius * 9/2) + 32
Step 4: Print Fahrenheit
Step 5: Stop
Desk checking
Now that we are done with, the algorithm let us perform a desk check to know if the
algorithm is producing the desired result. See table 2.1. The table consists of four fields the
steps which represents the order of instruction execution, the operation which is responsible
for the actual processing of the instruction, the result displays the outcome of every step
and finally the status shows whether the instruction is given the desired result or not.
Because all the fields are labeled Ok then we conclude that everything is OK and we can
proceed to the next phase which. is implementation.
Step Operations Result Status
1 Algorithm starts here Algorithm starts OK
2 No operation required No result OK
2.1 Request for input User enters 20 from keyboard OK
2.2 Read 20 from keyboard 20 is assigned to Celsius OK
3 No operation required No result OK
3.1 Fahrenheit = (Celsius *9/2) +32 Fahrenheit = 68 OK
4 Print Fahrenheit = 68 Fahrenheit =68 is displayed on screen OK
5 Stop the algorithm Algorithm finishes and terminate OK
Table 2.1: A table to show the status of the desk checking operation
IMPLEMENTATION
After you have completed the design of the algorithm, the next step is to convert every step
of the algorithm to a valid statement in any of the programming languages, in our case C
language. To write the program you need to first state the kind of input (data) you are going
to use in the execution of the program, in our own case we want to use decimal numbers
(i.e. float). In addition, we would want to identify the data in the memory with the names
Celsius, and Fahrenheit. After which we will proceed with the statement that will execute
the main section of the algorithm, which is the section that does the conversion of the
temperature from Celsius to Fahrenheit, i.e. step 3.2 in the algorithm. Note that the
algorithm with the refinement is what you are going to convert not the one without
refinement.
15 | P a g e
Listing 2.1 shows a C program implementation and the sample execution of the refined
algorithm in the Design section. We used statements to explain each step of the program.
For the purpose of brevity, we have deferred the detailed explanation of the program for
now; we will be discussing it in our next class.
/* ***********************************************
* Performs Celsius to Fahrenheit conversion *
************************************************/
#include<stdio.h> /* Definition for printf and Scanf */
void main(){ /* The program starts here */
/* declaration of input variables */
float Celsius;
float Product;
float Fahrenheit;
/* conversion constants */
const float SCALERATE = 9.0/5.0;
const float TEMPSCALE = 32;
/* Read input from keyboard */
printf("Enter Celsius temperature and press enter key when done ");
scanf("%f", &Celsius);
/* Calculate the Fahrenheit equivalent */
Fahrenheit = Celsius * SCALERATE + TEMPSCALE;
/* Print the result (output) of the conversion */
printf("n The Fahrenheit equivalent of n %.2f degree Celsius is %.2f n", Celsius,
Fahrenheit);
} /* The program ends here */
Listing 2.1: Program to convert Celsius temperature to Fahrenheit.
Sample output of the program
Enter Celsius temperature value and press enter key when done >> 20
The Fahrenheit equivalent of
20.00 degree Celsius is 68.00
16 | P a g e
TESTING
Testing the program means verifying that the program will give the required output when
given a set of valid input data. You have to test the program by supplying it with a set of
valid input data and examining the data carefully to know if it corresponds with the
intended output. To be sure that the program is behaving well you have to test it with
variable input sets. In some cases, you might have to test how the program will behave if
given some unrelated input values. This has to be ascertained so that the program will not
crash when someone mistakenly put some unrelated input value(s).
USE CASE II: Volume calculation
THE PROBLEM
Given the radius and height of a cylinder, calculate the volume
ANALYSIS
From the problem, we can deduce that the solution will require two inputs the radius and
height of the cylinder then one output will be required which is the volume. The input
values will be of float (fractional) type, since the constant pie is of decimal type, which
will change the integer variable to be of fractional type. The relationship that exist between
the variables (i.e. the input and output) will be listed subsequently.
DATA REQUIREMENT
 Required Constant
PI 3.14 /* the value of the constant PI */
 Required Input
Radius /* the radius of the cylinder */
Height /* the height of the cylinder */
Area /* the area of the cylinder */
 Required Output
Volume /* the volume of the cylinder */
 Required Formulas
Area = PI * Radius * Radius
Volume = Area * Height
17 | P a g e
DESIGN
ALGORITHM
Step 1: Start
Step 2: Get input
Step 3: Calculate volume
Step 4: Print volume
Step 5: Stop
o Step 2 refinement
2.1: Request for input
2.2: Read input
o Step 3 refinement
3.1: Area = PI * Radius * Radius
3.2: Volume = Area * Height
ALGORITHM WITH REFINEMENT
Step 1: Start
Step 2: Get input
2.1: Request for input
2.2: Read input
Step 3: Calculate volume
3.1: Area = PI * Radius * Radius
3.2: Volume = Area * Height
Step 4: Print volume
Step 5: Stop
The relationship between the original problem and its sub-problems (subtasks) can be
demonstrated using structured chart as show in figure 2.2. The algorithm and the structured
chart has the same sub-problem (subtask) though they differ in some ways, the algorithm
shows the sequence of steps to be followed to accomplish the task while the structured
chart only shows the subordination that exists between the main task and the rest of the
subtask and equally the relationships that exists between the modules.
18 | P a g e
Figure 2.2: Structured chart to show the top-down model of the prison problem
.
Desk checking
Table 2.2 shows how we have manually executed the instructions written in the algorithm
to know if the algorithm we give the desired result.
Step Operations Result Status
1 Algorithm starts here Algorithm starts OK
2 No operation required No result OK
2.1 Request for input User enters 7 and 8 from keyboard OK
2.2 Read 7 and 8 from keyboard
7 is assigned to radius and 8 is assigned
to height OK
3 No operation required No result OK
3.1 Area = 3.142 * 7 * 7 Area = 153.86 OK
3.2 Volume = 153.86 * 8 Volume = 1230.88 OK
4 Print volume Algorithm finishes and terminate OK
5 Stop the algorithm Algorithm stops here OK
Table 2.2: A desk check to verify if the algorithm is solving the intended problem.
IMPLEMENTATION
/* ***********************************************
* Calculate the volume of a cylinder *
************************************************/
#include<stdio.h> /* Definition for printf and Scanf */
void main(){ /* The program starts here */
/* Perform variable declaration */
#define PI 3.142
float radius;
float height;
float area;
float volume;
/* Read read radius and height from keyboard */
printf("Enter the the radius and press enter >> ");
scanf("%f", &radius);
19 | P a g e
printf("Enter the height and press enter >> ");
scanf("%f", &height);
/* Calculate volume */
area = PI * radius * radius;
volume = area * height;
/* Print volume */
printf("The volume of the cylinder is %f ", volume );
} /* the program finishes or terminates here */
Sample output of the program
Enter the the radius and press enter key >> 7
Enter the height and press enter key >> 8
The volume of the cylinder is 1231.66
TESTING
The same explanation given in case study I still holds in here so you can refer to testing in
case study I for a review.
Summary
 A problem is a situation that is to be resolved using well-defined mathematical
principles
 Solution is a means of finding solution to a problem
 Problem solving is an act of finding a solution to perplexing, distressing, vexing or
unsettled question
 Computer cannot be used to solve problems relating to physical activities or
emotional problems
 Computer is very good at solving repetitive tasks in fast and consistent manner
 The four Polya’s problem solving strategies are: Understanding the problem,
Device a plan, Carrying out the plan and Looking back
 An algorithm is a sequential set of instructions that are followed in other to solve a
problem using a finite amount of data and time.
 In problem solving one problem can have many algorithm while one algorithm can
be implemented using many programs
 An algorithm consist of three components: input, process and output
 An algorithm consist of five properties: Finiteness, Definiteness, Effectiveness,
Generality, and Input/output
20 | P a g e
 An algorithm can be expressed in three ways: Natural Language, Pseudo Code, and
Flow Chart.
 The two methodologies used in the development of algorithm are top-down design
and object oriented design (OOD).
 Top-down design is algorithm development approach that involves decomposition
of a large problem into manageable parts, that can be solved and unified to form
the solution of the overall problem
 A module is a self-contained set of steps needed for the solution of problems
 In top down-design approach, the problems are divided in a structured chart that
are composed of modules.
 Abstract step is a step in the algorithm that contains some unspecified details
 Concrete step is a step in the algorithm for which there is no need for further
specification of details.
 Software Development Method is made up of the following implementation
strategies: requirement specification, analysis, design, implementation, testing and
maintenance.
 Stepwise refinement is an algorithm development process that involves providing
in each step all the details needed to solve a problem.
 Desk checking is the process of simulating the computer execution process by
going through the algorithm step-by-step in other to detect and correct errors.
 Abstraction is the process of modeling a problem by extracting the relevant
information from the problem.
Exercises
Algorithm questions
1. Write an algorithm to calculate simple interest
2. Write an algorithm to calculate area of triangle
3. Write an algorithm to find the largest of three numbers x, y, z
4. Write an algorithm to test if a given integer value is prime or not
Programming questions
5. Write a C program to calculate simple interest
6. Write a C program to calculate area of triangle
7. Write a C program to find the largest of three numbers x, y, z
8. Write a C program to test if a given integer value is prime or not
Other questions
I will send more question before our next meeting.
21 | P a g e
References
Government of Andhra Pradesh. (n.d.). Board of Intermediate Education. Retrieved from
bieap.gov.in/Pdf/CSPaperII.pdf
Institute of Distance & Open Learning (IDOL). (n.d.). University of Mubai. Retrieved from
archive.mu.ac.in/myweb_test/syllFybscit/C++.pdf
Koffman, J. R. (2016). ProblemSolving and Program Design in C. England: Pearson Education Limited.
McQuain. (2011, 12). CS 2104: Introduction to Problem Solving. Retrieved from Computer
Science@Virginia Tech: courses.cs.vt.edu/cs2104/Fall12/notes/T16_Algorithms.pdf
Nell Dale, John Lewis. (2002). C o m p u t e r Sc i e n c e Illuminated. Singapore: Jones and Bartlett.

Contenu connexe

Tendances

pseudo code basics
pseudo code basicspseudo code basics
pseudo code basicsSabik T S
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming conceptssalmankhan570
 
PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESPROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESABHINAV SINGH
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programmingNoel Malle
 
Operating System Multiple Choice Questions
Operating System Multiple Choice QuestionsOperating System Multiple Choice Questions
Operating System Multiple Choice QuestionsShusil Baral
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programmingJordan Delacruz
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentationfazli khaliq
 
Programming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharProgramming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharVivek Parihar
 
Chap 2 classification of parralel architecture and introduction to parllel p...
Chap 2  classification of parralel architecture and introduction to parllel p...Chap 2  classification of parralel architecture and introduction to parllel p...
Chap 2 classification of parralel architecture and introduction to parllel p...Malobe Lottin Cyrille Marcel
 
Artificial Intelligence: The Nine Phases of the Expert System Development Lif...
Artificial Intelligence: The Nine Phases of the Expert System Development Lif...Artificial Intelligence: The Nine Phases of the Expert System Development Lif...
Artificial Intelligence: The Nine Phases of the Expert System Development Lif...The Integral Worm
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & ReasoningSajid Marwat
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of CompilersSarmad Ali
 
Types of Programming Errors
Types of Programming ErrorsTypes of Programming Errors
Types of Programming ErrorsNeha Sharma
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer Ashim Lamichhane
 
Types of errors
Types of errorsTypes of errors
Types of errorsRiya Josh
 

Tendances (20)

pseudo code basics
pseudo code basicspseudo code basics
pseudo code basics
 
Basic programming concepts
Basic programming conceptsBasic programming concepts
Basic programming concepts
 
PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESPROGRAMMING LANGUAGES
PROGRAMMING LANGUAGES
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Operating System Multiple Choice Questions
Operating System Multiple Choice QuestionsOperating System Multiple Choice Questions
Operating System Multiple Choice Questions
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Programming languages and concepts by vivek parihar
Programming languages and concepts by vivek pariharProgramming languages and concepts by vivek parihar
Programming languages and concepts by vivek parihar
 
Chap 2 classification of parralel architecture and introduction to parllel p...
Chap 2  classification of parralel architecture and introduction to parllel p...Chap 2  classification of parralel architecture and introduction to parllel p...
Chap 2 classification of parralel architecture and introduction to parllel p...
 
Artificial Intelligence: The Nine Phases of the Expert System Development Lif...
Artificial Intelligence: The Nine Phases of the Expert System Development Lif...Artificial Intelligence: The Nine Phases of the Expert System Development Lif...
Artificial Intelligence: The Nine Phases of the Expert System Development Lif...
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
 
Computer fundamental
Computer fundamentalComputer fundamental
Computer fundamental
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
 
Presentation 1
Presentation 1Presentation 1
Presentation 1
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Types of Programming Errors
Types of Programming ErrorsTypes of Programming Errors
Types of Programming Errors
 
The calculator
The calculatorThe calculator
The calculator
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Types of errors
Types of errorsTypes of errors
Types of errors
 
Amdahl`s law -Processor performance
Amdahl`s law -Processor performanceAmdahl`s law -Processor performance
Amdahl`s law -Processor performance
 

Similaire à Csc 102 lecture note(introduction to problem solving)

Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to ProgrammingProf Ansari
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)TejaswiB4
 
PROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUESPROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUESsudhanagarajan5
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)praveena p
 
operation research notes
operation research notesoperation research notes
operation research notesRenu Thakur
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer ProgrammingProf. Erwin Globio
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptxshoaibkhan716300
 
PCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptxPCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptxsudharsanm56
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESHarshJha34
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CPrabu U
 
1 Saint Leo University GBA 334 Applied Decision.docx
 1 Saint Leo University  GBA 334  Applied Decision.docx 1 Saint Leo University  GBA 334  Applied Decision.docx
1 Saint Leo University GBA 334 Applied Decision.docxaryan532920
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sitSaurabh846965
 
Program concep sequential statements
Program concep sequential statementsProgram concep sequential statements
Program concep sequential statementsankurkhanna
 
GE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfGE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfAsst.prof M.Gokilavani
 

Similaire à Csc 102 lecture note(introduction to problem solving) (20)

Introduction to Programming
Introduction to ProgrammingIntroduction to Programming
Introduction to Programming
 
Chapter 2(1)
Chapter 2(1)Chapter 2(1)
Chapter 2(1)
 
PROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUESPROBLEM SOLVING TECHNIQUES
PROBLEM SOLVING TECHNIQUES
 
Unit 1 python (2021 r)
Unit 1 python (2021 r)Unit 1 python (2021 r)
Unit 1 python (2021 r)
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
 
operation research notes
operation research notesoperation research notes
operation research notes
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
Programming_Lecture_1.pptx
Programming_Lecture_1.pptxProgramming_Lecture_1.pptx
Programming_Lecture_1.pptx
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
 
PCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptxPCCF UNIT - 1 - M.Sudharsan.pptx
PCCF UNIT - 1 - M.Sudharsan.pptx
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
1 Saint Leo University GBA 334 Applied Decision.docx
 1 Saint Leo University  GBA 334  Applied Decision.docx 1 Saint Leo University  GBA 334  Applied Decision.docx
1 Saint Leo University GBA 334 Applied Decision.docx
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
 
DebuggingMOZ04
DebuggingMOZ04DebuggingMOZ04
DebuggingMOZ04
 
Software Development
Software DevelopmentSoftware Development
Software Development
 
Program concep sequential statements
Program concep sequential statementsProgram concep sequential statements
Program concep sequential statements
 
GE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdfGE3151 PSPP _Unit 1 notes and Question bank.pdf
GE3151 PSPP _Unit 1 notes and Question bank.pdf
 

Dernier

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 

Dernier (20)

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 

Csc 102 lecture note(introduction to problem solving)

  • 1. 1 | P a g e FEDERAL UNIVERSITY, NDUFU-ALIKE IKWO (FUNAI) FACULTY OF SCIENCE DEPARTMENT OF MATHEMATICS/COMPUTER SCIENCE/STATISTICS/INFORMATICS CSC 102: INTRODUCTION TO PROBLEM SOLVING (LECTURE NOTE) PROGRAM TEAM MEMBERS Chizoba C. Nnamene (Course Coordinator) Ikenna Ezea
  • 2. 2 | P a g e COURSE DESCRIPTION This course is designed to equip the student with the skills needed to solve problem in a broad range of fields. It lays more emphases on the appropriate problem solving skills a computer scientist or a programmer may need for the execution of variable range of tasks. After the completion of this course, the student is expected to know the following problems solving concepts:  Problem solving strategies  Role of algorithm in problem solving process  Implementation strategies  Concepts of algorithm  Properties of algorithm Prerequisite: A background in CSC 101: Introduction to computer science or any other related course(s) is essential. The course description at a glance Course content Section Problem solving strategies See section 1.1 Concepts of algorithm See section 1.2 Properties of algorithm See section 1.2.2 Role of algorithm in problem solving process See section 1.2.3 Implementation strategies See section 2.1
  • 3. 3 | P a g e CONTENTS 1.0 Introduction 4 1.1. General Problem Solving Strategies 4 1.2. Concepts of Algorithm 5 1.2.1. Major Components of Algorithm 6 1.2.2. Properties of Algorithm 6 1.2.3. Role of Algorithm in Problem Solving 7 1.2.4. Ways of expressing Algorithm 7 1.2.5. Algorithm Development Methodologies 8 1.2.5.1. Top-Down Design 8 1.2.5.2. Object Oriented Design 9 2.1 Implementations strategies 9 2.1.1. Specify the problem requirements (Requirement Specification). 10 2.1.2. Analyze the problem (Analysis) 10 2.1.3. Design the algorithm to solve the problem (Design). 11 2.1.4. Implement the algorithm (Implementation). 11 2.1.5. Test and verify the completed program (Testing). 11 2.1.6. Maintain and update the program (Maintenance). 11 2.2. Applications of Software Development Methods in Problem Solving 12 CASE STUDY I: Temperature conversion 12 USE CASE II: Volume calculation 16 Summary 19 Exercises 20 References 21
  • 4. 4 | P a g e 1.0. Introduction Problem solving is a compound word that is composed of two words, “Problem” and “Solving”. For us to give a definition we need to take the words into context. Depending on the context, problem has been defined in a number of ways. The dictionary definition holds that problem is a question raised for inquiry, consideration or solution, in mathematics problem has been defined as a situation that is to be resolved using well- defined mathematical principles. Solving on the other hand can be defined as a means of finding solution to a problem. Based on the above definitions we can formally define problem solving as the act of finding a solution to perplexing, distressing, vexing or unsettled question. Though the definition of problems cited in the first paragraph suits this definition, some of them are not suitable in the context of computing. This is because computers are limited in its problem solving capabilities. Computers cannot be used in solving problems involving physical activities or emotions. Such as resolving marital problems, providing solutions to the age long problems between Catholics and Protestants, squeezing passengers in an overloaded bus, or the religious conflict between Muslims and Christians in Nigeria. A computer can be considered as an unintelligent device in that it cannot act unless when instructed to do so. It cannot analyze and proffer a solution to a problem without the programmer performing the analysis and providing the instructions in form of a program, which is fed into the computer in other to carry out the designated task. However, once a problem has been analyzed and instruction translated into program the computer has the ability to carry out the processing in a very fast, repeated and consistent manner for different data entry and variable situations. Computer helps people in the computation of repeated and boring tasks, thereby saving time and effort required to carry out the tasks. Computers can be used for registration of courses, administering of examinations and marking of scripts, financial management and budgeting, etc. 1.1. General Problem Solving Strategies To solve a problem one has to understand the problem domain and the situation to avoid mistakes or incorrect assumptions. To be a better problem solver we need to have a good understanding of the general problem-solving framework. One of the frameworks is the one outlined by Polya in his book “How to solve it”. This problem solving approach even though was written for mathematical problem solving it has been widely adopted in computing and many other problem solving domains. The four Polya’s problem solving strategies are: 1. Understanding the problem: Carefully read the problem to understand what needs to be accomplished. Assess your background skills in the area under consideration to know if you have to acquire more skills in other to solve the problem. Visualize the final-result and use it as a guide in determining the validity of your solution and the result that will be obtained. Identify the known and the unknown (variables). Check the data and the conditions that needs to be satisfied. Check to know if the condition is
  • 5. 5 | P a g e sufficient to determine the unknown. Split the problem into parts and write down the parts. 2. Device a plan: Check to see if there is a link between the data and the unknown (variable), if there is no link then try using auxiliary problem. Check if a similar problem exists so you can adapt the solution instead of reinventing the wheel. After all, the outcome of this phase is the plan of the solution. 3. Carrying out the plan: In carrying out the plan, you have to go through the steps to know if they are correct, ascertain if there is any missing link. Check if the correctness of the plan can be proved. If the plan does not work correctly, discard it and try another plan. 4. Looking Back: This is the moment of reflection. This is the phase that you can crosscheck what you have done to arrive at the present stage. In this phase, you can ascertain what worked and what did not work. This is the time your argument and results are verified for correctness and consistency. In this phase, you can check if the solution can be applied in other problems. At this point, you can also ascertain if you can still get the same result using different methods. 1.2. Concepts of Algorithm Problem solving as we have seen involves the abstraction and decomposition of large amount of problem into smaller manageable subtasks that can be handled independently. An algorithm is important in the planning and execution of a problem solution since it specifies the sequence of steps needed to carry out the instructions that will lead to the overall result. An algorithm can be defined as a sequential set of instructions that are followed in other to solve a problem using a finite amount of data in a finite amount of time. More than one algorithm can be written for a particular problem (see figure 1.0) but the choice of selecting a particular algorithm in place of the other is dependent on the following factors: reliability, accuracy, ease of modification and time required for the execution when converted to a high-level language. Figure 1.0: Relationship between Problem, Algorithms and Programs
  • 6. 6 | P a g e 1.2.1. Major Components of Algorithm Most of the algorithms used in solving program related problems consist of three major sections: the input, processing and output. That is the summary of most if not all the activities undertaken by most algorithm in other to produce a result. To execute a task the algorithm requires some data (i.e. input), it performs some computation on the data (i.e. processing) then it produces result (i.e. output). The processing comprises of any or all of the following: computation, selection, iteration, etc. Figure 1.1. Shows the three major sections of an algorithm. Figure 1.1: The three major sections of an Algorithm Input: This represent the data that is to be sent for processing in the system. Most algorithms provides some variables and the description of the data that the variable will handle. Processing: This is the action performed on data in other to produce the desired result. Such actions like computation, selection, iteration, etc. Output: This is the result produced after the data has been processed. When the algorithm has been converted to programs, the data is usually displayed through the output device, for example the monitor. 1.2.2. Properties of Algorithm a. Finiteness: An algorithm should be able to terminate after a finite number of instructions must have been processed. That means it does not have to take forever to process a set of instructions. b. Definiteness: The algorithm should be developed in a form that each step will be precise and easy to understand. c. Effectiveness: This means that the algorithm should be in a form that will be easy to convert to a programming statement in a finite amount of time. d. Generality: The algorithm should be able to produce the same output when given different type of valid data (i.e. data taking from a specified domain). e. Input/output: The algorithm should be able to produce output value(s) when given a set of specified input value(s). There should be a relationship between the input and the output produced by the algorithm.
  • 7. 7 | P a g e 1.2.3. Role of Algorithm in Problem Solving a. Algorithm helps in the evaluation of a problem to know if it can be solved using a computer. Once an algorithm can be written for a problem then the problem can be solved using computational means. b. Algorithm helps in the identification of the various steps, major decision points and the variables needed to solve a problem. This are the concepts that are needed for the development of a computer program. c. Algorithm helps in the decomposition of a large task into small manageable subtasks. The decomposition helps in reducing the complexity of the problem and make it solvable. d. The atomic nature of the tasks/subtasks of the algorithm makes the decision making process more rational in nature, since the subtasks are supported by facts. e. Given different tasks, one algorithm can be applied in performing all the tasks. This enhances the consistency and reliability of the problem solving process. 1.2.4. Ways of expressing Algorithm The expression of algorithm can come in three major ways. They are:  Natural Language: This is a method of expressing algorithm using our day-to-day language, like English or other languages. This has been found to be disadvantageous as it is very wordy and confusing. Example 1.1: Write an algorithm in natural language to calculate the area of a triangle (area = ½ * base * height) Solution Step 1: Start Step 2: Select from the triangle the values for base and height Step 3: Calculate the product of the values (i.e. base and height) Step 4: Divide the product of base and height by 2 Step 5: The area is the result gotten after dividing base and height by 2 Step 6: Stop  Pseudo Code: This type of expression has a form that is closely related to a programming language though there is no restriction on the syntax. It is not ambiguous like the natural language. Example 1.2: Write a pseudo code to calculate the area of a triangle Solution: Step 1: Start Step 2: Read base and height Step 3: Product = base x height Step 4: Area = product/2 Step 5: Print Area Step 6: Stop
  • 8. 8 | P a g e  Flow chart: Uses symbols to represent the sequence of instructions. It is not ambiguous like the natural language, but the modification is done using a specialized tool. In addition, the implementation uses a standard rules. Example 1.1: Draw a flowchart to calculate the area of a triangle (area = ½ * base * height) Solution: 1.2.5. Algorithm Development Methodologies Algorithm development can be approached using the following methodologies: Top- Down Design (functional decomposition) and Object Oriented Design. We will proceed with the explanation of top-down design in the next section, after that we will explain Object Oriented Design. 1.2.5.1. Top-Down Design The most common problem solving approach that is used among humans is divide and conquer, which means dividing a large problem into smaller parts that can be solved independently. This is the concept used in Top-Down Design. Top-down design, which is also called functional decomposition, is a problem solving methodology that involves splitting a large problem into smaller manageable parts that can be solved independently and integrated to form the overall solution. The problems in a top-down design are arranged in a hierarchical tree structure (structured chart), consisting of problems or sub problems called modules. A module is a self-contained set of steps needed for the solution of a problem. The modules are arranged in a hierarchy from top to the bottom in a structure chart. The module at the top is the main problem while the once at the bottom is a sub division of the problem. The modules are numbered according to their position in the hierarchy; those in the same level are given the same number. The numbering starts from top, which is usually zero, down to the bottom, which can be any finite number, depending on the problem. The reason for the division of the problems into modules, parts, or segments is to reduce the complexity of the problem by sub dividing them into smaller manageable independent parts. In the context of computer science, the responsibility of the module
  • 9. 9 | P a g e depends on the requirement of the problem. Some of the module(s) could be responsible for data input, some may perform processing of data, this may involve; mathematical, logical or relational operation, while some may be responsible for the output. As an example, let us refer to figure 2.1. The figure is a hierarchical tree structure (structured chart) that consist of three levels (level 0, 1, 2, and 3) the top level or level 0 describes the function of the overall problem. It is the abstract step because the problems at this level can further be decomposed into smaller sub problems in the levels that follows. The last module at the bottom (i.e. the module at level 3), that cannot be decomposed any further is called the concrete step. Refer to case study II to see a detailed example of dot-down design methodology. Figure 2.1: An illustration of top-down design using a structured chart 1.2.5.2. Object Oriented Design 2.1 Implementations strategies In section 1.1, we introduced general problem solving strategies using Polya’s approach. In this section, we are going to limit our conversation to computer-based problem solving strategy. Problem solving is an activity undertaken in every programming or software development environment, so it is an indispensable knowledge needed by every programmer or software developer. Problem solving is not just limited to computer scientists, or programmers, it is also used by business students, engineers and scientists though in a different way. In business studies, students use systems approach, while in engineering and science, the engineers and scientists use engineering and scientific method respectively, the programmers on the other hand use software development approach, and
  • 10. 10 | P a g e that is going to be our topic of discussion in this section. The software development methods are as follows: 2.1.1.Specify the problem requirements (Requirement Specification). This involves a critical examination of the posed problem so, as to get a better understanding of the requirement needed to solve the problem. The problem is restated and every unimportant aspects are eliminated at this point. This is to help in presenting the problem in a clear and unambiguous form. 2.1.2.Analyze the problem (Analysis) The identification of the input variables (i.e. the data) needed for the implementation of the problem is done at this point. The expected output (i.e. the result) that is to be obtained after the execution of the input data and the formats (example a table with heading, rows and columns) of presenting the result are also identified. The use of formulas or other methods as a means of expressing the relationship that exists with the variables in the problem is strongly encouraged. It is important to note that if the first step and this second step is not carried out properly, it will lead to error or failure in the solution. See example 2.1 for explanation of this phase. Example 2.1: Given the three sides and height of a triangle, calculate in centimeter the area and perimeter of the triangle.  Problem Input Three sides (side 1, side 2, side 3) of the triangle (in centimeter) Height (h) of the triangle (in centimeter)  Problem Output Area of the triangle Perimeter of the triangle  Formula to identify the relationship between the input and output Once we have been able to determine the input and output of the problem, then we can establish a relationship between the input and output variables using formula(s). Let the base = side3; Perimeter = side1+side2+side3; Area = ½ * base * h; When solving a problem we extract those variables and relationship that are of interest to us. The process of modelling a problem by extracting relevant information is known as abstraction.
  • 11. 11 | P a g e 2.1.3. Design the algorithm to solve the problem (Design). This phase involves developing the sequence of steps called an algorithm that will be followed in other to solve a given problem, and after all, a verification will be made to know if the steps taken was able to solve the problem. It is usually advisable that top-down design (or divide and conquer) approach be adopted in carrying out this task of algorithm design and development. Using top-down design implies that the overall solution of the problem will be realized by unifying all the steps followed and solutions obtained from the sub modules. Some steps taken at each module might need to be expanded so that the required details will be provided to adequately, solve the problem. This approach of expanding the steps by providing additional detailed steps to a particular step is called stepwise refinement. Let us examine how a lecturer develop his lecture note, he take up a topic, break it down into sub topics (or course outline), then for each of the sub topics he fills in some additional details that will enhance the understanding of the course. This process of providing some additional details into a sub topic or course outline is an example of stepwise refinement in top down design process. After all the instructions and steps have been identified, it is important that we simulate the computer execution process by going through the instructions step-by-step to verify that all the steps in the design is behaving as intended. This process of simulating the computer execution process by going through the algorithm step-by-step to detect and correct errors is known as desk checking. Desk checking helps to detect error early during the algorithm design. This will alleviate the overhead involved in detecting and correcting error later in the program development or implementation phase. 2.1.4. Implement the algorithm (Implementation). After the algorithm has been developed, the next step, which is the implementation of the algorithm, is to convert every step in the algorithm to an equivalent statement in a programming language. One algorithm can be implemented using one or more programming language(s). 2.1.5. Test and verify the completed program (Testing). Testing and verification involves executing the program in the computer to know if it is producing the desired result. Testing phase is a very tedious task, as the program has to be tested given different circumstances and data. 2.1.6. Maintain and update the program (Maintenance). After the program has been tested, certified and put into productive use, it will be made to work under different hardware, operating system, geographic locations, security conditions, etc. and will be expected to deliver its task effectively and uninterruptedly. In addition, the software is to adapt to changes in government/organizational policies. When all these start happening the program starts malfunctioning, thereby deviating from the originally intended task. So based on these there is need for regular or periodic maintenance and update. This update will continue for a period of five years or more depending on the organizational policies. During this time, the original developers may have left the
  • 12. 12 | P a g e company thereby entrusting the responsibility of the software maintenance on may not have a good understanding of the software and can only be guided by the software documentation. So based on this for the maintenance and update of a program to be effective there is need for proper documentation at every point of software development and maintenance. Maintenance and update is a means through which software are released at interval to be installed in already existing software to improve its functionality, correct faults, improve performance or address some security challenges. 2.2. Applications of Software Development Methods in Problem Solving In this section, we will be demonstrating how we can apply software development method to problem solving. CASE STUDY I: Temperature conversion THE PROBLEM You have been entrusted with the job of weather forecasting, and you have a device that can only read temperature in Celsius and you are expected to report in Fahrenheit. Write a program to convert every Celsius temperature reading recorded by your device to Fahrenheit. ANALYSIS The first thing to do is to understand what is expected of you in the problem. The problem says that you will be getting the Celsius temperature from your device, which will be converted to Fahrenheit. Therefore, the input is Celsius and the output is Fahrenheit. In this phase, we equally need to ascertain the relationship between the input and the output. This can be established using the formula. DATA REQUIREMENT  Required Input Celsius /* the temperature in degree Celsius */ Product /* the result obtained after multiplying Celsius by 9/5 */ o Constants SCALERATE = 9.0/5.0; TEMPSCALE = 32;
  • 13. 13 | P a g e  Required Output Fahrenheit /* the temperature in degree Fahrenheit */  Required Formulas Fahrenheit = (Celsius * 9/5) + 32 By substituting the constants SCALERATE for 9/5 and TEMPSCALE for 32 we have Fahrenheit = (Celsius * SCALERATE) + TEMPSCALE DESIGN The next step will be to formulate the algorithm by listing the sequence of steps needed to execute the problem. Such steps are listed below: ALGORITHM Step 1: Start Step 2: Read Celsius Temperature Step 3: Convert Celsius to Fahrenheit Step 4: Print Fahrenheit Step 5: Stop It is time to decide which step needs to be extended further so, as to convey more meaning and enhance a better clarity. Step 1, 4 and 5 needs no refinement since it is just to start, read Celsius temperature and display the temperature in Fahrenheit, but step 1 and 2 needs more refinement like we will see shortly. o Step 1 refinement Step 1: Read Celsius Temperature 1.1: Write “Enter Celsius Temperature” 1.2: Read Celsius temperature 1.3: Press return key o Step 2 refinement Step 2: Convert Celsius to Fahrenheit 2.1: Fahrenheit = (Celsius * 9/2) + 32 ALGORITHM WITH REFINEMENT Step 1: Start Step 2: Read Celsius Temperature 2.1: Write “Enter Celsius temperature value”
  • 14. 14 | P a g e 2.2: Press return key 2.3: Read Celsius temperature Step 3: Convert Celsius to Fahrenheit 3.1: Fahrenheit = (Celsius * 9/2) + 32 Step 4: Print Fahrenheit Step 5: Stop Desk checking Now that we are done with, the algorithm let us perform a desk check to know if the algorithm is producing the desired result. See table 2.1. The table consists of four fields the steps which represents the order of instruction execution, the operation which is responsible for the actual processing of the instruction, the result displays the outcome of every step and finally the status shows whether the instruction is given the desired result or not. Because all the fields are labeled Ok then we conclude that everything is OK and we can proceed to the next phase which. is implementation. Step Operations Result Status 1 Algorithm starts here Algorithm starts OK 2 No operation required No result OK 2.1 Request for input User enters 20 from keyboard OK 2.2 Read 20 from keyboard 20 is assigned to Celsius OK 3 No operation required No result OK 3.1 Fahrenheit = (Celsius *9/2) +32 Fahrenheit = 68 OK 4 Print Fahrenheit = 68 Fahrenheit =68 is displayed on screen OK 5 Stop the algorithm Algorithm finishes and terminate OK Table 2.1: A table to show the status of the desk checking operation IMPLEMENTATION After you have completed the design of the algorithm, the next step is to convert every step of the algorithm to a valid statement in any of the programming languages, in our case C language. To write the program you need to first state the kind of input (data) you are going to use in the execution of the program, in our own case we want to use decimal numbers (i.e. float). In addition, we would want to identify the data in the memory with the names Celsius, and Fahrenheit. After which we will proceed with the statement that will execute the main section of the algorithm, which is the section that does the conversion of the temperature from Celsius to Fahrenheit, i.e. step 3.2 in the algorithm. Note that the algorithm with the refinement is what you are going to convert not the one without refinement.
  • 15. 15 | P a g e Listing 2.1 shows a C program implementation and the sample execution of the refined algorithm in the Design section. We used statements to explain each step of the program. For the purpose of brevity, we have deferred the detailed explanation of the program for now; we will be discussing it in our next class. /* *********************************************** * Performs Celsius to Fahrenheit conversion * ************************************************/ #include<stdio.h> /* Definition for printf and Scanf */ void main(){ /* The program starts here */ /* declaration of input variables */ float Celsius; float Product; float Fahrenheit; /* conversion constants */ const float SCALERATE = 9.0/5.0; const float TEMPSCALE = 32; /* Read input from keyboard */ printf("Enter Celsius temperature and press enter key when done "); scanf("%f", &Celsius); /* Calculate the Fahrenheit equivalent */ Fahrenheit = Celsius * SCALERATE + TEMPSCALE; /* Print the result (output) of the conversion */ printf("n The Fahrenheit equivalent of n %.2f degree Celsius is %.2f n", Celsius, Fahrenheit); } /* The program ends here */ Listing 2.1: Program to convert Celsius temperature to Fahrenheit. Sample output of the program Enter Celsius temperature value and press enter key when done >> 20 The Fahrenheit equivalent of 20.00 degree Celsius is 68.00
  • 16. 16 | P a g e TESTING Testing the program means verifying that the program will give the required output when given a set of valid input data. You have to test the program by supplying it with a set of valid input data and examining the data carefully to know if it corresponds with the intended output. To be sure that the program is behaving well you have to test it with variable input sets. In some cases, you might have to test how the program will behave if given some unrelated input values. This has to be ascertained so that the program will not crash when someone mistakenly put some unrelated input value(s). USE CASE II: Volume calculation THE PROBLEM Given the radius and height of a cylinder, calculate the volume ANALYSIS From the problem, we can deduce that the solution will require two inputs the radius and height of the cylinder then one output will be required which is the volume. The input values will be of float (fractional) type, since the constant pie is of decimal type, which will change the integer variable to be of fractional type. The relationship that exist between the variables (i.e. the input and output) will be listed subsequently. DATA REQUIREMENT  Required Constant PI 3.14 /* the value of the constant PI */  Required Input Radius /* the radius of the cylinder */ Height /* the height of the cylinder */ Area /* the area of the cylinder */  Required Output Volume /* the volume of the cylinder */  Required Formulas Area = PI * Radius * Radius Volume = Area * Height
  • 17. 17 | P a g e DESIGN ALGORITHM Step 1: Start Step 2: Get input Step 3: Calculate volume Step 4: Print volume Step 5: Stop o Step 2 refinement 2.1: Request for input 2.2: Read input o Step 3 refinement 3.1: Area = PI * Radius * Radius 3.2: Volume = Area * Height ALGORITHM WITH REFINEMENT Step 1: Start Step 2: Get input 2.1: Request for input 2.2: Read input Step 3: Calculate volume 3.1: Area = PI * Radius * Radius 3.2: Volume = Area * Height Step 4: Print volume Step 5: Stop The relationship between the original problem and its sub-problems (subtasks) can be demonstrated using structured chart as show in figure 2.2. The algorithm and the structured chart has the same sub-problem (subtask) though they differ in some ways, the algorithm shows the sequence of steps to be followed to accomplish the task while the structured chart only shows the subordination that exists between the main task and the rest of the subtask and equally the relationships that exists between the modules.
  • 18. 18 | P a g e Figure 2.2: Structured chart to show the top-down model of the prison problem . Desk checking Table 2.2 shows how we have manually executed the instructions written in the algorithm to know if the algorithm we give the desired result. Step Operations Result Status 1 Algorithm starts here Algorithm starts OK 2 No operation required No result OK 2.1 Request for input User enters 7 and 8 from keyboard OK 2.2 Read 7 and 8 from keyboard 7 is assigned to radius and 8 is assigned to height OK 3 No operation required No result OK 3.1 Area = 3.142 * 7 * 7 Area = 153.86 OK 3.2 Volume = 153.86 * 8 Volume = 1230.88 OK 4 Print volume Algorithm finishes and terminate OK 5 Stop the algorithm Algorithm stops here OK Table 2.2: A desk check to verify if the algorithm is solving the intended problem. IMPLEMENTATION /* *********************************************** * Calculate the volume of a cylinder * ************************************************/ #include<stdio.h> /* Definition for printf and Scanf */ void main(){ /* The program starts here */ /* Perform variable declaration */ #define PI 3.142 float radius; float height; float area; float volume; /* Read read radius and height from keyboard */ printf("Enter the the radius and press enter >> "); scanf("%f", &radius);
  • 19. 19 | P a g e printf("Enter the height and press enter >> "); scanf("%f", &height); /* Calculate volume */ area = PI * radius * radius; volume = area * height; /* Print volume */ printf("The volume of the cylinder is %f ", volume ); } /* the program finishes or terminates here */ Sample output of the program Enter the the radius and press enter key >> 7 Enter the height and press enter key >> 8 The volume of the cylinder is 1231.66 TESTING The same explanation given in case study I still holds in here so you can refer to testing in case study I for a review. Summary  A problem is a situation that is to be resolved using well-defined mathematical principles  Solution is a means of finding solution to a problem  Problem solving is an act of finding a solution to perplexing, distressing, vexing or unsettled question  Computer cannot be used to solve problems relating to physical activities or emotional problems  Computer is very good at solving repetitive tasks in fast and consistent manner  The four Polya’s problem solving strategies are: Understanding the problem, Device a plan, Carrying out the plan and Looking back  An algorithm is a sequential set of instructions that are followed in other to solve a problem using a finite amount of data and time.  In problem solving one problem can have many algorithm while one algorithm can be implemented using many programs  An algorithm consist of three components: input, process and output  An algorithm consist of five properties: Finiteness, Definiteness, Effectiveness, Generality, and Input/output
  • 20. 20 | P a g e  An algorithm can be expressed in three ways: Natural Language, Pseudo Code, and Flow Chart.  The two methodologies used in the development of algorithm are top-down design and object oriented design (OOD).  Top-down design is algorithm development approach that involves decomposition of a large problem into manageable parts, that can be solved and unified to form the solution of the overall problem  A module is a self-contained set of steps needed for the solution of problems  In top down-design approach, the problems are divided in a structured chart that are composed of modules.  Abstract step is a step in the algorithm that contains some unspecified details  Concrete step is a step in the algorithm for which there is no need for further specification of details.  Software Development Method is made up of the following implementation strategies: requirement specification, analysis, design, implementation, testing and maintenance.  Stepwise refinement is an algorithm development process that involves providing in each step all the details needed to solve a problem.  Desk checking is the process of simulating the computer execution process by going through the algorithm step-by-step in other to detect and correct errors.  Abstraction is the process of modeling a problem by extracting the relevant information from the problem. Exercises Algorithm questions 1. Write an algorithm to calculate simple interest 2. Write an algorithm to calculate area of triangle 3. Write an algorithm to find the largest of three numbers x, y, z 4. Write an algorithm to test if a given integer value is prime or not Programming questions 5. Write a C program to calculate simple interest 6. Write a C program to calculate area of triangle 7. Write a C program to find the largest of three numbers x, y, z 8. Write a C program to test if a given integer value is prime or not Other questions I will send more question before our next meeting.
  • 21. 21 | P a g e References Government of Andhra Pradesh. (n.d.). Board of Intermediate Education. Retrieved from bieap.gov.in/Pdf/CSPaperII.pdf Institute of Distance & Open Learning (IDOL). (n.d.). University of Mubai. Retrieved from archive.mu.ac.in/myweb_test/syllFybscit/C++.pdf Koffman, J. R. (2016). ProblemSolving and Program Design in C. England: Pearson Education Limited. McQuain. (2011, 12). CS 2104: Introduction to Problem Solving. Retrieved from Computer Science@Virginia Tech: courses.cs.vt.edu/cs2104/Fall12/notes/T16_Algorithms.pdf Nell Dale, John Lewis. (2002). C o m p u t e r Sc i e n c e Illuminated. Singapore: Jones and Bartlett.