0% found this document useful (0 votes)
284 views23 pages

PPS Chapter-1

The document provides an introduction to computers and programming. It discusses the basic components of a computer including input, output, storage, and the central processing unit. It describes the functions of hardware and software, with hardware being the physical parts and software being the programs and instructions. It also differentiates between types of software, specifically system software which controls basic computer functions, and application software.

Uploaded by

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

PPS Chapter-1

The document provides an introduction to computers and programming. It discusses the basic components of a computer including input, output, storage, and the central processing unit. It describes the functions of hardware and software, with hardware being the physical parts and software being the programs and instructions. It also differentiates between types of software, specifically system software which controls basic computer functions, and application software.

Uploaded by

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

Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

Subject
Programming for Problem Solving (3110003)

Chapter – 1
Introduction to Computer and Programming

Prepared by – Prof. Viral H. Panchal 1


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

CONTENTS
1. INTRODUCTION
1.1. Advantages (Characteristics) of Computers
1.2. Limitations of Computers
2. BASIC BLOCK DIAGRAM AND FUNCTIONS OF VARIOUS COMPONENTS OF
COMPUTER
3. CONCEPT OF HARDWARE AND SOFTWARE
3.1. Types of Software
3.2. Difference between Compiler and Interpreter
4. PROGRAMMING LANGUAGES
5. FLOWCHART
5.1. Flowchart Examples
6. ALGORITHM
6.1. Algorithm Examples

Prepared by – Prof. Viral H. Panchal 2


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

1. INTRODUCTION
• A computer is an electronic device which accepts data from outside world and
manipulates or process it according to instruction given at high speed.
• It has memory to store large amount of data, can process it in accurate form with
high speed by using powerful processor.
• Computer is also called data processor because it can store, process and retrieve
data whenever required.
• A computer cannot work of its own, but work is based on some prior instructions
given to it that is known as computer programming.
• According to instruction it performs action. A computer therefore follows a series
of instructions, programmed into its memory by its user.

1.1. Advantages (Characteristics) of Computers


• Automatic – The computers are automatic machines in the sense that once started
on a job, they carry on, until the job is finished, normally without any user’s help.
• Speed – First basic reason of usage of computer is high speed. Speed is measure
in clock cycle i.e., Hertz (Hz), now a days computers are available in speed of
2.2 GHz or higher.
• Accuracy - In addition to speed, computers are very accurate. It produces highly
accurate and reliable results than human beings.
• Diligence – A computer can perform the same task repeatedly with the same
degree of accuracy and reliability at the first one. This is because unlike human
beings, a computer is free from monotony, tiredness, lack of concentration, etc.,
and hence, can work for hours together without creating any errors.
• Large Storage – A computer can store and recall any amount of information
because of its secondary storage capability.
• Versatility – A computer can perform any task, by generating finite series of
logical steps.

1.2. Limitations of Computers


• It cannot operate by itself without the assistance of human beings.
• It cannot identify any problem of the world on its own that requires a solution.
• It cannot identify the input/output needed to solve a problem.
• It cannot identify and collect the data needed to produce any desired output.
• It cannot design or develop its own software that is necessary to transform any
data into a desired output.
• Computers cannot interpret and use the information that is stored in a computer.

Prepared by – Prof. Viral H. Panchal 3


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

2. BASIC BLOCK DIAGRAM AND FUNCTIONS OF VARIOUS


COMPONENTS OF COMPUTER

Figure 2.1: Block diagram of a computer

• Figure 2.1 above shows the block diagram of a computer.


• In this figure, the solid lines are used to indicate the flow of instructions and data,
and the dotted lines represent the control exercised by the control unit.
• A computer has following components:
1. Input Unit
2. Output Unit
3. Storage Unit
4. Central Processing Unit (CPU)

1. Input Unit – Information is entered into a computer through input devices. An


input device reads the data and program into the computer.
• An input device converts input information into suitable binary form
acceptable to the computer.
• It supplies the converted instructions and data to the computer system for
further processing.
• Some popular input devices are keyboard, mouse, joystick, etc.

2. Output Unit – The output device receives results and other information from
the computer and provide them to the users.
• The computer sends information to an output device in the binary form.

Prepared by – Prof. Viral H. Panchal 4


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• An output device converts it into a suitable form convenient to users such as


printed form, display on a screen, voice output, etc.
• Some of the popular output units are computer screen (Visual Display Unit,
VDU), printer, plotter, etc.

3. Storage Unit – The function of storage unit is to store information.


