Professional Documents
Culture Documents
Int. to Problem Solving With Basic-1
Int. to Problem Solving With Basic-1
Problem Solving with Basic Programming Language NOT FOR SALE Page | 1
1. Introduction to problem-solving in programming
Problem-solving is a critical skill in programming. It involves the ability to analyze a problem,
break it down into smaller components, and create a solution using programming concepts and
techniques. Problem-solving in programming requires a combination of technical knowledge,
creativity, and critical thinking.
The first step in problem-solving is to understand the problem. This may involve reading a
problem statement, analyzing data, or identifying requirements. Once the problem is
understood, the next step is to break it down into smaller components or sub-problems. This
helps to simplify the problem and makes it easier to solve. The next step is to create a solution
using programming concepts and techniques. This may involve writing code, creating
algorithms, or designing data structures. The solution should be tested and refined until it
meets the requirements of the problem. Hence, effective problem-solving in programming
requires a deep understanding of programming languages, data structures, algorithms, and
software design principles. It also requires strong analytical and critical thinking skills, as well
as the ability to work collaboratively and communicate effectively.
In computer science, problem solving refers to the process of finding solutions to problems
using algorithms and programming (i.e. codes). It involves analyzing a problem, identifying
the requirements and constraints, and developing a logical plan of action to solve it.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 2
By following a structured approach to problem-solving, programmers can create effective
solutions that meet the requirements of the problem. Overall, problem solving in computer
science involves using logical thinking and algorithmic approaches to identify, analyze and
solve complex problems efficiently and effectively.
Properties of Algorithm
An algorithm is a set of steps or instructions that are used to solve a problem or perform a
task. Here are some of the properties of algorithms:
1. Clear and Unambiguous: An algorithm must be clear and unambiguous, which means
that it should be easy to understand and there should be no room for confusion or
misinterpretation.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 3
2.Finiteness: An algorithm must terminate after a finite number of steps. It should not
go on indefinitely without producing a result or run indefinitely, which can lead to
resource depletion and system crashes.
3. Input: An algorithm must have zero or more inputs that are given to it before it
begins. The inputs are used by the algorithm to produce the desired output.
4. Output: An algorithm must produce one or more outputs that are the result of the
inputs and the steps performed by the algorithm.
5. Effectiveness: An algorithm must be effective, which means that it must solve the
problem or perform the task it was designed for. It should not produce incorrect or
incomplete results.
6. Generality: An algorithm must be general, which means that it should be applicable to
a wide range of inputs, not just specific cases.
7. Feasibility: An algorithm must be feasible, which means that it should be possible to
implement the algorithm using the available resources, such as time and memory.
8. Optimality: An algorithm should be optimal, which means that it should be designed to
produce the best result with the available resources. An optimal algorithm should have
the least possible time complexity and space complexity.
9. Methodical: An algorithm should be well-organized, with clear logical steps that enable
easy debugging and maintenance.
10. Modularity: An algorithm can be split into smaller, reusable modules, which can be
used in different contexts or applications.
These properties are essential for designing efficient algorithms that can solve problems in
various domains, including computer science, mathematics, engineering, and more.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 4
1. Defining the problem: Before solving a problem, it's essential to define the problem
precisely. Algorithms can help define the problem by breaking it down into smaller,
more manageable parts, allowing for a clearer understanding of what needs to be
solved.
2. Generating solutions: Algorithms can be used to generate solutions to a problem.
They can take input data, apply a series of rules and calculations, and generate an
output that provides a solution.
3. Optimizing solutions: Once a solution has been generated, algorithms can be used to
optimize the solution by tweaking the inputs or adjusting the rules and calculations.
This can lead to a better outcome than the initial solution.
4. Implementation: Algorithms can be used to implement a solution to a problem. They
can be used to write code, build models, or create workflows that solve the problem in
a systematic and efficient way.
5. Automation: Algorithms can automate repetitive tasks, freeing up time for humans to
focus on more complex problem-solving activities.
6. Testing and validation: Algorithms can be used to test and validate solutions to a
problem. By running simulations or applying a set of inputs to the solution, algorithms
can identify potential problems and help refine the solution.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 5
c. Advantages of Flowcharts
1. The flowchart shows the logic of a problem displayed in pictorial fashion which
felicitates easier checking of an algorithm.
2. The Flowchart is good means of communication to other users. It is also a compact
means of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts
can be connected to make master chart.
4. The flowchart is a permanent record of the solution which can be consulted at a later
time.
e. Flow Lines: Flow lines indicate the direction being followed in the
flowchart. In a Flowchart, every line must have an arrow on it to
indicate the direction. The arrows may be in any direction
Problem Solving with Basic Programming Language NOT FOR SALE Page | 6
Example 2: Draw a flowchart to find out the biggest of the three unequal positive numbers.
Example 3: Draw a flowchart for adding the integers from 1 to 100 and to print the sum.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 7
Example 4: Develop a flowchart to illustrate how to make a land phone telephone call
Example 5: ABC company plans to give a 6% year-end bonus to each of its employees
earning N6,000 or more per month , and a fixed N250bonus to the remaining employees. Draw
a flowchart for calculating the bonus for an employee
5.2 Pseudocode
Pseudocode is a high-level, informal language that is used to describe the logic of a computer
program. It is not a specific programming language, but rather a way of writing code that can
Problem Solving with Basic Programming Language NOT FOR SALE Page | 8
be easily understood by both humans and computers. Pseudocode is a valuable tool for
planning and designing computer programs. It allows programmers to focus on the logic and
structure of the program without getting bogged down in the details of a specific programming
language. By using these concepts, you can create effective and efficient pseudocode that
accurately represents the logic of your program.
Here are some key concepts of pseudocode:
1. Statements: Pseudocode is made up of statements that describe the steps of the
program. These statements are similar to those in a programming language, but they
are written in a more natural language.
2. Variables: Pseudocode uses variables to represent data that is used in the program.
Variables can be assigned values and used in calculations and other operations.
3. Expressions: Pseudocode uses expressions to represent calculations and other
operations. These expressions can include variables, constants, and operators.
4. Control Structures: Pseudocode uses control structures such as if-then-else
statements, loops, and functions to control the flow of the program.
5. Comments: Pseudocode includes comments to explain the purpose of certain
statements or to provide additional information about the program.
6. Readable: Pseudocode is designed to be easily readable by humans. It uses natural
language and avoids complex syntax and programming conventions.
7. Translatable: Pseudocode can be translated into actual code in a programming
language. This makes it a useful tool for planning and designing programs before they
are actually coded.
Properties of Pseudocode
Here are some properties of pseudocode:
1. Clarity: Pseudocode must be clear and understandable. It should be written in a way
that can be easily interpreted by anyone who reads it.
2. Simplicity: Pseudocode must be simple and easy to understand. It should not contain
unnecessary details or complex syntax.
3. Flexibility: Pseudocode must be flexible. It should allow for changes and modifications
to be made easily without affecting the overall structure of the program.
4. Readability: Pseudocode must be readable. It should be well-formatted and structured
in a way that is easy to follow.
5. Modularity: Pseudocode must be modular. It should be broken down into smaller,
more manageable parts that can be easily combined to create the final program.
6. Accuracy: Pseudocode must be accurate. It should accurately represent the logic of
the program and the steps that need to be taken to achieve the desired outcome.
By keeping these properties in mind, you can create effective and efficient pseudocode that
accurately represents the logic of your program and is easy to understand and modify.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 9
3. Algorithm: An algorithm is a step-by-step description of a process. It is a set of
instructions that can be followed to solve a particular problem or perform a specific
task. Algorithms are often used in programming to solve complex problems and are the
foundation of computer programming.
This algorithm takes the base and height of the triangle as input and calculates the area using
the formula A = 0.5 * b * h. The result is then outputted to the user. This algorithm assumes
that the input values are valid and that the base and height are both measured in the same
unit (e.g. meters, inches, etc.).
Note that this algorithm can be implemented in any programming language by using the
appropriate syntax for input, output, and arithmetic operations.
The flowchart starts with the "Start" symbol and then proceeds to the next step, which is to
input the base of the triangle (b). From there, it proceeds to the next step to input the height
of the triangle (h). The flowchart then calculates the area of the triangle using the formula:
area = 0.5 * b * h. The result is outputted to the user and the flowchart ends with the "End"
symbol.
This flowchart is a visual representation of the algorithm described in the previous answer. It
shows the flow of data and the steps involved in computing the area of a triangle. Note that
this flowchart can be implemented in any programming language by using the appropriate
syntax for input, output, and arithmetic operations.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 10
Input base of triangle (b)
Input height of triangle (h)
area = 0.5 * b * h
Output area
End
This pseudocode starts with the "Begin" keyword and then proceeds to the next step to input
the base of the triangle (b). From there, it proceeds to the next step to input the height of the
triangle (h). The pseudocode then calculates the area of the triangle using the formula: area =
0.5 * b * h. The result is outputted to the user and the pseudocode ends with the "End"
keyword.
This algorithm takes the values of a, b, and c as input and calculates the roots of the quadratic
equation using the discriminant formula, which is d = b^2 - 4ac. If the discriminant is
negative, the roots are imaginary and a message is displayed to the user. If the discriminant is
zero, there is only one real root and it is calculated using the formula -b/2a. If the discriminant
is positive, there are two real roots and they are calculated using the quadratic formula. The
roots are then displayed to the user.
Note: This algorithm can be implemented in any programming language by using the
appropriate syntax for input, output, and arithmetic operations.
This flowchart starts with the "Start" symbol and then proceeds to the next step to input the
coefficients a, b, and c of the quadratic equation. From there, it calculates the discriminant
Problem Solving with Basic Programming Language NOT FOR SALE Page | 11
using the formula d = b^2 - 4ac. The flowchart then checks if the discriminant is negative,
zero, or positive using an "If" statement.
If the discriminant is negative, the flowchart displays a message "Roots are imaginary". If the
discriminant is zero, the flowchart calculates the root using the formula r = -b/2a and displays
"Root is" followed by the value of the root. If the discriminant is positive, the flowchart
calculates the roots using the quadratic formula and displays "Roots are" followed by the
values of the roots.
This flowchart is a visual representation of the algorithm described in the previous answer. It
shows the flow of data and the steps involved in finding the roots of a quadratic equation. Note
that this flowchart can be implemented in any programming language by using the appropriate
syntax for input, output, and arithmetic operations.
7. Program Objects
In computer science, a program object refers to a self-contained unit of code that encapsulates
data and behavior. It is an instance of a program or module that can be executed within a
larger program or system. Programming objects involves creating software objects that
interact with one another to perform specific tasks or solve problems. These objects are
defined by classes, which are blueprints for creating instances of objects with specific
properties and behaviors. In object-oriented programming, objects can communicate with one
another through methods, which are functions that belong to a particular object. These
methods can access and manipulate the properties of the object, as well as communicate with
other objects.
Program objects can be created using various programming paradigms such as procedural
programming, object-oriented programming, or functional programming. In object-oriented
programming, program objects are typically instances of classes, which define the behavior
Problem Solving with Basic Programming Language NOT FOR SALE Page | 12
and attributes of the object. Program objects can communicate with each other and exchange
data through methods, functions, and interfaces. They can also be used to implement
abstraction and encapsulation, which are important concepts in software engineering that
enable modular design and code reuse.
Problem Solving with Basic Programming Language NOT FOR SALE Page | 13