0% found this document useful (0 votes)
48 views23 pages

Unit 2

The document discusses the steps involved in problem solving using computers. It explains that the programmer must write the solution to the problem in a way the computer can understand by breaking it down into simple operations. There are 7 main steps to solving a problem with a computer program: 1) problem analysis, 2) design including creating an algorithm and flowchart, 3) coding, 4) compilation and execution, 5) debugging and testing, 6) implementation and maintenance, and 7) program documentation. It provides examples of algorithms and flowcharts to solve problems such as calculating the sum of two numbers, finding the largest of three numbers, and calculating simple interest.

Uploaded by

Niranjan Tamang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
48 views23 pages

Unit 2

The document discusses the steps involved in problem solving using computers. It explains that the programmer must write the solution to the problem in a way the computer can understand by breaking it down into simple operations. There are 7 main steps to solving a problem with a computer program: 1) problem analysis, 2) design including creating an algorithm and flowchart, 3) coding, 4) compilation and execution, 5) debugging and testing, 6) implementation and maintenance, and 7) program documentation. It provides examples of algorithms and flowcharts to solve problems such as calculating the sum of two numbers, finding the largest of three numbers, and calculating simple interest.

Uploaded by

Niranjan Tamang
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 23

Unit 2

Problem Solving using Computer


Steps Involved in Problem Solving:
A computer cannot solve a problem on its own. One has to provide step by step solutions
of the problem to the computer.
In fact, the task of problem solving is not that of the computer. It is the programmer who
has to write down the solution to the problem in terms of simple operations which the
computer can understand and execute.
In order to solve a problem by the computer, one has to pass though certain stages or
steps. They are
1. Problem Analysis
2. Design(Algorithm and flow chart)
3. Coding
4. Compilation and Execution
5. Debugging and Testing
6. Implementation and maintenance
7. Program Documentation
1. Problem Analysis:
This step is the process of becoming familiar with the problem that will be solved with
computer program. We need to analyze and understand the problem in depth before
solving it. Analyzing the problem requires us to identify the program inputs, outputs, its
conditions, any equation or formula to be used, software and hardware requirements,
time constraints, etc.

For example, Compute the average marks obtained by students in ”Computer-Programming”.


Inputs: Marks of individual students
Outputs: The average mark of students
Formula: Average=Total Marks / No of students
i.e. A = T/N

Compiled By: Er. Ram Chandra Aryal 1


1.1 Feasibility Study:
A feasibility study is an evaluation and analysis of a project or system that somebody
has proposed. We also call it a feasibility analysis. The study tries to determine whether
the project is technically and financially feasible, i.e., is it technically or financially viable?
Financially feasible, in this context, means whether the project is feasible within the
estimated cost.
There are mainly five types of feasibilities checks:
• Economic: Can we complete the project within the budget or not?
• Legal: Can we handle this project as cyber law and other regulatory
framework/compliances?
• Operation feasibility: Can we create operations which is expected by the client?
• Technical: Need to check whether the current computer system can support the
software
• Schedule: Decide that the project can be completed within the given schedule or not.

1.2 Requirement analysis:


