0% found this document useful (0 votes)
16 views

Module 1

The document provides an introduction to programming and problem solving. It discusses what a computer is and how it works, with a focus on the central processing unit (CPU). The CPU has three main components: the control unit, immediate access store, and arithmetic logic unit. It also discusses different types of software, including system software, application software, and middleware. Programming is defined as the process of preparing instructions for a computer to perform tasks, while problem solving is developing algorithms and programs to solve problems.

Uploaded by

meclinejosefl
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Module 1

The document provides an introduction to programming and problem solving. It discusses what a computer is and how it works, with a focus on the central processing unit (CPU). The CPU has three main components: the control unit, immediate access store, and arithmetic logic unit. It also discusses different types of software, including system software, application software, and middleware. Programming is defined as the process of preparing instructions for a computer to perform tasks, while problem solving is developing algorithms and programs to solve problems.

Uploaded by

meclinejosefl
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

20CS1001 - PROGRAMMING FOR

PROBLEM SOLVING

Lets Learn A Language


To talk to PC

Dr.D.BRINDHA/CSE/KITS 1
MODULE 1
Introduction to Programming

Dr.D.BRINDHA/CSE/KITS 2
Introduction to Computer and programming

Computer science is all about


solving problems with
computers

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)

• The CPU (Central Processing Unit) is the part of


a computer system that is commonly referred to as the
"brains" of a computer. The CPU is also known as
the processor or microprocessor.
• The CPU is responsible for executing a sequence of stored
instructions called a program .
• This program will take inputs from an input device, process
the input in some way and output the results to an output
device.
• CPU's aren’t only found in desktop or laptop computers,
many electronic devices now rely on them for their operation.
Mobile phones, DVD players, automated car and washing
machines are examples of equipment that have a CPU.

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

• write the computer program using your favorite 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 18
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 19
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 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.

🞂 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

22
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 23
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 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”

Pseudocode of the algorithm can be


written as follows:

• PRINT "Enter the Number"


• INPUT number
• IF number MOD 2 == 0 THEN
• PRINT "Number is Even"
• ELSE
• PRINT "Number is 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

Modular programming emphasis


on breaking of large programs into
small problems to increase the
maintainability, readability of the
code and to make the program
handy to make any changes in
future or to correct the errors.

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

Calculate the average grade for all students in a class.

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

printf("%d", (x, y)) // semicolon missed


}
Dr.D.BRINDHA/CSE/KITS 50
Semantic errors :
• This error occurs when the statements written in
the program are not meaningful to the compiler.
void main() String s = "...";
{
int a, b, c; int a = 5 - s;
a + b = c; //semantic error
}

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

You might also like