Module 1
Module 1
PROBLEM SOLVING
Dr.D.BRINDHA/CSE/KITS 1
MODULE 1
Introduction to Programming
Dr.D.BRINDHA/CSE/KITS 2
Introduction to Computer and programming
Dr.D.BRINDHA/CSE/KITS 3
A computer
• A computer is a programmable machine that receives input, stores
and manipulates data, and provides output in a useful format.
Dr.D.BRINDHA/CSE/KITS 4
Let the computer communicate with the user
5
Dr.D.BRINDHA/CSE/KITS
CPU (Central Processing Unit)
Dr.D.BRINDHA/CSE/KITS 6
What is the purpose of the CPU?
• The purpose of the CPU is to process data.
• The CPU is where processes such as
calculating, sorting and searching take place.
• Whatever is done on our computers, such as
checking emails, playing games and doing
homework, the CPU has processed the data
we use.
• The CPU is made up of three main
components,
1. the control unit,
2. the immediate access store and
3. the arithmetic and logic unit.
Dr.D.BRINDHA/CSE/KITS 7
CPU- COMPONENTS
1)Immediate access store
The immediate access store is where the CPU holds all the data and programs that it
is currently using. You can think of it like the numbers typed into a calculator – they
are being stored inside the calculator while it processes the calculations. The
immediate access store is often referred to as the registers in the CPU.
Registers
• Temporary storage area for data &
instructions
• The important registers, within CPU is
program counter (PC). A program
counter keeps track of next instruction to
be executed
Dr.D.BRINDHA/CSE/KITS 8
2)Arithmetic and logic unit (ALU)
• Performs arithmetic & logic operations like ADDITION, SUBTRACTION,
INCREMENT, AND, SHIFT, ROTATE etc.,
• More powerful CPU's can support additional mathematical operations like
multiplication and division.
• The ALU’s operations fall into two parts:
• the arithmetic part, which deals with calculations, Eg: 1 + 2 = 3
• the logic part, which deals with any logical comparisons, Eg: 2 >1
3)Control Unit
• The control unit consists of control signal that set up a communication channel and
controls the flow of data within the CPU and other devices
• The control unit communicates to the memory, arithmetic and logic unit and I/O
devices, how to respond to the instructions that have been sent to the processor.
Dr.D.BRINDHA/CSE/KITS 9
Memory Devices
• Memory is one or more sets of
chips that store data/program
instructions, either temporarily or
permanently .
• It is critical processing
component in any computer
Dr.D.BRINDHA/CSE/KITS 10
Basic Units Of Measurement
Dr.D.BRINDHA/CSE/KITS 11
Steps to Develop a Program
Dr.D.BRINDHA
Assistant Professor
CSE/KITS
12
Hardware and software
• Hardware - The “machine” part of the computer
• Software - “programmable” part of the computer
• The instructions needed to direct the computer to complete specific tasks
Dr.D.BRINDHA/CSE/KITS 13
3 main categories of Software
1)System Software
•System software is a type of computer program that is designed to run a computer’s hardware
and application programs.
•The system software is the interface between the hardware and user applications. The operating
system (OS) is the best-known example of system software.
•The OS manages all the other programs in a computer.
Other examples of system software include:
•The BIOS (basic input/output system) gets the computer system started after you turn it on and manages
the data flow between the operating system and attached devices such as the hard disk, video adapter,
keyboard, mouse and printer.
•The boot program loads the operating system into the computer's main memory or random access
memory (RAM).
•An assembler takes basic computer instructions and converts them into a pattern of bits that the
computer's processor can use to perform its basic operations.
•A device driver controls a particular type of device that is attached to your computer, such as a keyboard
or a mouse. The driver program converts the more general input/output instructions of the operating system
to messages that the device type can understand.
Dr.D.BRINDHA/CSE/KITS 14
2)Application Software
• Application Software is a program that does real work for the user.
• It is mostly created to perform a specific task for a user.
• Application Software acts as a mediator between the end-user and System Software. It is also known as an
application package.
• This type of software is written using a high-level language like C, Java, VB. Net, etc. It is a user-specific and is
designed to meet the requirements of the user.
3)Middleware
• Middleware is software which lies between an operating system and the applications running on it.
• Essentially functioning as hidden translation layer, middleware enables communication and data management
for distributed applications
• Common middleware examples include database middleware, application server middleware, message-
oriented middleware, web middleware
Dr.D.BRINDHA/CSE/KITS 15
Dr.D.BRINDHA/CSE/KITS 16
Operating System
• An operating system (OS) is a type of system software that manages computer's hardware and
software resources.
• It provides common services for computer programs.
• An OS acts a link between the software and the hardware.
• It controls and keeps a record of the execution of all other programs that are present in the
computer, including application programs and other system software.
Compiler
• A compiler is a software that translates the code written in one language to some other
language without changing the meaning of the program.
• The compiler is also said to make the target code efficient and optimized in terms of time and
space
• A compiler performs almost all of the following operations during compilation:
preprocessing, lexical analysis, parsing, semantic analysis (syntax-directed translation),
conversion of input programs to an intermediate representation, code optimization and
code generation.
• Examples of compiler may include gcc (C compiler) , javac (Java Compiler) etc.
Dr.D.BRINDHA/CSE/KITS 17
Compiler
Dr.D.BRINDHA/CSE/KITS 18
What is programming?
Dr.D.BRINDHA/CSE/KITS 19
What is Problem Solving?
Dr.D.BRINDHA/CSE/KITS 20
Human Language to tell the way to go to KFC
sequence of instructions
• A computer program is also called a computer software, which can range from two
lines to millions of lines of instructions.
• Computer program instructions are also called program source code and computer
programming is also called program coding.
• A computer without a computer program is just a dump box; it is programs that make
computers active.
21
Different terminologies
🞂 An algorithm is a precise sequence of instructions for solving a problem.
🞂 Running a program is the process of telling the computer to evaluate the compiled
instructions.
🞂 Bugs are problems/errors with a program that cause it to stop working or produce
incorrect or undesirable results.
🞂 The process of finding and fixing errors in your code is called debugging
22
HOW TO DEVELOP A PROGRAM
Dr.D.BRINDHA/CSE/KITS 24
Representation of Program
Pseudocode
• Pseudocode is written in a format which is very close to the actual
programming language.
• informal representation of the code, doesn't follow rules of the
language
Example
Two numbers should be read and then their addition result should be displayed.
1.START
2.Read number1,number2
3.sum number1 + number2
4.Print sum
5.STOP
Dr.D.BRINDHA/CSE/KITS 25
Representation of Program
Flow chart
• Visual representation of an algorithm.
• Diagram made up of boxes, diamonds and other shapes, connected by
arrows.
• Each shape represents a step of the solution process and the arrow
represents the order or link among the steps
Dr.D.BRINDHA/CSE/KITS 26
Shapes or symbols to draw flow charts
Dr.D.BRINDHA/CSE/KITS 27
Example 1: Write an algorithm to find the square of a
number Flowchart to
• Input: Number whose square is required calculate square
of a number
• Process: Multiply the number by itself to
get its square
• Output: Square of the number
Algorithm:
– Step 1: Input a number and store it to num
– Step 2: Compute num * num and store it in
square
– Step 3: Print square
pseudocode
INPUT num
COMPUTE square = num * num
PRINT square
Dr.D.BRINDHA/CSE/KITS 28
Let us write an algorithm to check whether
a number is odd or even.
• • Input: Any number
• • Process: Check whether the number is even
or not
• • Output: Message “Even” or “Odd”
Dr.D.BRINDHA/CSE/KITS 29
Let us write a pseudocode and draw a flowchart where
multiple conditions are checked to categorise a person as
either child (<13), teenager (>=13 but <20) or adult
(>=20),based
• • Input: Age
on age specified:
• • Process: Check Age as per the given criteria
• • Output: Print either “Child”, “Teenager”, “Adult”
Pseudocode is as follows:
• INPUT Age
• if Age < 13 then
• PRINT "Child"
• else if Age < 20 then
• PRINT "Teenager"
• else
• PRINT "Adult"
Dr.D.BRINDHA/CSE/KITS 30
Dr.D.BRINDHA/CSE/KITS 31
Software development life cycle
What is SDLC?
• SDLC is a process followed for a software project, within a software organization.
• It consists of a detailed plan describing how to develop, maintain, replace and alter
or enhance specific software.
• The life cycle defines a methodology for improving the quality of software and the
overall development process.
Dr.D.BRINDHA/CSE/KITS 32
Software development life cycle
The following five phases are followed in order to develop any program/software
• the developer tries to identify what is to be done, the
exact specification is understood and documented
• tries to find the solution of the problem i.e how to do
• coding is done in any programming languages
• developed code is tested to find errors and correct
them in the software testing phase
• finally software is installed and maintained
Dr.D.BRINDHA/CSE/KITS 33
Structured Programming
• The concept of structure programming is used to have better reliable
and quality design and coding.
• It refers to a programming strategy that encompasses number of
methodologies to produce good quality design and code, which can be
easily understood,tested,debugged,modified and maintained in future
• There are three mail principles of structural programming:
• Program design using top-down or bottom-up approach
• Decomposition of program into components i.e., modular programming.
• Structuring of control flow.
Dr.D.BRINDHA/CSE/KITS 34
Top-Down & Bottom-Up Approach
Using this top-down approach
a large complex problem is
Top Down Approach
broken up into sub-problems,
and if necessary these are
further divided until the tasks
to be solved are simpler or
easier for programming code
to be developed.
Dr.D.BRINDHA/CSE/KITS
Modular Programming
Dr.D.BRINDHA/CSE/KITS 36
Structuring of control flow
• The idea behind the structuring the flow of control is to reduce the complexity, which gets
increased due to abrupt control transfers, interconnections and cross connections among
various parts of a program.
• It strongly follow the principle of single entry and single exit to all sub-parts od a program.
• Thus can be achieved by implementing all processing requirements using combinations of
three basic control flows: Sequence, Selection and Iteration
Dr.D.BRINDHA/CSE/KITS 37
Human Language to tell the way to go to KFC
sequence of instructions
Dr.D.BRINDHA/CSE/KITS 38
Computer-programming language
• As we have developed so many languages to communicate among ourselves, computer
scientists have developed several computer-programming languages to provide
instructions to the computer (i.e., to write computer programs).
• Java
• C
• C++
• Python
• PHP
• Perl
• Ruby
Dr.D.BRINDHA/CSE/KITS 39
Dr.D.BRINDHA/CSE/KITS 40
Dr.D.BRINDHA/CSE/KITS 41
Dr.D.BRINDHA/CSE/KITS 42
Dr.D.BRINDHA/CSE/KITS 43
Example for input/process/output
• 1. Input: get all the grades … perhaps by typing them in via the keyboard or
by reading them from a USB flash drive or hard disk.
• 2. Process: add them all up and compute the average grade.
• 3. Output: output the answer to either the monitor, to the printer, to the USB
flash drive or hard disk … or a combination of any of these devices.
Dr.D.BRINDHA/CSE/KITS 44
Steps for Problem Solving
Dr.D.BRINDHA/CSE/KITS 45
Analysing the problem:
• It is important to clearly understand a problem before we begin to
find the solution for it.
• By analysing a problem, we would be able to figure out what are the
inputs that our program should accept and the outputs that it
should produce.
• Developing an Algorithm:
• Well-defined sequence of steps that provides a solution for a given
problem.
• The solution is represented in natural language.
• For a given problem, more than one algorithm is possible and we
have to select the most suitable solution
Dr.D.BRINDHA/CSE/KITS 46
Coding:
• After finalizing the algorithm, we need to convert the algorithm into the
format which can be understood by the computer to generate the desired
solution.
• Different high level programming languages can be used for writing a
program.
Dr.D.BRINDHA/CSE/KITS 47
Testing and Debugging
The program should meet the requirements of the user.
It must respond within the expected time.
It should generate correct output for all possible inputs.
syntactical errors, no output will be obtained.
In case the output generated is incorrect, then the program
should be checked for logical errors.
unit or component testing, integration testing, system testing, and
acceptance testing while developing complex applications.
The errors or defects found in the testing phases are debugged or
rectified and the program is again tested. This continues till all
the errors are removed from the program.
Dr.D.BRINDHA/CSE/KITS 48
Dr.D.BRINDHA/CSE/KITS 49
Syntax and Semantic errors
• Syntax errors: Errors that occur when you violate the rules of writing C syntax
are known as syntax errors.
• This compiler error indicates something that must be fixed before the code can be
compiled. All these errors are detected by compiler and thus are known as compile-time
errors.
• Most frequent syntax errors are:
• Missing Parenthesis (})
• Printing the value of variable without declaring it
• Missing semicolon like this:
#include<stdio.h>
void main()
{
int x = 10;
int y = 15;
int a = "hello";
Dr.D.BRINDHA/CSE/KITS 51
Steps to develop a program(Representation of Algorithm)
Dr.D.BRINDHA/CSE/KITS 52
Types of programming languages
Dr.D.BRINDHA/CSE/KITS 53
Introduction to C, Developing a C program
Dr.D.BRINDHA/CSE/KITS 54
Algorithmic
Language
Basic Combined
programming
Language
American National
Standards
Institute (ANSI) International
Organization for
Standardization
(ISO)
55
Back-end (Server-side)
Applications of C
Dr.D.BRINDHA/CSE/KITS
56
Console input and output functions
Dr.D.BRINDHA/CSE/KITS 57
Error diagnostics, Debugging techniques Syntax and
Semantic errors.
Dr.D.BRINDHA/CSE/KITS 58