Requirements analysis, also called requirements engineering, is the process of
determining user expectations for a new or modified product. These features, called
requirements, must be quantifiable, relevant and detailed.
Includes the following tasks:
a. Identify and express system requirements(Identify functional and non-functional
requirements
• Functional: inputs, outputs, processes, stored data
• Non-Functional: performance, Budget, costs, time tables, training needs, quality and
security
b. Prioritize system requirements
c. Update or refine the project plan
d. Communicate the requirements statement

Compiled By: Er. Ram Chandra Aryal 2


2. Design (Algorithm and Flow chart):

2.1 Algorithm:
• An algorithm can be defined as complete, unambiguous and finite number of
steps for solving a given problem.
• Simply, it is the step by step description of the method to solve a problem.
• Developing an algorithm is a step of program design.

The characteristics of Algorithm are:


1. Input: One or more quantities are externally supplied for processing which is
known as inputs
2. Output: After inputs are processed, they must produce at least one quantities as
output
3. Unambiguous: Each instruction in algorithm must be clear. It should not have
double meaning.
4. Finiteness: the algorithm should terminate after a finite number of steps.
5. Effectiveness: Must be developed using basic operation so that it can be
implemented effectively
Some conventions used in developing algorithm:
• Each algorithm must be enclosed by two statements START and STOP
• To accept data from user, INPUT or READ statement is used.
• To display any message, the OUTPUT, PRINT or DISPLAY statement is used.
• The arithmetic operators (+,-,* and /) are used in the arithmetic expression.
• The relational operators (>,>=,<=,==,>,<,!=) are used in relational expression.
• The logical operators (AND, OR, NOT) are used in logical expression.
Advantages of algorithm:
• It is a step-wise representation of a solution to a given problem, which makes it
easy to understand.
Compiled By: Er. Ram Chandra Aryal 3
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to understand
for anyone even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy to debug.
• By using algorithm, the problem is broken down into smaller pieces or steps
hence, it is easier for programmer to convert it into an actual program

Disadvantages of algorithm.
• Writing algorithm takes a long time.
• An Algorithm is not a computer program; it is rather a concept of how a program
should be.

Example:
Write an algorithm to find the sum of two numbers entered by user.
Step 1: Start
Step 2: Declare variables A, B, SUM
Step 3: Input two numbers A and B
Step 4: SUM = A + B
Step 5: Print SUM
Step 6: Stop

2.2 Flowchart:
• Flow chart is a pictorial (diagrammatic) representation of the procedure for solving a
problem and help a great deal to analyze the problem and plan its solution in a systemic
and orderly manner. A flow chart includes a set of various Standard shaped boxes that
are interconnected by flow lines.
• Simply it is graphical representation of an algorithm.
• Flowchart facilitate communicates between programmers and business persons.
Flowchart helps in explaining the program to others. Once a flowchart is drawn, it become
easy to write the program in any high level language. A flowchart when translated in to a
proper computer language, results in a complete program.
Compiled By: Er. Ram Chandra Aryal 4
Flowchart symbols and their meanings:

Flowchart Structures:

Fig. Sequential Structure Fig. Conditional Structure Fig. Loop Structure

Advantages of Flowchart:
• Flowchart provides a clear overview of the entire problem.
• It serves as a guide for program coding.
• It is a convenient method of communication.
Compiled By: Er. Ram Chandra Aryal 5
• It helps during error detection and removal.
• It is an important tool for planning and designing a new system.
• It can be used for effective analysis of the problem.

Disadvantages of flowchart:
• The flowchart can be complex when the logic of a program is quite complicated.

• Drawing flow chart is a time-consuming task.

• Difficult to alter the flowchart. Sometimes, the designer needs to redraw the
complete flowchart to change the logic of the flowchart or to alter the flowchart.
• Since it uses special sets of symbols for every action, it is quite a tedious task to
develop a flowchart as it requires special tools to draw the necessary symbols.
• In the ease of a complex flowchart, other programmers might have a difficult time
understanding the logic and process of the flowchart.
• It is just a visualization of a program; it cannot function like an actual program.

Example:
Draw a flowchart to find the sum of two numbers entered by user.

Sum = Numberl + Nuinber2

End Fig. Flowchart of sum of two numbers

Compiled By: Er. Ram Chandra Aryal 6


Example 1: Write an algorithm and draw a flowchart to calculate the simple
interest
Algorithm:
Step 1: Start
Step 2: Declare variables Principal Amount P, Time T, rate R and
Simple Interest SI.
Step 3: Read P, T and R
Step 4: SI= (P*T*R) /100
Step 6: Print SI
Step 7: Stop

Flowchart:

Fig. flowchart of Simple interest

Compiled By: Er. Ram Chandra Aryal 7


Example 2: Write an algorithm and draw a flowchart to find the greatest
number among the 2 numbers
Algorithm:
Step 1: Start
Step 2: Declare variables A and B
Step 3: Read number A and B
Step 4: Now check the condition
if A> B
print A is greater
else
print B is greater
Step 5: Stop
Flowchart:

Compiled By: Er. Ram Chandra Aryal 8


Example 3: Write an algorithm and draw a flowchart to find the largest among
three entered numbers

Algorithm:
Step 1: Start
Step 2: Declare variables A, B and C
Step 3: Read A, B and C
Step 4: if A>B
if A>C
print A is greater
else
print C is greater
else
if B>C
print B is greater
else
print C is greater
Step 5: Stop

Compiled By: Er. Ram Chandra Aryal 9


Flowchart:

Fig. Flowchart of greater (largest) among three numbers

Compiled By: Er. Ram Chandra Aryal 10


Example 3: Write an algorithm and draw a flowchart to calculate the root of the
Quadratic equation
Algorithm:
Step 1: start
Step 2: Declare a, b, c, r1, r2, r and d
Step 2: Read a, b and c
Step 3: Calculate Discriminant d
d= b²-4ac
Step 4: if d>0
r1=(-b+sqrt(d))/2a
r2=(-b-sqrt(d))/2a
print real roots r1 and r2
else if d==0
r=r1=r2=-b/2a
print roots are equal which are r
else
print roots are imaginary
Step 5: stop

Compiled By: Er. Ram Chandra Aryal 11


Flowchart:

Compiled By: Er. Ram Chandra Aryal 12


3. Coding:
• The process of transforming the program logic design into computer language
format. Coding is the real job of programmer.
• The algorithm to solve a problem which is described by pseudo-code or flow chart is
converted into actual programming language code.
• It is an act of transforming operations in each box of the flowchart in terms of the
statement of the program.
• The code written by programmer by using any programming language like C is called
the source code or source program.

Example: WAP to find the sum of two numbers entered by user.


Program Code:
#include<stdio.h>
int main()
{
int Num1, Num2, Sum;
printf("Enter two numbers");
scanf("%d%d",&Num1,&Num2);
Sum=Num1+Num2;
printf("Sum=%d", Sum);
return 0;
}

Compiled By: Er. Ram Chandra Aryal 13


Pseudo code:
A Pseudo code is defined as a step-by-step description of an algorithm. Pseudo code does
not use any programming language in its representation instead it uses the simple English
language text as it is intended for human understanding rather than machine reading.
Pseudo code is the intermediate state between an idea and its implementation (code) in
a high-level language.

Fig Pseudo code is an intermediate state between algorithm and program

• Often at times, algorithms are represented with the help of pseudo codes as
they can be interpreted by programmers no matter what their programming
background or knowledge is.
• Pseudo code, as the name suggests, is a false code or a representation of code
which can be understood by even a layman with some school level programming
knowledge.

Advantage:

• Acts as a bridge between the program and the algorithm or flowchart. Also works as
a rough documentation, so the program of one developer can be understood easily
when a pseudo code is written out. In industries, the approach of documentation is
essential. And that's where a pseudo- code proves vital.
• The main goal of a pseudo code is to explain what exactly each line of a program
should do, hence making the code construction phase easier for the programmer.

Disadvantage

• Pseudo code does not provide a visual representation of the logic of programming.
• There is no proper format for writing the for pseudo code.
• In Pseudo code there is extra need of maintain documentation.
• In Pseudo code there is no proper standard very company follow their own standard
for writing the pseudo code.

Compiled By: Er. Ram Chandra Aryal 14


Example 1: Write pseudo code to find the sum of two numbers entered by user.

Input Number 1, Number2;

Sum=Number1+Number2

Print Sum

Example 2: Write pseudo code to check if the user entered number is odd or even
num: INPUT "Enter a number"

IF num MOD 2 ==0

print "Even Number"

ELSE

print "Odd Number"

We can also write pseudo code in this way:


Pseudo code Example to Calculate the Area of a Rectangle
BEGIN
length = INPUT: "Enter the length of the rectangle"

width = INPUT: "Enter the width of the rectangle"

area = length * width

OUTPUT area
END

Compiled By: Er. Ram Chandra Aryal 15


4. Compilation and Execution:

• The source code written in any programming language is not directly executed by the
computer.
• It should be translated into to the machine readable format i.e. actual machine
language.
• The process of translation of source code into the target code is called the
compilation.
• Each programming language has its own compiler program that translates the source
code into its target code.
• The compilation process tests the program whether it contains syntax errors or not.
• If syntax errors are present, compiler cannot compile the code.
• Once the compilation is completed then the program is linked with other object
programs needed for execution, there by resulting in a binary program and then the
program is loaded in the memory for the purpose of execution and finally it is
executed.

5. Debugging and testing:

Debugging:

• Debugging is the discovery and correction of programming errors, when error


appears debugging is necessary.
• Written program may have errors, some errors can be detected by compiler and
some errors cannot identified by the compiler and occurred during the program run.
Some common types of errors are:
• Syntax Errors
• Logical Errors
• Runtime Errors

Compiled By: Er. Ram Chandra Aryal 16


Syntax Error:
A syntax error is an error in the syntax of a coding or programming language, entered
by a programmer. Syntax errors are caught by a software program called a compiler,
and the programmer must fix them before the program is compiled and then run.

Logical Errors:
A logical error is an error in a program’s source code that gives way to an unanticipated
and erroneous behavior. A logical error is classified as a type of runtime error that can
result in a program producing incorrect output.

Runtime Errors:
A Runtime Error is an error that occurs at the time of running or executing a program.
When this error occurs, the program may hang or crash displaying an error message.
There are many reasons for a runtime error, like when the program enters an infinite
loop, it triggers the runtime error. Sometimes, it also occurs due to the user’s fault. A
typical runtime error is a division by zero error.

Testing:

• Testing is a process of identifying defects in the software product. It is performed


to validate the behavior of the software or the application compared to requirements.
• In other words, we can say that the testing is a collection of techniques to determine the
accuracy of the application under the predefined specification but, it cannot identify all
the defects of the software.
• Each software or application needs to be tested before delivering to the clients and
checks whether the particular software or the application is working fine as per the
given requirements.
Some Types of software testing are:
• Unit Testing
• Integration Testing
• Alpha Testing
• Beta Testing
• Acceptance Testing etc.

Compiled By: Er. Ram Chandra Aryal 17


Unit testing:
Unit testing is a method of testing individual units or components of a software
application. It is typically done by developers and is used to ensure that the
individual units of the software are working as intended. Unit tests are usually
automated and are designed to test specific parts of the code, such as a particular
function or method. Some popular frameworks and tools that are used for unit
testing include JUnit, NUnit, and xUnit.

Integration Testing:
Integration testing is a method of testing how different units or components of a
software application interact with each other. It is used to identify and resolve any
issues that may arise when different units of the software are combined. Integration
testing is typically done after unit testing and before functional testing, and is used
to verify that the different units of the software work together as intended.
Integration testing is of four types:
(i) Top-down (ii) Bottom-up (iii) Sandwich (iv) Big-Bang

Alpha Testing:
This is a type of validation testing. It is a type of acceptance testing which is done
before the product is released to customers. It is typically done by QA people.
Example:
When software testing is performed internally within the organization.

Beta Testing:
The beta test is conducted at one or more customer sites by the end-user of the
software. This version is released for a limited number of users for testing in a real-
time environment.
Example:
When software testing is performed for the limited number of people.

Acceptance Testing:
Acceptance testing is done by the customers to check whether the delivered
products perform the desired tasks or not, as stated in requirements.

Compiled By: Er. Ram Chandra Aryal 18


6. Implementation and maintenance:
• Maintenance includes all the activities after the installation/implementation of
software that is performed to keep the system operation.
• There are some issues like changes in UI, functionality, bugs etc. which come up in the
client environment after the software is installed. To fix those issues, several versions
are released.
• Software Maintenance is the process of modifying a software product after it has
been delivered to the customer. The main purpose of software maintenance is to
modify and update software applications after delivery to correct faults and to improve
performance.

Need for Maintenance:


Software Maintenance must be performed in order to:
• Correct faults.
• Improve the design.
• Implement enhancements.
• Interface with other systems.
• Accommodate programs so that different hardware, software, system features, and
telecommunications facilities can be used.

Maintenance can be divided into the following:


i. Corrective maintenance:
Corrective maintenance of a software product may be essential either to rectify some
bugs observed while the system is in use, or to enhance the performance of the system
ii. Adaptive maintenance:
This includes modifications and updations when the customers need the product to run
on new platforms, on new operating systems, or when they need the product to interface
with new hardware and software.
iii. Perfective maintenance
A software product needs maintenance to support the new features that the users want
or to change different types of functionalities of the system according to the customer
demands.

Compiled By: Er. Ram Chandra Aryal 19


iv. Preventive maintenance
This type of maintenance includes modifications and updations to prevent future
problems of the software. It goals to attend problems, which are not significant at this
moment but may cause serious issues in future. This involves taking measures to prevent
future problems, such as updating documentation, reviewing and testing the system,
and implementing preventive measures such as backups.

7. Program Documentation:

• From the start of the problem solving to the end of the implementation of the
program, all the tasks should be documented i.e. kept for future reference. A program
may be difficult to understand even to programmer who wrote the code after some
days.
• It is also the important part of the problem solving or program development. It helps
to those who use, maintain and extend the program in future.
• Properly documented program is necessary which will be useful and efficient in
debugging, testing, maintenance and redesign process.
Documentation may be of two types:
a. Technical document known as programmers documents which includes the problem
analysis to implementation details for that program. It is needed for future reference
for any modification, update of the program. Documentation may be in the form of
pseudo code, flowchart, E-R diagram and other standard UML diagram etc.
b. User document also known as User manual is the documentation prepared for the
end-user of the program that guides the user how to operate the program.
Documentation may include the instructions for installation of program, instruction
for using its functionality etc.

Compiled By: Er. Ram Chandra Aryal 20


Some Examples of Algorithm and flowchart:
1. Write an algorithm and draw a flowchart of area of circle:

Algorithm:
Step 1: Start
Step 2: Declare variables radius and area
Step 3: Read the radius of the circle
Step 4: Compute the Area as per the formula.
Area=3.14*radius*radius
Step 5: Print the area of the circle
Step 6: Stop

Fig. Flowchart of area of Circle

Compiled By: Er. Ram Chandra Aryal 21


2. Write an algorithm and draw a flowchart to check whether a entered
number is even or odd
Algorithm:
Step 1: start
Step 2: Read a number N
Step3: calculate r=N%2
Step 4: if remainder r==0
print N is even
else
print N is Odd
Step 4: stop

Flowchart:

Compiled By: Er. Ram Chandra Aryal 22


3. Write an algorithm and draw a flow chart to find the sum of first 50
numbers.
Algorithm:
Step 1: start
Step 2: Declare variables N, sum and initialize as sum=0 and N=0
Step 3: Increase N by 1
Step 4: calculate sum as
sum= sum + N
Step 5: if N<=50 then
goto step 3
else
print sum
Step 6: stop
Flowchart:

Compiled By: Er. Ram Chandra Aryal 23

You might also like