0% found this document useful (0 votes)
27 views13 pages

Unit 2

Chapter 2 discusses problem-solving using computers, emphasizing the importance of clearly defining problems and developing step-by-step methods to solve them. Key stages in problem-solving include problem analysis, algorithm development, flowcharting, coding, compilation, debugging, and documentation. The chapter also highlights the advantages and disadvantages of algorithms and flowcharts, as well as the significance of proper documentation for future maintenance and understanding of programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views13 pages

Unit 2

Chapter 2 discusses problem-solving using computers, emphasizing the importance of clearly defining problems and developing step-by-step methods to solve them. Key stages in problem-solving include problem analysis, algorithm development, flowcharting, coding, compilation, debugging, and documentation. The chapter also highlights the advantages and disadvantages of algorithms and flowcharts, as well as the significance of proper documentation for future maintenance and understanding of programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Chapter 2

Problem Solving using Computer

A computer is a very powerful and versatile machine capable of performing a


multitude of different tasks. A computer performs many tasks exactly in the same
manner as it is programmed.

In order to instruct a computer correctly, the user must have clear understanding of
the problem to be solved. A part from this he should be able to develop a method,
in the form of series of sequential steps, to solve it. Once the problem is well-
defined and a method of solving it is developed, then instructing the computer to
solve the problem becomes relatively easier task.

Thus, before attempt to write a computer program to solve a given problem. It is


necessary to formulate or define the problem in a precise manner. Once the
problem is defined, the steps required to solve it, must be stated clearly in the
required order

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. Algorithm Development

3. Flowcharting

4. Coding
5. Compilation and Execution

6. Debugging and Testing

7. Documentation
1. Problem Analysis

• Process of becoming familiar with the problem.

• We need to analyze and understand it well before solving.

• The user’s requirements cannot be fulfilled without clear understanding of


his/her problem in depth.

• Inadequate identification of problem may cause program less useful and


insufficient.

• Example: Banking Solution, Hospital Medical Study

2. Algorithm Development

• An algorithm can be defined as “a complete, unambiguous, finite


number of logical steps for solving a specific problem”
• Step By Step description of the method to solve a problem.
• Effective procedure for solving a problem in finite number of
steps.
• Developing an algorithm is a step of program design.

Advantages of algorithm

1. It is a step-wise representation of a solution to a given problem, which


makes it easy to understand.

2. An algorithm uses a definite procedure.

3. It is not dependent on any programming language, so it is easy to understand


for anyone even without programming knowledge.

4. Every step in an algorithm has its own logical sequence so it is easy to


debug.

5. 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.

1. Writing algorithm takes a long time.

2. An Algorithm is not a computer program, it is rather a concept of how


a program should be.

Q. An algorithm to find sum of two numbers

Step 1: Start

Step 2: Declare variables num1, num2 and sum.

Step 3: Read values num1 and num2.

Step 4: Add num1 and num2 and assign the result to sum.

Sum=num1+num2

Step 5: Display sum

Step 6: Stop

Q. Write an algorithm to calculate the simple interest using the formula.

Step 1: Start

Step 2: Read the three input quantities P, N and R.

Step 3 : Calculate simple interest as Simple interest = P* N* R/100

Step 4: Print simple interest.

Step 5: Stop.

Q. Write an algorithm to print from 1 to 20

Step 1: Start
Step 2: Initialize X as 1,

Step 3: Print X

Step 4: Increment X by 1

Step 5: If X <= 20 then

go back to step 3

Else

Go to step 6

Step 6: Stop

Q. Write an algorithm and draw a flow chart to find whether a number even
or odd

3. Flowcharting

A flow chart is a step by step diagrammatic representation of the logic paths to


solve a given problem. Or A flowchart is visual or graphical representation of an
algorithm. The flowcharts are pictorial representation of the methods to b used to
solve a given problem and help a great deal to analyze the problem and plan its
solution in a systematic and orderly manner. A flowchart when translated in to a
proper computer language, results in a complete program.

• Graphical representation of an algorithm using standard symbols.

• Includes a set of various standard shaped boxes that are interconnected by


