0% found this document useful (0 votes)
15 views24 pages

Unit1 2

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 24

20CS1001 - PROGRAMMING FOR

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

• Computer program is written using any programming


language and save it in a text file called the program file.

• The conversion from text program to binary file is done by


another software called Compiler and this process of
conversion from text formatted program to binary format
file is called program compilation.

• Finally, execute the binary file to perform the


programmed task.
Dr.D.BRINDHA/CSE/KITS 7
What is programming?

• The process of preparing an instructional program for a device


• A computer program is also called a computer software, which can range from
two lines to millions of lines of instructions.
• A computer program is a sequence of instructions written using a Computer
Programming Language to perform a specified task by the computer.
• Attempting to get a computer to complete a specific task without making mistakes
• Computer's are only smart because we program them to be.
• A computer without a computer program is just a dump box; it is programs
that make computers active.

Dr.D.BRINDHA/CSE/KITS 8
What is Problem Solving?

• The process of identifying a problem, developing an algorithm for the


identified problem and finally implementing the algorithm to develop a
computer program.
• When problems are straightforward and easy, we can easily find the
solution. But a complex problem requires a methodical approach to find the
right solution.
• Begins with the precise identification of the problem and ends with a
complete working solution in terms of a program or software

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

• A computer program is also called a computer software or Program source code,


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.

12
Different terminologies
🞂 An Algorithm is a precise sequence of instructions for solving a problem.

🞂 Compiling is the process of converting a program into instructions that can be


understood by the computer.

🞂 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?

• Analyze the problem to identify inputs, outputs and processing


requirements.
• Identify various processing steps needed to solve the problem and represent
them in a particular way.
• algorithm, pseudo code, flowchart

• Add the syntax of the programming language to the above representation,


it becomes the program.
• Type the program and compile it.
• Run the compiled program and check it with various input to verify its
correctness.
Dr.D.BRINDHA/CSE/KITS 14
Representation of Program
Algorithm
1. An algorithm is defined as a well-defined sequence of steps that provides a
solution for a given problem
2. Written in a natural language or plain English language
3. Can be quite abstract or in quite detailed
4. it is independent of the platform of programming you choose.
Example
Two numbers should be read and then their addition result should be displayed.
1.Read first and second number
2.add both numbers and get the result
3.Print the result.

Dr.D.BRINDHA/CSE/KITS 15
Characteristics of a good algorithm

• Precision — the steps are precisely stated or defined.


• Uniqueness — results of each step are uniquely defined and only
depend on the input and the result of the preceding steps.
• Finiteness — the algorithm always stops after a finite number of steps.
• Input — the algorithm receives some input.
• Output — the algorithm produces some output.

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

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

Algorithm Pseudo code


Step1: Input a number and PRINT "Enter the Number"
store it in num1. INPUT number
Step2: Find modulo 2 of IF number MOD 2 == 0
num. THEN
Step3: If answer is zero, then PRINT "Number is Even"
print even ,else print odd. ELSE
PRINT "Number is 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

You might also like