0% found this document useful (0 votes)
29 views35 pages

Applied Chapter2

The document discusses problem solving using computers. It explains that a computer is a tool to solve problems and programming involves writing instructions to solve problems. It then outlines the typical steps in problem solving using computers which include problem definition, analysis, coding, compilation, debugging, testing, and documentation.

Uploaded by

work
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views35 pages

Applied Chapter2

The document discusses problem solving using computers. It explains that a computer is a tool to solve problems and programming involves writing instructions to solve problems. It then outlines the typical steps in problem solving using computers which include problem definition, analysis, coding, compilation, debugging, testing, and documentation.

Uploaded by

work
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Computer Programming

BCT/BEL I/I
Chapter-2:
Problems Solving Using Computer
Problem Solving using Computer

• A computer is a tool to solve a problem.

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

• Using a computer as a problem solving tool following steps are involved:


Problem Solving using Computer

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:

Analysing the problem require us to identify the following:

• 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

• Special constraints or conditions (if any)

• Any formulas or equations to be used


Problem Solving using Computer

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

 The word “algorithm” which means a procedure or a technique.


 An algorithm is a sequence of steps to solve a particular problem or algorithm is an ordered set of
unambiguous steps that produces a result and terminates in a finite time.
 Algorithm has the following characteristics
• Input: An algorithm may or may not require input
• Output: Each algorithm is expected to produce at least one result
• Definiteness: Each instruction must be clear and unambiguous.
• Finiteness: If the instructions of an algorithm are executed, the algorithm should terminate after finite
number of steps
Algorithm Example(1)

Write an algorithm to add two numbers entered by user.


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
Algorithm Example(2)
Write an algorithm to find the area of Circle
.

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)

Write an algorithm to find the average of 6 subjects.

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

• Pseudocode is an informal way of writing a program. It is not exactly a computer


program.

• It represents the algorithm of the program in natural language and mathematical


notations.

• Usually, there is no particular code syntax to write a pseudocode.


Pseudo-Code(1)
Pseudo-Code(2)
Flow chart

• A flowchart is a type of diagram that represents an algorithm, workflow or process.

• The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows.

• This diagrammatic representation illustrates a solution model to a given problem.


Flow Chart Symbols
Guidelines for Preparing Flowchart

• Standard symbols should be used while drawing flowchart.

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

• Avoid intersection of flow lines.

• Use annotation symbol to describe steps more clearly.


Flowchart(1)

Draw a flowchart to find the sum of two numbers


Flowchart(2)

Draw a flowchart to convert temperature from Fahrenheit to Celsius


Flowchart(3)

Draw a flowchart to find Area and Perimeter of Square


Flowchart(4)

Draw a flowchart to find the smallest of two numbers


Flowchart

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

Sometimes the errors exist during the


execution-time even after the
successful compilation known as run-
time errors. When the program is
running, and it is not able to perform
the operation is the main cause of the
run-time error. The division by zero is
the common example of the run-time
error. These errors are very difficult to
find, as the compiler does not point to
these errors.
Linker Error
Linker errors are mainly generated when the
executable file of the program is not created.
This can be happened either due to the wrong
function prototyping or usage of the wrong
header file. For example, the main.c file
contains the sub() function whose declaration
and definition is done in some other file such
as func.c. During the compilation, the compiler
finds the sub() function in func.c file, so it
generates two object files,
i.e., main.o and func.o. At the execution time, if
the definition of sub() function is not found in
the func.o file, then the linker error will be
thrown. The most common linker error that
occurs is that we use Main() instead of main().
Logical Errors

The logical error is an error that leads


to an undesired output. These errors
produce the incorrect output, but they
are error-free, known as logical errors.
These types of mistakes are mainly
done by beginners. The occurrence of
these errors mainly depends upon the
logical thinking of the developer. If the
programmers sound logically good,
then there will be fewer chances of
these errors.
Semantic Errors

Semantic errors are the errors that


occurred when the statements are not
understandable by the compiler.
Compile time Vs Runtime

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

• Both the compile-time and runtime refer to different types of error.


Thank
You

You might also like