• The data and instructions that are entered into the computer system through
input units must be stored inside the computer before the actual processing
starts.
• Similarly, the results produced by computer after processing be kept
somewhere before they are passed onto the output unit for display.
• Moreover, the intermediate results produced by the computer must also be
preserved.
• The storage unit of the computer provides support for these storage functions.
• There are two types of storage:
1. Primary storage (main memory)
2. Secondary storage
• The main memory is a fast memory. It stores programs along with data. The
main memory is directly accessible by the CPU. The main memory is volatile
(i.e., data losses on power off)
• The secondary memory, also called the auxiliary memory, is used to store
information, data, and program instructions permanently. These may be used
later or deleted whenever not required.

4. Central Processing Unit (CPU) – The CPU is a brain of a computer. Its


primary function is to execute programs.
• Besides executing programs, the CPU also controls the operation of all other
components such as memory, input, and output devices.
• The major sections of a CPU are:
1. Arithmetic and Logic Unit (ALU)
2. Control Unit (CU)
• Arithmetic and Logic Unit (ALU) – The operation of an ALU is to perform
arithmetic and logic operations such as addition, subtraction, multiplication
and division; AND, OR, NOT, Exclusive OR operations. It also performs
increment, decrement, and shift operations.
• Control Unit (CU) – The control unit is the most important part of the CPU as it
controls and co-ordinates the activities of all other units such as ALU, memory
unit, input and output unit. Although, it does not perform any actual processing
on the data, the CU acts as the central nervous system.

Prepared by – Prof. Viral H. Panchal 5


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

3. CONCEPT OF HARDWARE AND SOFTWARE


• Hardware refers to the physical elements of a computer. This is also called the
machinery or the equipment of the computer.
• User can see and touch the hardware components.
• Examples of hardware in a computer are keyboard, mouse, monitor, CPU, etc.
• A computer is not capable of performing any task with just the hardware.
• It requires instructions to determine whether it will function as desired or not.
Instructions are also entered like the data using keyboard.
• A sequence of instructions given to a computer to perform a particular task is
called a program.
• A set of programs written by programmers for a computer is called software.

3.1. Types of Software


• There are basically two types of software:
1. System Software
2. Application Software

1. System Software – System software helps the computer perform essential


operating tasks and enables the application software to run.
• They control internal computer functions, such as reading data from input
device, transmit processing information to output devices, provides various
facilities like file management, I/O management, and CPU time to user
program during execution of program.
• It also helps hardware component work together and provide support for
development and execution of application software.
• There are various system software available:
o Operating System (OS)
o Compiler
o Assembler
o Interpreter
o Loader
o Linker
o Translator

• Operating System (OS) - It is system software which manages hardware as


well as interacts with user and provides different services to user programs.
• It provides services like memory management, I/O management, CPU
management, process management.
• Examples of OS are DOS, Windows XP, Vista, Windows 7, Linux, etc.

Prepared by – Prof. Viral H. Panchal 6


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Compiler – We know that the computer only understands machine language


(the language of 0’s and 1’s). So, the program written in high-level language
needs to be translated into machine language before it can be executed by
the computer.
• The compiler translated high-level language program to machine language
program. A program written in high-level language is known as source code
and a program obtained after compilation is known as object code.

• Assembler – A program which translates an assembly language program into


a machine language program is called assembler.
• The assembler is actually a complicated program written in machine
language. Assembly code is a mnemonic version of machine code.
• A program written is assembly language is called source program. The
assembler converts the source program into the machine language program
known as object program.

• Interpreter – An interpreter is a translating program for the purpose of


converting high-level language into machine language.
• An interpreter translates only one statement of a high-level language at a
time.
• After translation the statement is immediately executed. Means we can say
that the interpreter translates line by line high-level language programs into
machine language programs.

• Loader - Loader loads the program into the main memory area where the
program can be executed. Example is Boot Strap loader.

• Linker – Linker links the symbolic code of source and library files to make
executable program.

• Translator – Translator convert one language into other.

Prepared by – Prof. Viral H. Panchal 7


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

2. Application Software – Software designed for user specific need is called


application software or application package.
• Examples are library management, school management, hospital
management, etc. They are developed with the help of programming
language.
• Some program directs the computer to perform specific tasks requested by
user, such as printing report of customize program, mail, store result, etc. Such
program also called application software.
• There are basically two types of application software:
1. General purpose software
2. Special purpose software

• General Purpose Software – They are used for many numbers of tasks and
provide many features. Examples are MS Office, Page maker, etc.

• Special Purpose Software – It is designed for specific purpose only. User


programs come under special purpose software. Examples are pay roll
system for specific company, tax calculation software, etc.

3.2. Difference between Compiler and Interpreter


