Applied Chapter2
Applied Chapter2
BCT/BEL I/I
Chapter-2:
Problems Solving Using Computer
Problem Solving using Computer
• Problem solving is the process of transforming the description of a problem into a solution by using our knowledge
of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies,
techniques and tools.
• Programming is a problem solving activity. When we write a program, we are actually writing an instruction for the
computer to solve something for us.
1. Problem Definition
A clearly defined problem is already half the solution. Computer programming requires us to define the problem first
before we even try to create a solution.
2. Problem Analysis:
• Input(s) to the problem, their form and the input media to be used
• Output(s) expected from the problem, their form and the output media to be used
3.Coding: 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. The code written by programmer
by using any programming language like C is called the source code or source program.
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 converted program in actual
machine language is then executed by the computer which is known as program execution.
Problem Solving using Computer
5.Debugging and Testing: A written program may have errors, some errors can be detected by the
language compilers and some errors can not be identified by the compiler and occured during the program run.
Common types of errors are
Syntax Errors: Identified by compiler at the program compilation time.
Logical Errors: Not identified by the compiler at compile time and identified at the execution time. e.g. misuse of
operators
So testing is the process of checking the program for its correct functionality by executing the program with
some
input data set and observing the output of the program.
6.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. It is also the important part of the problem solving
or program development. Documentation may be of two types
Technical Documentation known as programmer's documentations which includes the problem analysis to
implementation details for that program. It is needed for future reference for any modification, update of
the program.
User manual is the documentation prepared for the end-user of the program that guides the user how to
operate the program.
Algorithm
1. Start
2. Input the the value of radius R
3. Let PI=3.14
4. Calculate area=PI*R*R
5. Print area
6. End
Algorithm Example(3)
Step 1: Start
Step 2: Declare a variable sum with value 0.
Step 3: Get sum of all the values in sum variable using
loop. Step 4: Divide sum by 6 and assign it to avg variable.
Step 5: Print avg
Step 6: End
Pseudo-Code
• The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows.
• Ensure that flowchart has START (or BEGIN) and STOP (or END).
• Flowchart should be neat, clean and easy to follow. There should be no any ambiguity.
• The usual direction of flowchart is from top to bottom or from left to right.
• The terminal symbol, that is, START/BEGIN or STOP/END should have only one flow
line.
Guidelines for Preparing Flowchart
• Only one flow line should come out from process symbol.
• Only one flow line should enter a decision symbol, but two or three flow-lines, one for each
possible answer, can leave the decision symbol.
• If the flowchart is lengthy and complex connector symbol should be used to reduce the
number of flow lines.
Advantages of Flowchart:
•Flowcharts are a better way of communicating the logic of the system.
•Flowcharts act as a guide for blueprint during program designed.
•Flowcharts help in debugging process.
•With the help of flowcharts programs can be easily analyzed.
•It provides better documentation.
•Flowcharts serve as a good proper documentation.
Disadvantages of Flowchart:
•It is difficult to draw flowcharts for large and complex programs.
•There is no standard to determine the amount of detail.
•Difficult to reproduce the flowcharts.
•It is very difficult to modify the Flowchart.
Flowchart vs Algorithm
Create a program to compute the volume of a sphere.
Write a program the converts the input Celsius degree
into its equivalent Fahrenheit degree.
Write a program that exchanges the value of two
variables: x and y.
Errors In Program
• Errors are the problems or the faults that occur in the program, which makes the behavior of the
program abnormal, and experienced developers can also make these faults.
• Programming errors are also known as the bugs or faults, and the process of removing these bugs
is known as debugging.
• These errors are detected either during the time of compilation or execution.
• Thus, the errors must be removed from the program for the successful execution of the program.
Types of Errors
Syntax Error
Syntax errors are also known as the
compilation errors as they occurred at
the compilation time, or we can say
that the syntax errors are thrown by the
compilers. These errors are mainly
occurred due to the mistakes while
typing or do not follow the syntax of
the specified programming language.
These mistakes are generally made by
beginners only because they are new
to the language. These errors can be
easily debugged or corrected.
Runtime Error
• Compile-time and Runtime are the two programming terms used in the software development.
• Compile-time is the time at which the source code is converted into an executable code while the
run
time is the time at which the executable code is started running.