flow lines.
• Flow lines have arrows (direction of flow).

• Activities are written within boxes in English.

• Communicates between programmers and business persons.

Advantages of Flowcharts

• Communication

– Quickly provide logic, ideas and descriptions of algorithms.

• Effective Analysis

– Clear overview of the entire problem.

• Proper Documentation

– Documents the steps followed in an algorithm.

– Helps us understand its logic in future.

• Efficient Coding

– More ease with comprehensive flowchart as a guide

• Easy in debugging and program maintenance

– Debugging and maintenance of operating program

Disadvantages of flowchart

1. The flowchart can be complex when the logic of a program is quite


complicated.

2. Drawing flowchart is a time-consuming task.

3. 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.
4. 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.

5. In the case of a complex flowchart, other programmers might have a difficult


time understanding the logic and process of the flowchart.

6. It is just a visualization of a program, it cannot function like an actual


program.

Flowchart Symbols

The symbols that we make use while drawing flowcharts as given below are as per
conventions followed by International Standard Organization (ISO).

a. Oval: Rectangle with rounded sides is used to indicate either START/STOP of


the program.

b. Input and output indicators: Parallelograms are used to represent input and
output operations. Statements like INPUT, READ and PRINT are represented in
these Parallelograms.

c. Process Indicators: - Rectangle is used to indicate any set of processing


operation such as for storing arithmetic operations.
d. Decision Makers: The diamond is used for indicating the step of decision
making and therefore known as decision box. Decision boxes are used to test the
conditions or ask questions and depending upon the answers, the appropriate
actions are taken by the computer. The decision box symbol is

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

f. On- Page connectors: Circles are used to join the different parts of a flowchart
and these circles are called on-page connectors. The uses of these connectors give
a neat shape to the flowcharts. Ina complicated problems, a flowchart may run in to
several pages. The parts of the flowchart on different pages are to be joined with
each other. The parts to be joined are indicated by the circle.

g. Off-page connectors: This connector represents a break in the path of flowchart


which is too large to fit on a single page. It is similar to on-page connector. The
connector symbol marks here the algorithm ends on the first page and where it
continues on the second.

Points to remember

• There should be start and stop to the flowchart.

• Only one flow line should emerge from a process symbol.


• Only one flow line should enter a decision symbol, but two or three flow
lines can leave the decision symbol.

Flowchart to convert Fahrenheit to Celsius


Flowchart to *Print 1 to 20:
ABC company plans to give a 6% year-end bonus to each of its employees earning Rs 6,000 or
more per month , and a fixed Rs 250/- - bonus to the remaining employees. Draw a flowchart for
calculating the bonus for an employee

4. Coding
• The process of transforming the program logic design into computer language
format.
• An act of transforming operations in each box of the flowchart in terms of the
statement of the program.
• The code written using programming language is also known as source code.
• Coding isn’t the only task to be done to solve a problem using computer.
5. Compilation and Execution
• Process of changing high level language into machine level language.
• It is done by special software, COMPILER
• 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.
• The program may ask user for inputs and generates outputs after processing the
inputs.

6. Debugging and Testing


• Debugging is the discovery and correction of programming errors.
• Some errors may remain in the program because the designer/programmer might
have never thought about a particular case.
• When error appears debugging is necessary.
Testing ensures that program performs correctly the required task.
• Verification ensures that program does what the programmer intends to do.
• Validation ensures that the program produces the correct results for a set of test
data.
• Test data are supplied to the program and output is observed.
• Expected output = Error free

7. Program Documentation
• Helps to those who use, maintain and extend the program in future.
• A program may be difficult to understand even to programmer who wrote the
code after some
days.
• Properly documented program is necessary which will be useful and efficient in
debugging,
testing, maintenance and redesign process.

Two types of documentations


1. Programmer’s Documentation (Technical Documentation)
• Maintain, redesign and upgrade
• Logic, DFD, E-R, algorithm and flowchart
2. User Documentation (User Manual)
• Support to the user of the program
• Instructions for installation of the program
Differences between Algorithm and Flowchart

You might also like