0% found this document useful (0 votes)
86 views31 pages

ES105-Programming For Problem Solving: Chapter - 1

This document provides an overview of key concepts related to computer programming and problem solving, including: 1) It defines a computer as a device capable of performing computations and making logical decisions under the control of computer programs or software. Hardware includes physical components while software includes programs and instructions. 2) It describes the main parts of a computer including input/output units, control unit, arithmetic logic unit, memory, and central processing unit. Primary memory is volatile and holds active data while secondary memory is non-volatile external storage. 3) It explains different types of software including system software that runs hardware/applications, and application software designed for specific functions. Programming languages, compilers, interpreters, and assemblers are

Uploaded by

Aadil Vahora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views31 pages

ES105-Programming For Problem Solving: Chapter - 1

This document provides an overview of key concepts related to computer programming and problem solving, including: 1) It defines a computer as a device capable of performing computations and making logical decisions under the control of computer programs or software. Hardware includes physical components while software includes programs and instructions. 2) It describes the main parts of a computer including input/output units, control unit, arithmetic logic unit, memory, and central processing unit. Primary memory is volatile and holds active data while secondary memory is non-volatile external storage. 3) It explains different types of software including system software that runs hardware/applications, and application software designed for specific functions. Programming languages, compilers, interpreters, and assemblers are

Uploaded by

Aadil Vahora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

ES105- Programming for

Problem Solving
Chapter - 1
• Computer What is Computer?
– Device capable of performing computations and making
logical decisions
– Computers process data under the control of sets of
instructions called computer programs
• Hardware
– Physical components of computer
– Various devices comprising a computer
– Keyboard, screen, mouse, disks, memory, CD-ROM, and
processing units
• Software
– Programs or set of instructions that run on a computer
Computer
• Input Unit − Devices like keyboard and mouse that are used to input data and instructions to
the computer are called input unit.
• Output Unit − Devices like printer and visual display unit that are used to provide information
to the user in desired format are called output unit.
• Control Unit − As the name suggests, this unit controls all the functions of the computer. All
devices or parts of computer interact through the control unit.
• Arithmetic Logic Unit − This is the brain of the computer where all arithmetic operations and
logical operations take place.
• Memory − All input data, instructions and data interim to the processes are stored in the
memory. Memory is of two types – primary memory and secondary memory. Primary
memory resides within the CPU whereas secondary memory is external to it.
• CPU − Control unit, arithmetic logic unit and memory are together called the central processing
unit or CPU.
Primary Memory
• Primary memory holds only those data and instructions on which the computer is currently
working.
• It has a limited capacity and data is lost when power is switched off.
• These memories are faster than secondary memory because it requires less overhead.
• Also known as Main Memory and is volatile
• The data and instruction required to be processed resides in the main memory. It is divided
into two subcategories RAM and ROM.
• RAM(Random Access Memory): internal memory of the CPU for storing data, program, and
program result. It is a read/write memory which stores data until the machine is working.
• ROM(Read Only Memory): The memory from which we can only read but cannot write on it.
The information is stored permanently in such memories during manufacture. A ROM stores
such instructions that are required to start a computer.
Secondary Memory

• This type of memory is also known as external memory or non-volatile.


• It is slower than the main memory.
• These are used for storing data/information permanently.
• CPU directly does not access these memories, instead they are accessed via input-output
routines.
• The contents of secondary memories are first transferred to the main memory, and then the
CPU can access it. For example, disk, CD-ROM, DVD, Pen drive etc.
Types of Software

• System software: Software required to run the hardware parts of the


computer and other application software
• Interface between hardware and user applications
• Ex. Operating System, Language Processors and Device Drivers
• Application Software: Software designed for specific function and solve
particular problem
• Ex. Word Processing, PowerPoint presentation
Operating System

• An interface between the hardware and the user.


• Provides an easy and efficient use of the system resources.
• Keeps all hardware parts in a state of readiness to follow user instructions
• Co-ordinates between different devices
• Schedules multiple tasks as per priority
• Allocates resource to each task
Compiler

• Scan program, translate the complete program into machine code or


low level language and then creates an executable code
• Instructions written in high-level language(C) also must be translated
to machine language instructions
• Converts whole program in one go
• The output produced by a compiler is an Object Program (Machine
Language version of source code)
Interpreter

• An interpreter translates high-level instructions and executes it immediately


upon translation
• Converts program one by one line
• The advantage of an interpreter, however, is that it does not need to go
through the compilation stage during which machine instructions are
generated.
• This process can be time-consuming if the program is long.
Assembler

• Program that converts assembly language into machine code


• It takes basic commands and operations from assembly code and converts
them into binary code that is recognized by processor
Types of Languages

• High level language: Language that enables a programmer to write


programs that are less dependent on the computer and closer to human
language
• Low level language: language that is designed to operate and handle the
entire hardware and instruction set architecture of computer directly
• Machine Language: language that is understood by the computer system
easily which contains binary code with 0s and 1s
Algorithm