Parameter Compiler Interpreter
Input An entire program is taken A single line of code or
by compiler at a time. instruction is taken by interpreter
at a time.
Output It outputs intermediate It does not generate any
object code. intermediate object code.
Working The compilation is Compilation and execution are
mechanism implemented prior to implemented simultaneously.
execution.
Speed Faster Comparatively slower
Memory Memory requirement is more Memory requirement is less as
as object code is created. object code does not created.
Errors Shows all the errors after Displays errors line by line.
compilation at a time.
Error detection Comparatively difficult Easier
Pertaining C, C++, C#, Scala, Java, PHP, Perl, Python, Ruby
programming typescript uses compiler. uses an interpreter.
languages

Prepared by – Prof. Viral H. Panchal 8


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

4. PROGRAMMING LANGUAGES
• A programming language is a set of rules that tells the computer what operations
to do. These languages are used by the programmers to create other kinds of
software.
• It is classified as:
1. Machine language or low-level language
2. Assembly language
3. High-level language

1. Machine Language or Low-level Language – Machine language is the


language of 0’s and 1’s. The computer can directly understand the machine
language. Every microprocessor has different machine language.

• Advantages:
1. Program execution is faster in comparison with others.
2. Due to direct writing into machine code the size of code is compact and
small in comparison with other languages.
3. It occupies less memory.

• Disadvantages or Drawbacks:
1. It requires depth technical knowledge to debug program.
2. Need to remember all operation codes and memory addresses.
3. Due to only two combinations (0’s and 1’s) it is difficult to understand.

2. Assembly Language – Assembly language is a low-level programming


language that allows a computer user to write a program using abbreviations
or more easily remembered words instead of numbers.
• Assembly language uses a mnemonic to represent each low-level machine
instruction.
• Assembly language may also be called symbolic machine code.
• Computer requires assembler to translate assembly language program into
machine language program and then it is only become executable.

• Advantages:
o The programs are very easy to understand or debug.
o The programs are fast to enter using alphanumeric keys of keyboard.

• Disadvantages or Drawbacks:
o It requires assembler to translate assembly language program to
machine language program.

Prepared by – Prof. Viral H. Panchal 9


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

o Programmer must have detailed knowledge of the architecture of


microprocessor.
o Assembly language programs are not portable.

3. High-level Language – A high-level language resembles some human


language such as English. It allows users to write in a familiar notation, rather
than numbers or abbreviations.
• Also, unlike machine and assembly languages, high-level languages are not
machine dependent, i.e., they can be used on more than one kind of computer.
• Few examples are FORTRAN, COBOL, BASIC, Pascal, C, C++, JAVA, etc.

• Advantages:
o The high-level sentences are easy sentences, so it is very easy to learn.
o No need to learn computer architecture.
o The programs are very easy to understand or debug.
o The programs are fast to enter using alphanumeric keys of keyboard.
o The programs are portable.

• Disadvantages or Drawbacks:
o High-level language program requires compiler or interpreter to
translate high-level language program into machine language that
means object code.
o Object code needs loader to load code into the main memory and
execute that program.
o Programmers need to learn structure of high-level language program
and syntax of every statement.
o Some high-level languages are dependent on operating system.

Prepared by – Prof. Viral H. Panchal 10


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

5. FLOWCHART
• A flowchart is a graphical representation of a program flow of any problem to
be solved by computer programming language.
• It is prepared first before writing any program.
• It is used to correct and debug a program flow after coding part is completed.
• Through flowchart it is easy to understand logic and sequence of problem.

• Symbols of Flowchart: Flow chart used following symbols:

1. Start and Stop:


Used to start flowchart as well as to termin
flowchart.

2. Input / Output:

Used for input and output operation.

3. Process or expression representation:

Used to represent any assignment or expression.

4. Decision:

Used for any decision-making statement.

5. Direction of data flow or flow lines:

These arrows indicate the flow of sequence.

6. Connector:

Used for connecting flow lines from different places.

7. Loop:

Used for iteration or looping statement.

Prepared by – Prof. Viral H. Panchal 11


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Advantages:
o Easy to draw.
o Easy to understand logic.
o Easy to identify mistakes by non-computer person.
o Easy to show branching and looping.

• Disadvantages:
o Time consuming.
o Difficult to modify.
o Very difficult to draw flowchart for big or complex problems.

5.1. Flowchart Examples


• Draw a flowchart to find sum of two numbers.

Prepared by – Prof. Viral H. Panchal 12


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to find area of rectangle.

• Draw a flowchart to find average of three subject marks.

Prepared by – Prof. Viral H. Panchal 13


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to find maximum number from two numbers.

• Draw a flowchart to find whether given number is odd or even.

