Unit1 2
Unit1 2
Unit1 2
PROBLEM SOLVING
UNIT 1
Steps to Develop a Program
Dr.D.BRINDHA
Assistant Professor
CSE/KITS
1
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 2
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 3
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 4
Dr.D.BRINDHA/CSE/KITS 5
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 6
Compiler
Dr.D.BRINDHA/CSE/KITS 8
What is Problem Solving?
Dr.D.BRINDHA/CSE/KITS 9
Problem Solving
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 10
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
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 11
Human Language to tell the way to go to KFC
sequence 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.
12
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
13
How to develop a program?
Dr.D.BRINDHA/CSE/KITS 15
Characteristics of a good algorithm
16
Representation of Program
Pseudocode
• The word “pseudo” means “not real,” so “pseudocode” means “not
real code”.
• 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 17
Benefits of Pseudo code
• Helps in representing the basic functionality of the intended
program.
• The programmer safeguards against leaving out any
important step.
• Helps to review the steps to confirm that the proposed
implementation is going to achieve the desire output.
18
Representation of Program
Flow chart
• 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 19
Shapes or symbols to draw flow charts
Circle
Dr.D.BRINDHA/CSE/KITS 20
Example 1: Write an algorithm to find the square of a number
Flowchart
• Input: Number whose square is required
• 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 21
Example 2: Write an algorithm to check whether a number is
odd or even.
Flow chart
• Input: Any number
• Process: Check whether the number is even or not
• Output: Message “Even” or “Odd”
Dr.D.BRINDHA/CSE/KITS 22
Example 3: Write a pseudo code and draw a flowchart where multiple
conditions are checked to categories a person as either child (<13), teenager
(>=13 but <20) or adult (>=20), based on age specified.
• Input: Age
• Process: Check Age as per the given criteria
• Output: Print either “Child”, “Teenager”, “Adult”
Pseudo code
INPUT Age
if Age < 13 then
PRINT "Child"
else if Age < 20 then
PRINT "Teenager"
else
PRINT "Adult"
Dr.D.BRINDHA/CSE/KITS 23
Example 4: Write the algorithm, pseudo code and draw flowchart to find
the grossPay with the working hours and pay rate per hour.
Dr.D.BRINDHA/CSE/KITS 24