Unit 1
Unit 1
SAMRIDDHI COLLEGE
Lokanthali-1, Bhaktapur, Nepal
Bachelor of Science in
Computer Science & Information Technology
(B.Sc. CSIT)
First Semester
Unit 1
Problem Solving with Computer
by:
Er. Bikal Adhikari
(B.E., M.Sc. Engg., M.Sc. ISE)
2
WHAT IS COMPUTER ?
A computer is an advanced electronic device which accepts raw
data from user via input devices like keyboard, mouse, scanner
etc, processes these data under the control of a set of
instructions called programs, and finally gives the meaningful
information to the user as output via output devices like monitor,
printer, etc. A computer system has in general two major parts.
They are hardware and software.
Hardware: The part of the computer which we can touch or feel
is called hardware. It is the physical part of the computer.
Examples: Monitor, Keyboard, Mouse etc.
Software: The part of the computer which we can only feel but do
not have any physical existence is called software. Examples: MS
Word, Window Media Player etc.
3
Fig: Simple Block Diagram of a Computer
4
PROBLEM ANALYSIS
In order to solve a problem using computer software, the programmer or
developer has to carefully analyze the problem at hand. Following are the
points to be considered while analyzing the problems to be solved by
computer software:
Objective
Input Requirements
Processing Requirements
Output Requirements
Evaluating Feasibility
5
ALGORITHM AND FLOWCHART
Algorithm: An algorithm is a set of ordered steps to solve a problem.
Algorithms are very important because computer can only understand the
instructions in a certain programming language, and instructions can be
ordered as per the algorithm to accomplish a task.
Flowchart: A Flowchart is a diagrammatic/graphical/pictorial representation
of an algorithm. Different symbols used while drawing flowchart are as
follows:
Symbols Meaning Symbols Meaning
Flowline Function/Procedure
Terminal (Start/Stop)
Connector
Input/Output
Off page Connector
Processing
Magnetic disk
storage
Decision Comment
6
EXAMPLES
Example 1: Write an algorithm and draw a flowchart to display the sum of
two numbers entered by the user.
Start
Stop
Fig: Flowchart
7
Example 2: Write an algorithm and draw a flowchart to determine whether
a number entered by the user is even or not.
Algorithm:
Step 1: Start
Step 2: Declare a variables n and rem.
Step 3: Read values into n.
Step 4: Compute n modulo 2 and assign the result to
the variable rem.
Step 5: Is rem equal to zero?
5.1. If yes, continue.
5.2. Otherwise, goto step 8.
Step 6: Display "The entered number is even".
Step 7: Goto Step 9
Step 8: Display "The entered number is odd."
Step 9: Stop
8
Start
Input n
rem ← n mod 2
Is False
rem=0?
True
Stop
Fig: Flowchart
9
Example 3: Write an algorithm and draw a flowchart to find the sum of
first n natural numbers. The value of n is entered by the user.
Algorithm:
Step 1: Start
Step 2: Declare variables n, i and sum.
Step 3: Read values into n.
Step 4: Initialize i to 1.
Step 5: Initialize sum to zero.
Step 6: Is i less than or equal to n?
6.1. If yes, continue.
6.2. Otherwise, goto step 10
Step 7: Add the values of sum and i and assign the
result to sum.
Step 8: Increment i by 1.
Step 9: Goto step 6.
Step 10: Display sum
Step 11: Stop
10
Start
i ←1
sum ←0
Read n
Is False
i <= n?
True
sum ← sum+i Display
sum
i ← i+1
Stop Fig: Flowchart
11
Example 4: Write an algorithm and draw a flowchart to find the solutions
of a quadratic equation ax2 + bx+ c = 0 where the coefficients a, b and c are
entered by the user.
Step 1: Start
Step 2: Declare variables a, b, c, d, r, r1, r2.
Step 3: Read values into a, b and c.
Step 4: Compute the expression (b2-4ac) and assign the result to d.
Step 5: Is d equal to zero?
5.1. If yes, continue
Algorithm:
5.2. Otherwise, goto step 9
Step 6: Compute -b/2a and assign the result to r.
Step 7: Display r
Step 8: Goto step 14
Step 9: Is d greater than zero?
9.1. If yes, continue
9.2. Otherwise, goto step 13
Step 10: Assign (-b+sqrt(d))/2a to r1 and (-b-sqrt(d))/2a to r2
Step 11: Display r1 and r2
Step 12: Goto step 14
Step 13: Display "The roots are imaginary"
Step 14: Stop 12
Start
Input a, b and c
d ← b2-4×a×c
False
Flowchart: Is d=0?
True False
Is d>0?
r ← -b/2a
True
display r r1 ← (-b+sqrt(d))/2a and
r2 ← (-b-sqrt(d))/2a display "roots are
imaginary"
display r1 and r2
Stop
13
CODING
→ Coding is an activity of writing computer programs.
→ Writing the source code of a program using particular programming
language is known as program coding.
→ Coding involves the translation of algorithm/flowchart into a high level
program.
14
COMPILATION AND EXECUTION
Source Source Source
Code Code Code
Compiler
Run time
Linker .exe
library
15
Source Code: Generally, you can write a computer program on a text
editor. You can save it as a file with certain extension onto the disk.
Generally, the program written in a file using particular programming
language is known as source code. For C programs, the source code
file ends with “.c” extension. In a complex software or program, there
can be many source code or ".c" files.
Complier: It compiles source code into object code. The process is
known as compilation. The compiler produces an object code for
each corresponding source code.
Object Code: It is a file containing machine code of a program that
can be run by the microprocessor of the computer.
Linking: The process of combining different object codes into a
single executable file is known as linking. Linker does this job under
the control of runtime library. A run time library is a collection of
software programs used at program run time to provide one or more
native program functions or services.
.exe file: The file which can directly run when double clicked is
known as an executable file. For windows based OS, ".exe" is the
extension for executable files.
16
Execution: The process of compiling and running a program is known
as execution.
All of the above components like text editor, compiler, linker etc are
present in a single software package called IDE(Integrated
Development Environment). Example TURBO C, CODEBLOCKS,
DEVCPP etc.
17
HISTORY OF C PROGRAMMING LANGUAGE
C Programming language is a structured and procedure oriented
programming language designed by Dennis Ritchie in early 1970s at Bell
Lab while working on Unix Operating System.
It is very popular programming language in designing operating system
core components and device drivers.
It is a minimalistic yet a very powerful programming language.
The main reason behind the C's popularity is due to the fact that the
programs written in C are very close to the algorithm that can run on
computer hardware.
18
ALGOL = Algorithmic Language, BCPL = Basic Combined Programming Language, ANSI =
American National Standards Institute, ISO = International Organization for Standardization 19
ERROR
An error is a bug in a program or software which causes it operate
incorrectly. Error must be minimized for a software product or program to
run efficiently. Following are the different types of errors:
1) Syntax error:- The syntax error occurs due to the poor understanding of
the programming language. It is similar to the grammatical mistakes in
English language. However, in context of computer, syntax error would
prevent the program from being compiled.
2) Run-time error:- The run time error occurs when program is in the state
of running. Memory space running out, array out of the bound error,
divide by zero error etc are some examples of run time error which can
cause a running program to terminate.
3) Logical error:- The logical error occurs due to the poor understanding of
the problem. Logical error can be minimized by reviewing the literature
through books, journal articles, conference proceedings etc.
4) Latent error:- The hidden or unknown errors are known as latent errors.
20
TESTING AND DEBUGGING
Testing:
The process of executing a program with an intention of finding an error or
bug is known as testing. Testing is done for improving quality, reliability,
verification and validation of the program or software product. When we buy
a new bike, we go for a short test drive. After testing, we can come to the
conclusion whether it is suitable for us or not. If there is any problem(error)
we would look for another model or another piece. Testing can be done
manually by human based testing or it can be done automatically by
computer based testing.
Debugging:
The process of isolating or correcting errors in a program is known as
debugging. Different methods of debugging are error isolation, tracing, watch
values, breakpoints, stepping etc.
21
DOCUMENTATION
After software has been developed, it needs proper documentation.
Document serves as a good future reference to the all the stakeholders
i.e. the developer, company, and the customer.
The software documentation consist all the details related to
requirement analysis, feasibility study, algorithm development and
flowcharts, coding and organization, testing and debugging etc.
22
Thank You!!!
23