Prepared by – Prof. Viral H. Panchal 14


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to find maximum number from three different numbers.

• Draw a flowchart to find root of equation: ax2 + bx + c.

Prepared by – Prof. Viral H. Panchal 15


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to reverse given number.

• Draw a flowchart to find factorial of given number: f = 1 x 2 x 3 x …… N.

Prepared by – Prof. Viral H. Panchal 16


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to do the sum of 10 elements read from user.

• Draw a flowchart to find maximum number from N different number.

Prepared by – Prof. Viral H. Panchal 17


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to generate Fibonacci series up to given term.

Prepared by – Prof. Viral H. Panchal 18


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

• Draw a flowchart to accept N numbers and count how many of them were
odd and compute sum of all these odd.

Prepared by – Prof. Viral H. Panchal 19


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

6. ALGORITHM
• An algorithm is a finite and ordered sequence of steps for solving a problem in a
systematic manner.
• It is also called as a step-by-step solution of the problem.

• Advantages:
o Easy to write.
o Human readable techniques to understand logic.
o Algorithms for big problems can be written with moderate efforts.

• Disadvantages:
o Difficult to debug.
o Difficult to show branching and looping.
o Jumping (goto) makes it hard to trace some problems.

6.1. Algorithm Examples


• Write an algorithm to find out sum of two numbers.

Step 1: Start
Step 2: input two numbers: a, b
Step 3: calculate Sum = a + b
Step 4: print “total=”, sum
Step 5: stop

• Write an algorithm to find out area of square.

Step 1: Start
Step 2: input length : len
Step 3: calculate area = len * len
Step 4: print “area =”, area
Step 5: stop

• Write an algorithm to find average of three numbers.

Step 1: Start
Step 2: input three numbers: a, b, c
Step 3: calculate sum = a + b + c

Prepared by – Prof. Viral H. Panchal 20


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

Step 4: avg = sum / 3


Step 5: print “average =”, avg

• Write an algorithm to find whether given number is positive or negative.

Step 1: Start
Step 2: input number: num
Step 3: Check if num < 0 then go to step 6
Step 4: print “positive”
Step 5: stop
Step 6: print “negative”
Step 7: stop

• Write an algorithm to find out minimum number from three input numbers.

Step 1: Start
Step 2: input three numbers: a, b, c
Step 3: if a < b then go to next step otherwise (else) go to step 9
Step 4: if a < c then go to next step else go to step 7
Step 5: print “minimum =”, a
Step 6: stop
Step 7: print “minimum =”, c
Step 8: stop
Step 9: if b < c then go to next step else go to step 12
Step 10: print “minimum =”, b
Step 11: stop
Step 12: print “minimum =”, c
Step 13: stop

• Write an algorithm to find factorial of given number.

Step 1: Start
Step 2: input number: num
Step 3: i = 1
Step 4: f = 1
Step 5: repeat from step 6 to step 7 until i <= num

Prepared by – Prof. Viral H. Panchal 21


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

Step 6: f = f * I
Step 7: i = i + 1
Step 8: print “factorial =”, f
Step 9: stop

• Write an algorithm to reverse given number.

Step 1: Start
Step 2: input number: num
Step 3: sum = 0
Step 4: repeat from step 5 to step 7 until num > 0
Step 5: calculate r = num % 10
Step 6: calculate sum = sum * 10 + r
Step 7: calculate num = num / 10
Step 8: print “reverse number =”, sum
Step 9: stop

• Write an algorithm to solve following series: 1! + 2! + 3! + ….. + n!

Step 1: Start
Step 2: input number: num
Step 3: f = 1
Step 4: sum = 0
Step 5: I = 1
Step 6: repeat from step 7 to step 8 until I <= num
Step 7: f = f * I
Step 8: sum = sum + f
Step 9: I = I + 1
Step 10: print “sum =”, sum
Step 11: stop

• Write an algorithm to find whether given number is Armstrong or not.

Step 1: Start
Step 2: input number: num
Step 3: sum = 0, temp = num // store num to temp

Prepared by – Prof. Viral H. Panchal 22


Programming for Problem Solving (3110003) Chapter – 1: Introduction to computer and programming

Step 4: repeat from step 5 to step 7 until num > 0


Step 5: calculate r = num % 10
Step 6: calculate sum = sum + r * r * r
Step 7: calculate num = num / 10
Step 8: if temp = sum then next step else go to step 10
Step 9: print temp, “is Armstrong number”
Step 10: stop
Step 11: print temp, “is not Armstrong number”
Step 12: stop

Prepared by – Prof. Viral H. Panchal 23

You might also like