• In mathematics and computer science, an algorithm is an unambiguous specification of how to


solve a class of problems.
• It is a step-wise representation of a solution to a given problem, which makes it easy to
understand.
• As an effective method, an algorithm can be expressed within a finite amount of space and
time and in a well-defined formal language for calculating a function or task.
• Starting from an initial state and initial input (perhaps empty), the instructions describe a
computation that, when executed, proceeds through a finite number of well-defined
successive states, eventually producing "output" and terminating at a final ending state.
Algorithm

• Algorithms can be expressed in many kinds of notation, including natural


languages, pseudocode, flowcharts etc.
• Programming languages are intended to express the algorithm that can be
executed by computer
• It is not dependent on any programming language, so it is easy to
understand for anyone even without programming knowledge.
Steps involved in Algorithm Development

• Fulfilling the pre-requisites – operands, operators as an input


• Designing the algorithm – decides what to do with the input, process the
input
• Testing the algorithm – test using any computer language, convert
algorithm into language
Algorithm - Example

• Step1: Start
• Step2: Read\input the first num1.
• Step3: Read\input the second num2.
• Step4: Sum <- num1+num2 // calculation of sum
• Step5: Print Sum
• Step6: End
Algorithm - Example

• Step1: Start
• Step2: Read\input the first num1.
• Step3: Power <- num1^2 // power of 2
• Step4: Print Sum
• Step5: End
Flowchart

• A flowchart is a type of diagram that represents an algorithm, workflow or process.


• The flowchart shows the steps using various kinds of shapes, and their order by
connecting the boxes with arrows.
• This diagrammatic representation illustrates a solution model to a given problem.
• Flowcharts are used in analyzing, designing, documenting or managing a process
or program in various fields
Flowchart

• Advantages:
1. Flowchart is an excellent way of communicating the logic of a program.
2. Easy and efficient to analyze problem using flowchart.
3. During program development cycle, the flowchart plays the role of a blueprint, which
makes program development process easier.
4. After successful development of a program, it needs continuous timely maintenance during
the course of its operation. The flowchart makes program or system maintenance easier.
5. It is easy to convert the flowchart into any programming language code.
Flowchart
Flowchart - Example
Pseudocode

• An alternative approach to express an algorithm that bridges the gap between flowcharts
and computer code is called pseudocode.
• This technique uses code-like statements in place of the graphical symbols of the flowchart.
• Ex. . Keywords such as IF, DO, INPUT, etc., are capitalized, whereas the conditions,
processing steps, and tasks are in lowercase. Additionally, the processing steps are
indented.
• One advantage of pseudocode is that it is easier to develop a program with it than with a
flowchart.
Logical Representations - Sequence

• The sequence structure expresses the trivial


idea that unless you direct it otherwise, the
computer code is to be implemented one
instruction at a time.
• statements are placed one after the other and
the execution takes place starting from up to
down
Logical Representations - Selection

• Selection provides a means to split the program’s flow into branches based
on the outcome of a logical condition.
• In branch control, there is a condition and according to a condition, a
decision of either TRUE or FALSE is achieved.
• In the case of TRUE, one of the two branches is explored; but in the case of
FALSE condition, the other alternative is taken. Generally, the
• ‘IF-THEN’ is used to represent branch control.
Logical Representations - Selection
Logical Representations - Selection
Logical Representations - Repetition

• Repetition provides a means to implement instructions repeatedly. The resulting


constructs, called loops, come in two “flavors” distinguished by how they are terminated.
• The Loop or Repetition allows a statement(s) to be executed repeatedly based on certain
loop condition e.g. WHILE, FOR loops.
Logical Representations - Repetition
Example – Find Area and Perimeter of Square
• L : Side Length of Square
• AREA : Area of Square
• PERIMETER : Perimeter of Square

1. Step-1 Start
2. Step-2 Input Side Length of Square say L
3. Step-3 Area = L x L
4. Step-4 PERIMETER = 4 x L
5. Step-5 Display AREA, PERIMETER
6. Step-6 Stop
Example – Find the largest of two numbers
1. Step-1 Start
2. Step-2 Input two numbers say
NUM1,NUM2
3. Step-3 IF NUM1 > NUM2 THEN
print largest is NUM1
ELSE
print largest is NUM2
ENDIF
4. Step-4 Stop
Example – Find even number between 1 to 50
1. Step-1 Start
2. Step-2 I = 1
3. Step-3 IF (I >50) THEN
GO TO Step-7
ENDIF
4. Step-4 IF ( (I % 2) =0) THEN
Display I
ENDIF
5. Step-5 I = I + 1
6. Step-6 GO TO Step--3
7. Step-7 Stop
Exercise

1. Algorithm & Flowchart to find sum of series 1+2+3+…..+N


2. Algorithm & Flowchart to find largest to 3 numbers
3. Algorithm & Flowchart to find area of triangle

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy