0% found this document useful (0 votes)
17 views63 pages

Computer Fundamentals and Generations

This document provides an overview of computers, detailing their functionalities, advantages, and disadvantages. It also discusses the five generations of computers, their characteristics, and types such as PCs, workstations, minicomputers, mainframes, and supercomputers. Additionally, it describes the components of a computer, including the CPU, memory, and input/output devices.
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)
17 views63 pages

Computer Fundamentals and Generations

This document provides an overview of computers, detailing their functionalities, advantages, and disadvantages. It also discusses the five generations of computers, their characteristics, and types such as PCs, workstations, minicomputers, mainframes, and supercomputers. Additionally, it describes the components of a computer, including the CPU, memory, and input/output devices.
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

CHAPTER

Overview

T world is an information-rich world and it has become a necessity for everyone to know about

computers. Purpose of this tutorial is to introduce you about computer and its fundamentals.

Functionalities of a computer
Any digital computer carries out five functions in gross terms:

Takes data as input.

Stores the data/instructions in its memory and use them when required.

Processes the data and converts it into useful information.

Generates the output

Controls all the above four steps.

Definition
Computer is an electronic data processing device which

accepts and stores data input,

processes the data input, and

8
generates the output in a required format.

Advantages
Following list demonstrates the advantages of computers in today's arena.

High Speed
Computer is a very fast device.

It is capable of performing calculation of very large amount of data.

The computer has units of speed in microsecond, nanosecond, and even the picosecond.

It can perform millions of calculations in a few seconds as compared to man who will spend many months for
doing the same task.

Accuracy
In addition to being very fast, computers are very accurate.

The calculations are 100% error free.

Computers perform all jobs with 100% accuracy provided that correct input has been given.

Storage Capability
Memory is a very important characteristic of computers.

A computer has much more storage capacity than human beings.

It can store large amount of data.

It can store any type of data such as images, videos, text, audio and many others.

Diligence
Unlike human beings, a computer is free from monotony, tiredness and lack of concentration.

It can work continuously without any error and boredom.

It can do repeated work with same speed and accuracy.

Versatility
A computer is a very versatile machine.

A computer is very flexible in performing the jobs to be done.

9
This machine can be used to solve the problems related to various fields.

At one instance, it may be solving a complex scientific problem and the very next moment it may be playing a
card game.

Reliability
A computer is a reliable machine.

Modern electronic components have long lives.

Computers are designed to make maintenance easy.

Automation
Computer is an automatic machine.

Automation means ability to perform the given task automatically.

Once a program is given to computer i.e. stored in computer memory, the program and instruction can
control the program execution without human interaction.

Reduction in Paper Work


The use of computers for data processing in an organization leads to reduction in paper work and results in
speeding up a process.

As data in electronic files can be retrieved as and when required, the problem of maintenance of large
number of paper files gets reduced.

Reduction in Cost
Though the initial investment for installing a computer is high but it substantially reduces the cost of each of
its transaction.

Disadvantages
Following list demonstrates the disadvantages of computers in today's arena.

No I.Q
A computer is a machine that has no intelligence to perform any task.

Each instruction has to be given to computer.

A computer cannot take any decision on its own.

10
Dependency
It functions as per a user instruction, so it is fully dependent on human being.

Environment
The operating environment of computer should be dust free and suitable.

No Feeling
Computers have no feelings or emotions.

It cannot make judgment based on feeling, taste, experience, and knowledge unlike a human being.

11
CHAPTER

Generations
Computer Generations

G eneration in computer terminology is a change in technology a computer is/was being used. Initially, the

generation term was used to distinguish between varying hardware technologies. But nowadays, generation
includes both hardware and software, which together make up an entire computer system.

There are totally five computer generations known till date. Each generation has been discussed in detail along
with their time period and characteristics. Here approximate dates against each generations have been mentioned
which are normally accepted.

Following are the main five generations of computers

S.N. Generation and Description

First Generation
1
The period of first generation: 1946-1959. Vacuum tube based.

Second Generation
2
The period of second generation: 1959-1965. Transistor based.

Third Generation
3
The period of third generation: 1965-1971. Integrated Circuit based.

Fourth Generation
4
The period of fourth generation: 1971-1980. VLSI microprocessor based.

Fifth Generation
5
The period of fifth generation: [Link] microprocessor based

First Generation
The period of first generation was 1946-1959. The computers of first generation used vacuum tubes as the basic
components for memory and circuitry for CPU (Central Processing Unit). These tubes, like electric bulbs, produced
a lot of heat and were prone to frequent fusing of the installations, therefore, were very expensive and could be
afforded only by very large organisations. In this generation mainly batch processing operating system were used.
Punched cards, paper tape, and magnetic tape were used as input and output devices. The computers in this
generation used machine code as programming language.

21
The main features of first generation are:

Vacuum tube technology

Unreliable

Supported machine language only

Very costly

Generated lot of heat

Slow input and output devices

Huge size

Need of A.C.

Non-portable

Consumed lot of electricity

Some computers of this generation were:

ENIAC

EDVAC

22
UNIVAC

IBM-701

IBM-650

Second Generation
The period of second generation was 1959-1965. In this generation transistors were used that were cheaper,
consumed less power, more compact in size, more reliable and faster than the first generation machines made of
vacuum tubes. In this generation, magnetic cores were used as primary memory and magnetic tape and magnetic
disks as secondary storage devices. In this generation assembly language and high-level programming languages
like FORTRAN, COBOL were used. The computers used batch processing and multiprogramming operating
system.

The main features of second generation are:

Use of transistors

Reliable in comparison to first generation computers

Smaller size as compared to first generation computers

Generated less heat as compared to first generation computers

Consumed less electricity as compared to first generation computers

Faster than first generation computers

Still very costly

23
A.C. needed

Supported machine and assembly languages

Some computers of this generation were:

IBM 1620

IBM 7094

CDC 1604

CDC 3600

UNIVAC 1108

Third Generation
The period of third generation was 1965-1971. The computers of third generation used integrated circuits (IC's) in
place of transistors. A single IC has many transistors, resistors and capacitors along with the associated circuitry.
The IC was invented by Jack Kilby. This development made computers smaller in size, reliable and efficient. In this
generation remote processing, time-sharing, multi-programming operating system were used. High-level languages
(FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68 etc.) were used during this generation.

The main features of third generation are:

IC used

More reliable in comparison to previous two generations

Smaller size

Generated less heat

24
Faster

Lesser maintenance

Still costly

A.C needed

Consumed lesser electricity

Supported high-level language

Some computers of this generation were:

IBM-360 series

Honeywell-6000 series

PDP(Personal Data Processor)

IBM-370/168

TDC-316

Fourth Generation
The period of fourth generation was 1971-1980. The computers of fourth generation used Very Large Scale
Integrated (VLSI) circuits. VLSI circuits having about 5000 transistors and other circuit elements and their
associated circuits on a single chip made it possible to have microcomputers of fourth generation. Fourth
generation computers became more powerful, compact, reliable, and affordable. As a result, it gave rise to
personal computer (PC) revolution. In this generation time sharing, real time, networks, distributed operating
system were used. All the high-level languages like C, C++, DBASE etc. were used in this generation.

25
The main features of fourth generation are:

VLSI technology used

Very cheap

Portable and reliable

Use of PC's

Very small size

Pipeline processing

No A.C. needed

Concept of internet was introduced

Great developments in the fields of networks

Computers became easily available

Some computers of this generation were:

DEC 10

STAR 1000

26
PDP 11

CRAY-1(Super Computer)

CRAY-X-MP(Super Computer)

Fifth Generation
The period of fifth generation is 1980-till date. In the fifth generation, the VLSI technology became ULSI (Ultra
Large Scale Integration) technology, resulting in the production of microprocessor chips having ten million
electronic components. This generation is based on parallel processing hardware and AI (Artificial Intelligence)
software. AI is an emerging branch in computer science, which interprets means and method of making computers
think like human beings. All the high-level languages like C and C++, Java, .Net etc. are used in this generation.

AI includes:

Robotics

Neural networks

Game Playing

Development of expert systems to make decisions in real life situations.

Natural language understanding and generation.

The main features of fifth generation are:

ULSI technology

27
Development of true artificial intelligence

Development of Natural language processing

Advancement in Parallel Processing

Advancement in Superconductor technology

More user friendly interfaces with multimedia features

Availability of very powerful and compact computers at cheaper rates

Some computer types of this generation are:

Desktop

Laptop

NoteBook

UltraBook

ChromeBook

28
CHAPTER

Types

C omputers can be broadly classified by their speed and computing power.

Sr. No. Type Specifications

PC (Personal It is a single user computer system having moderately powerful


1
Computer) microprocessor

It is also a single user computer system which is similar to personal


2 WorkStation
computer but have more powerful microprocessor.

It is a multi-user computer system which is capable of supporting


3 Mini Computer
hundreds of users simultaneously.

It is a multi-user computer system which is capable of supporting


4 Main Frame hundreds of users simultaneously. Software technology is different
from minicomputer.

It is an extremely fast computer which can execute hundreds of


5 Supercomputer
millions of instructions per second.

PC (Personal Computer)
A PC can be defined as a small, relatively inexpensive computer designed for an individual user. PCs are based
on the microprocessor technology that enables manufacturers to put an entire CPU on one chip. Businesses use
personal computers for word processing, accounting, desktop publishing, and for running spreadsheet and
database management applications. At home, the most popular use for personal computers is playing games and
surfing Internet.

Although personal computers are designed as single-user systems, these systems are normally linked together to
form a network. In terms of power, now-a-days High-end models of the Macintosh and PC offer the same
computing power and graphics capability as low-end workstations by Sun Microsystems, Hewlett-Packard, and
Dell.

29
Workstation
Workstation is a computer used for engineering applications (CAD/CAM), desktop publishing, software
development, and other such types of applications which require a moderate amount of computing power and
relatively high quality graphics capabilities.

Workstations generally come with a large, high-resolution graphics screen, large amount of RAM, inbuilt network
support, and a graphical user interface. Most workstations also have a mass storage device such as a disk drive,
but a special type of workstation, called a diskless workstation, comes without a disk drive.

Common operating systems for workstations are UNIX and Windows NT. Like PC, Workstations are also single-
user computers like PC but are typically linked together to form a local-area network, although they can also be
used as stand-alone systems.

Minicomputer
It is a midsize multi-processing system capable of supporting up to 250 users simultaneously.

30
Mainframe
Mainframe is very large in size and is an expensive computer capable of supporting hundreds or even thousands
of users simultaneously. Mainframe executes many programs concurrently and supports many simultaneous
execution of programs.

Supercomputer
Supercomputers are one of the fastest computers currently available. Supercomputers are very expensive and are
employed for specialized applications that require immense amount of mathematical calculations (number
crunching). For example, weather forecasting, scientific simulations, (animated) graphics, fluid dynamic
calculations, nuclear energy research, electronic design, and analysis of geological data (e.g. in petrochemical
prospecting).

31
32
CHAPTER

Components

A ll types of computers follow a same basic logical structure and perform the following five basic

operations for converting raw input data into information useful to their users

Sr. No. Operation Description

1 Take Input The process of entering data and instructions into the computer system.

Saving data and instructions so that they are available for processing as and
2 Store Data
when required.

Performing arithmetic, and logical operations on data in order to convert them


3 Processing Data
into useful information.

The process of producing useful information or results for the user, such as a
4 Output Information
printed report or visual display.

Directs the manner and sequence in which all of the above operations are
5 Control the workflow
performed.

33
Input Unit
This unit contains devices with the help of which we enter data into computer. This unit makes link between user
and computer. The input devices translate the information into the form understandable by computer.

CPU (Central Processing Unit)


CPU is considered as the brain of the computer. CPU performs all types of data processing operations. It stores
data, intermediate results and instructions(program).It controls the operation of all parts of computer.

CPU itself has following three components

ALU(Arithmetic Logic Unit)

Memory Unit

Control Unit

Output Unit
Output unit consists of devices with the help of which we get the information from computer. This unit is a link
between computer and users. Output devices translate the computer's output into the form understandable by
users.

34
CHAPTER

CPU Central Processing Unit

C PU consists of the following features:

CPU is considered as the brain of the computer.

CPU performs all types of data processing operations.

It stores data, intermediate results and instructions(program).

It controls the operation of all parts of computer.

CPU itself has following three components.

Memory or Storage Unit:

Control Unit

ALU(Arithmetic Logic Unit)

35
Memory or Storage Unit:
This unit can store instructions, data and intermediate results. This unit supplies information to the other units of
the computer when needed. It is also known as internal storage unit or main memory or primary storage or
Random access memory(RAM).

Its size affects speed, power and capability. Primary memory and secondary memory are two types of memories
in the computer. Functions of memory unit are:

It stores all the data and the instructions required for processing.

It stores intermediate results of processing.

It stores final results of processing before these results are released to an output device.

All inputs and outputs are transmitted through main memory.

Control Unit
This unit controls the operations of all parts of computer but does not carry out any actual data processing
operations.

Functions of this unit are:

It is responsible for controlling the transfer of data and instructions among other units of a computer.

It manages and coordinates all the units of the computer.

It obtains the instructions from the memory, interprets them, and directs the operation of the computer.

It communicates with Input/Output devices for transfer of data or results from storage.

It does not process or store data.

36
ALU(Arithmetic Logic Unit)
This unit consists of two subsections namely

Arithmetic section

Logic Section

Arithmetic Section
Function of arithmetic section is to perform arithmetic operations like addition, subtraction, multiplication and
division. All complex operations are done by making repetitive use of above operations.

Logic Section
Function of logic section is to perform logic operations such as comparing, selecting, matching and merging of
data.

37
CHAPTER

Input Devices

F ollowing are few of the important input devices which are used in a computer:

Keyboard

Mouse

Joy Stick

Light pen

Track Ball

Scanner

Graphic Tablet

Microphone

Magnetic Ink Card Reader(MICR)

Optical Character Reader(OCR)

Bar Code Reader

Optical Mark Reader(OMR)

Keyboard
Keyboard is the most common and very popular input device which helps in inputting data to the computer. The
layout of the keyboard is like that of traditional typewriter, although there are some additional keys provided for
performing additional functions.

Keyboards are of two sizes 84 keys or 101/102 keys, but now keyboards with 104 keys or 108 keys are also
available for Windows and Internet.

38
CHAPTER

Output Devices

F ollowing are few of the important output devices which are used in a computer

Monitors

Graphic Plotter

Printer

Monitors
Monitors, commonly called as Visual Display Unit (VDU), are the main output device of a computer. It forms
images from tiny dots, called pixels that are arranged in a rectangular form. The sharpness of the image depends
upon the number of pixels.

There are two kinds of viewing screen used for monitors.

Cathode-Ray Tube (CRT)

Flat- Panel Display

Cathode-Ray Tube (CRT) Monitor


The CRT display is made up of small picture elements called pixels. The smaller the pixels, the better the image
clarity, or resolution. It takes more than one illuminated pixel to form whole character, such as the letter e in the
word help.

A finite number of characters can be displayed on a screen at once. The screen can be divided into a series of
character boxes - fixed location on the screen where a standard character can be placed. Most screens are
capable of displaying 80 characters of data horizontally and 25 lines vertically. There are some disadvantages of
CRT

Large in Size

High power consumption

46
CHAPTER

Memory

A memory is just like a human brain. It is used to store data and instructions. Computer memory is the

storage space in computer where data is to be processed and instructions required for processing are stored. The
memory is divided into large number of small parts called cells. Each location or cell has a unique address which
varies from zero to memory size minus one. For example if computer has 64k words, then this memory unit has 64
* 1024=65536 memory locations. The address of these locations varies from 0 to 65535.

Memory is primarily of three types

Cache Memory

Primary Memory/Main Memory

Secondary Memory

Cache Memory
Cache memory is a very high speed semiconductor memory which can speed up CPU. It acts as a buffer between
the CPU and main memory. It is used to hold those parts of data and program which are most frequently used by
CPU. The parts of data and programs are transferred from disk to cache memory by operating system, from where
CPU can access them.

Advantages
The advantages of cache memory are as follows

Cache memory is faster than main memory.

It consumes less access time as compared to main memory.

It stores the program that can be executed within a short period of time.

It stores data for temporary use.

Disadvantages
The disadvantages of cache memory are as follows

55
Cache memory has limited capacity.

It is very expensive.

Primary Memory (Main Memory)


Primary memory holds only those data and instructions on which computer is currently working. It has limited
capacity and data is lost when power is switched off. It is generally made up of semiconductor device. These
memories are not as fast as registers. The data and instruction required to be processed reside in main memory. It
is divided into two subcategories RAM and ROM.

Characteristics of Main Memory


These are semiconductor memories.

It is known as main memory.

Usually volatile memory.

Data is lost in case power is switched off.

It is working memory of the computer.

Faster than secondary memories.

A computer cannot run without primary memory.

56
Secondary Memory
This type of memory is also known as external memory or non-volatile. It is slower than 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. Contents of secondary memories are first transferred to main memory, and
then CPU can access it. For example: disk, CD-ROM, DVD etc.

Characteristic of Secondary Memory


These are magnetic and optical memories.

It is known as backup memory.

It is non-volatile memory.

Data is permanently stored even if power is switched off.

It is used for storage of data in a computer.

Computer may run without secondary memory.

Slower than primary memories.

57
58
CHAPTER

Random Access Memory

R AM(Random Access Memory) is the internal memory of the CPU for storing data, program and program

result. It is read/write memory which stores data until the machine is working. As soon as the machine is switched
off, data is erased.

Access time in RAM is independent of the address that is, each storage location inside the memory is as easy to
reach as other locations and takes the same amount of time. Data in the RAM can be accessed randomly but it is
very expensive.

RAM is volatile, i.e. data stored in it is lost when we switch off the computer or if there is a power failure. Hence a
backup uninterruptible power system(UPS) is often used with computers. RAM is small, both in terms of its
physical size and in the amount of data it can hold.

RAM is of two types

Static RAM (SRAM)

Dynamic RAM (DRAM)

59
Static RAM (SRAM)
The word static indicates that the memory retains its contents as long as power is being supplied. However, data
is lost when the power gets down due to volatile nature. SRAM chips use a matrix of 6-transistors and no
capacitors. Transistors do not require power to prevent leakage, so SRAM need not have to be refreshed on a
regular basis.

Because of the extra space in the matrix, SRAM uses more chips than DRAM for the same amount of storage
space, thus making the manufacturing costs higher. So SRAM is used as cache memory and has very fast access.

Characteristic of the Static RAM


It has long life

There is no need to refresh

Faster

Used as cache memory

Large size

Expensive

High power consumption

Dynamic RAM (DRAM)


DRAM, unlike SRAM, must be continually refreshed in order to maintain the data. This is done by placing the
memory on a refresh circuit that rewrites the data several hundred times per second. DRAM is used for most
system memory because it is cheap and small. All DRAMs are made up of memory cells which are composed of
one capacitor and one transistor.

Characteristics of the Dynamic RAM


It has short data lifetime

Need to be refreshed continuously

Slower as compared to SRAM

Used as RAM

Lesser in size

Less expensive

Less power consumption

60
CHAPTER

Read Only Memory

R OM stands for Read Only Memory. The memory from which we can only read but cannot write on it. This

type of memory is non-volatile. The information is stored permanently in such memories during manufacture. A
ROM, stores such instructions that are required to start a computer. This operation is referred to as bootstrap.
ROM chips are not only used in the computer but also in other electronic items like washing machine and
microwave oven.

Following are the various types of ROM

MROM (Masked ROM)


The very first ROMs were hard-wired devices that contained a pre-programmed set of data or instructions. These
kind of ROMs are known as masked ROMs which are inexpensive.

61
PROM (Programmable Read only Memory)
PROM is read-only memory that can be modified only once by a user. The user buys a blank PROM and enters
the desired contents using a PROM program. Inside the PROM chip there are small fuses which are burnt open
during programming. It can be programmed only once and is not erasable.

EPROM(Erasable and Programmable Read Only Memory)


The EPROM can be erased by exposing it to ultra-violet light for a duration of up to 40 minutes. Usually, an
EPROM eraser achieves this function. During programming, an electrical charge is trapped in an insulated gate
region. The charge is retained for more than ten years because the charge has no leakage path. For erasing this
charge, ultra-violet light is passed through a quartz crystal window(lid). This exposure to ultra-violet light dissipates
the charge. During normal use the quartz lid is sealed with a sticker.

EEPROM
(Electrically Erasable and Programmable Read Only
Memory)
The EEPROM is programmed and erased electrically. It can be erased and reprogrammed about ten thousand
times. Both erasing and programming take about 4 to 10 ms (milli second). In EEPROM, any location can be
selectively erased and programmed. EEPROMs can be erased one byte at a time, rather than erasing the entire
chip. Hence, the process of re-programming is flexible but slow.

Advantages of ROM
The advantages of ROM are as follows:

Non-volatile in nature

These cannot be accidentally changed

Cheaper than RAMs

Easy to test

More reliable than RAMs

These are static and do not require refreshing

Its contents are always known and can be verified

62
CHAPTER

Memory Units

M emory unit is:

the amount of data that can be stored in the storage unit.

that in which storage capacity is expressed in terms of Bytes.

Following are the main memory storage units:

Sr. No. Unit Description

Bit (Binary A binary digit is logical 0 and 1 representing a passive or an active state of a
1
Digit) component in an electric circuit.

2 Nibble A group of 4 bits is called nibble.

A group of 8 bits is called byte. A byte is the smallest unit which can represent a
3 Byte
data item or a character.

A computer word, like a byte, is a group of fixed number of bits processed as a unit
which varies from computer to computer but is fixed for each computer.
4 Word The length of a computer word is called word-size or word length and it may be as
small as 8 bits or may be as long as 96 bits. A computer stores the information in
the form of computer words.

65
Few higher storage units are following

Sr. No. Unit Description

1 Kilobyte (KB) 1 KB = 1024 Bytes

2 Megabyte (MB) 1 MB = 1024 KB

3 GigaByte (GB) 1 GB = 1024 MB

4 TeraByte (TB 1 TB = 1024 GB

5 PetaByte (PB) 1 PB = 1024 TB

66
CHAPTER

Operating System

It is a program with following features:

An operating system is a program that acts as an interface between the software and the computer
hardware.

It is an integrated set of specialised programs that are used to manage overall resources and operations of
the computer.

It is specialised software that controls and monitors the execution of all other programs that reside in the
computer, including application programs and other system software.

Objectives of Operating System


To make a computer system convenient to use in an efficient manner

To hide the details of the hardware resources from the users

To provide users a convenient interface to use the computer system

To act as an intermediary between the hardware and its users and making it easier for the users to access
and use other resources

To manage the resources of a computer system

To keep track of who is using which resource, granting resource requests, according for resource using and
mediating conflicting requests from different programs and users

To provide efficient and fair sharing of resources among users and programs

92
Characteristics of Operating System
Memory Management -- keeps tracks of primary memory i.e. what part of it is in use by whom, what part is
not in use etc. and allocates the memory when a process or program requests it.

Processor Management -- allocates the processor(CPU) to a process and deallocates processor when it is
no longer required.

Device Management -- keeps track of all devices. This is also called I/O controller that decides which
process gets the device, when, and for how much time.

File Management -- allocates and de-allocates the resources and decides who gets the resources.

Security -- prevents unauthorized access to programs and data by means of passwords and similar other
techniques.

Job accounting -- keeps track of time and resources used by various jobs and/or users.

Control over system performance -- records delays between request for a service and from the system.

Interaction with the operators -- The interaction may take place via the console of the computer in the
form of instructions. Operating System acknowledges the same, does the corresponding action and informs
the operation by a display screen.
Error-detecting aids -- Production of dumps, traces, error messages and other debugging and error-
detecting methods.

Coordination between other software and users -- Coordination and assignment of compilers,
interpreters, assemblers and other software to the various users of the computer systems.

93
Generations and Classification of programming languages:
There are five generations of Programming languages. They are:
First Generation Languages:
These are low-level languages like machine language (0/1).
Second Generation Languages:
These are low-level assembly languages used in kernels and hardware drives.
Third Generation Languages:
These are high-level languages like C, C++, Java, Visual Basic, and JavaScript.
Fourth Generation Languages:
These are languages that consist of statements that are similar to statements in the human
language. These are used mainly in database programming and scripting. Examples of these
languages include Perl, Python, Ruby, SQL, MATLAB (Matrix Laboratory).
Fifth Generation Languages:
These are the programming languages that have visual tools to develop a program. Examples
of fifth-generation languages include Mercury, OPS5, and Prolog.
The first two generations are called low-level languages. The next three generations are
called high-level languages.

Compiler and interpreter


A compiler translates the entire source code in a single run. An interpreter translates the entire
source code line by line.
Loading and Linking
Loading:
Bringing the program from secondary memory to main memory for execution is called
Loading.
Linking:
Establishing the link between all the modules or all the functions of the program in order to
continue the program execution is called linking.
The key difference between linking and loading is that the linking generates the
executable file of a program whereas, the loading loads the executable file obtained from
the linking into main memory for execution.

Flowchart and Algorithm


Flowchart is a diagrammatic /graphical representation of sequence of steps to solve a problem.
To draw a flowchart following standard symbols are use

Advantages of flowchart:
• Easy and efficient to analyse problem, plays the role of a blueprint for a program.

An algorithm is a sequence of steps to solve a particular problem in a finite time.


Algorithm has the following characteristics
• Input: An algorithm may or may not require input.
• Output: Each algorithm is expected to produce at least one result.
• Definiteness: Each instruction must be clear and unambiguous.
• Finiteness: If the instructions of an algorithm are executed, the algorithm should terminate
after finite number of steps.
Advantages of algorithm
• It is a step-wise representation of a solution to a given problem, which makes it easy to
understand.
• It is not dependent on any programming language, so it is easy to understand for anyone even
without programming knowledge.
UNIT 2: BASICS OF C
Constants, Variables and Keywords
The alphabets, digits and special symbols when properly combined form constants, variables
and keywords. A constant is an entity that doesn't change, whereas, a variable is an entity that
may change. A keyword is a word that carries special meaning. In programming languages,
constants are often called literals, whereas variables are called identifiers.
Types of C Constants
Constants in C can be divided into two major categories:
(a) Primary Constants
(b) Secondary Constants

Integer constant: No decimal point


Real constant: Must have a decimal point
The allowable range for integer constants is -2147483648 to +2147483647.
Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
A character constant is a single alphabet, a single digit or a single special symbol enclosed
within single inverted commas. E.g., ‘A’, ‘5’.
Types of C Variables
A particular type of variable can hold only the same type of constant. For example, an integer
variable can hold only an integer constant, a real variable can hold only a real constant and a
character variable can hold only a character constant. Hence there are as many types of
variables in C, as the types of constants in it.
C Keywords
Keywords are the words whose meaning has already been explained to the C compiler (or in a
broad sense to the computer). There are only 32 keywords available in C.
The keywords should not be used as variable names. However, some C compilers allow you to
construct variable names that exactly resemble the keywords.
The First C Program
#include <stdio.h>
int main ()
{
int p, n;
float r, si;
p = 1000;
n = 3;
r = 8.5;
/* formula for simple interest */
si = p * n * r / 100;
printf (“%f\n”, si);
return 0;
}
Each instruction in a C program is written as a separate statement.
The statements in a program must appear in the same order in which we wish them to be
executed.
Blank spaces may be inserted between two words to improve the readability of the statement.
All statements should be in lower case letters.
Every C statement must end with a semicolon (;). Thus ; acts as a statement terminator.
Comments are used in a C program to clarify either the purpose of the program or the purpose
of some statement in the program. They should be enclosed within /* */.
main():
main() is a function. It is a container for a set of statements. A C program may have multiple
functions. If it contains only one function its name has to be main() . All statements that belong
to main() are enclosed within a pair of braces {}.
main( )
{
statement 1 ;
statement 2 ;
statement 3 ;
}
Like functions in a calculator, functions in C also return a value. main() function always returns
an integer value, hence there is an int before main() . It is known as return type of the function.
The integer value that we are returning is 0. 0 indicates success. If statements in main() fail to
do their intended work, we can return a non-zero number from main() . This would indicate
failure. Some compilers like Turbo C/C++ even permit us to return nothing from main() . In
such a case we should precede it with the keyword void.
Variables: Declaration, initialization, usage
Any variable used in the program must be declared (initialized if needed) before it is used.
The arithmetic operators available in C are +, -, * and /
Data Types:
The primary data types could be of three varieties— char, int, and float. Each of them has
several sub-types.
C offers two variations of the integer data type – short and long. Each of these integers has
two further variations – signed and unsigned. In the signed variety, the highest (leftmost) bit
stores the sign of the number 0, if the number is positive, and 1, if the number is negative.
Parallel to integers, char s also can be signed or unsigned.
Reals – float, double, long double.
C does not contain any keyword to display output on the screen. All output to screen is achieved
using readymade library functions like printf( ). To be able to use the printf() function, it is
necessary to use #include <stdio.h> at the beginning of the program. #include is a pre-
processor directive.
The general form of printf( ) function is,
printf ( "<format string>", <list of variables> ) ;
<format string> can contain,
%f for printing real values
%d for printing integer values
%c for printing character values
In addition to format specifiers like %f, %d and %c the format string may also contain any
other characters. These characters are printed as they are when the printf( ) is executed.
Following are some examples of usage of printf( ) function:
printf ( "%f ", si ) ;
printf ( "%d %d %f %f ", p, n, r, si ) ;
printf ( "Simple interest = Rs. %f ", si ) ;
printf ( "Principal = %d \nRate = %f ", p, r ) ;
The output of the last statement would look like this...
Principal = 1000
Rate = 8.5
What is ‘\n’ doing in this statement? It is called newline and it takes the cursor to the next line.
printf( ) can not only print values of variables, it can also print the result of an expression. An
expression is nothing but a valid combination of constants, variables and operators.
File inclusion: Header file
File inclusion is a pre-processor directive.
The format is #include <filename>
It causes the entire contents of filename to be inserted into the source code where we have used
#include. It is common for the files that are to be included to have a .h extension. This extension
stands for ‘header file’, as its contents when included go to the head of your program. The
prototypes of all the library functions are grouped into different categories and then stored in
different header files. For example, prototypes of all maths related functions are stored in the
file ‘math.h’, prototypes of input/output functions are stored in the file ‘stdio.h’, ‘conio.h’.
Receiving Input:
To make the program general, the program itself should ask the user to supply the values for
variables through the keyboard during execution. This can be achieved using a function called
scanf() . It helps us receive input values them from the keyboard.

#include <stdio.h>
int main()
{
int p, n;
float r, si;
printf (“Enter values of p, n, r \n”); /* can be taken separately */
scanf (“%d %d %f ”, &p, &n, &r); /* can be taken separately */
si = p * n * r / 100;
printf (“%f\n”, si);
return 0;
}
The first printf() outputs the message ‘Enter values of p, n, r’ on the screen.
Note the use of ampersand ( & ) before the variables in the scanf() function is necessary. & is
the ‘Address of ’ operator. It gives the location number (address) used by the variable in
memory. When we say &a , we are telling scanf() at which memory location should it store
the value supplied by the user from the keyboard.
C Instructions:
There are three types of instructions in C:
(a) Type Declaration Instruction - This instruction is used to declare the type of variables
used in a C program.
(b) Arithmetic Instruction - This instruction is used to perform arithmetic operations on
constants and variables.
(c) Control Instruction - This instruction is used to control the sequence of execution of
various statements in a C program.
A variable must be defined before using it. The following statement is illegal since we are using
variable a before defining it.
float b = a + 3.1, a = 1.5;
The following statements would work
int a, b, c, d;
a = b = c = 10;
However, the following statement would not work
int a = b = c = d = 10;
Once again, we are trying to use b (to assign to a) before defining it.
C allows only one variable on left-hand side of = . That is, z = k * l is legal, whereas k * l = z
is illegal.
In addition to the division operator, C also provides a modular division operator. This operator
returns the remainder on dividing one integer with another. Thus, the expression 10 / 2 yields
5, whereas, 10 % 2 yields 0.
Note that the modulus operator ( % ) cannot be applied on a float. Also note that on using %,
sign of the remainder is always same as the sign of the numerator. Thus -5 % 2 yields -1,
whereas, 5 % -2 yields 1.
There is no operator in C to perform exponentiation operation. Exponentiation has to be carried
out as shown below:
float a;
a = pow (3.0, 2.0);
printf (“%f”, a);
Here pow() function is a standard library function. It is being used to raise 3.0 to the power of
2.0. The pow() function works only with real numbers, hence we have used 3.0 and 2.0.
Note that for pow() to work, it is necessary to #include <math.h> .
Hierarchy of Operations:
The priority or precedence in which the operations are performed is called the hierarchy of
operations. Parentheses has the highest priority followed by
Sum of n natural numbers:
#include<stdio.h>
int main()
{
int n = 9; // declare & initialize local variable n.
int sum = (n * (n + 1) ) / 2; /* define the mathematical formula to calculate the sum of given
number. */
printf("Sum of %d natural number is = %d", n, sum); // print the sum of natural number
return 0;
}

UNIT 3: CONTROL STATEMENTS


Decision Control
Loop Control
Case Control
Decision Control:
The if - else Statement:
C uses the keywords if and else to implement the decision control instruction. The general form
of this statement looks like this:
if (this condition is true)
statement1;
else
statement2;
The condition following the keyword if is always enclosed within a pair of parentheses. If the
condition is true (even any non-zero value), then statement1 is executed. If the condition is not
true (also if zero value), then statement2 is executed. The condition is expressed using
‘relational’ operators in C. These operators allow us to compare two values.
Here == is the equality operator and != the inequality operator. Note that = is used for
assignment, whereas, == is used for comparison of two quantities.
Multiple Statements within if - else
It may so happen that in a program we want more than one statement to be executed when the
expression following if is satisfied. If such multiple statements are to be executed, then they
must be placed within a pair of braces.
The default scope of if as well as else is the statement immediately after them. To override this
default scope, a pair of braces must be used.
Nested if-else
It is perfectly alright if we write another if-else construct within either the if block or the else
block. This is called ‘nesting’.

Example: Check whether an integer is odd or even


#include <stdio.h>
int main ()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number%2 == 0) {
printf("%d is an even integer.", number);
}
else
{
printf("%d is an odd integer.", number);
}
return 0;
}

Use of logical Operators:


C allows usage of three logical operators, namely, &&, || and !. These are to be read as ‘AND’,
‘OR’ and ‘NOT’ respectively. Of these, && and || operators allow two or more conditions to
be checked.
The else if Clause: In case of multiple if statements, all the conditions are checked even if the
required condition is satisfied. This increases the execution time. To avoid this, the else if
clause is used.
The Conditional Operators
The conditional operators ? and : are sometimes called ternary operators since they take three
arguments.
Their general form is,
expression 1 ? expression 2 : expression 3
What this expression says is: “if expression 1 is true, then the value returned will be expression
2 , otherwise the value returned will be expression 3 ”.
Ex:
int x, y;
scanf (“%d”, &x);
y = (x > 5 ? 3: 4);
This statement will store 3 in y if x is greater than 5, otherwise it will store 4 in y.

Loop Control:
The versatility of computer lies in its ability to perform a set of instructions repeatedly. This
involves repeating some portion of the program either a specified number of times or until a
particular condition is satisfied. This repetitive operation is done through a loop control
instruction. There are three ways to repeat a part of a program. They are:
(a) Using a while statement
(b) Using a for statement
(c) Using a do-while statement
The while loop:

Note the following points about while…


The statements within the while loop would keep getting executed till the condition being tested
remains true. When the condition becomes false, the control passes to the first statement that
follows the body of the while loop. Almost always, the while must test a condition that will
eventually become false, otherwise the loop would keep getting executed forever, indefinitely.
Instead of incrementing a loop counter, we can decrement it and still manage to get the body
of the loop executed repeatedly. This is shown below.
++i vs. i++
Both are increment operator, i++ is post-increment while ++i is pre-increment.
Sum of n natural numbers (Using While loop)
#include <stdio.h>
void main()
{
int num, i, sum = 0; // initialize and declare the local variables
printf("Enter a positive number : ");
scanf("%d", &num); // take a value up to which find the sum of n natural number
i = 0;
while (i <= num) // define the while loop and i should be less than num
{
sum = sum + i; // store the sum of natural number
i++; // increment by 1
}
// print the sum of natural number
printf(" \n Sum of first %d natural number is : %d", num, sum);
}
The do-while loop:

do
{
this;
and this;
} while (this condition is true);
There is a minor difference between the working of while and do-while loops. This difference
lies in the place where the condition is tested. The while tests the condition before executing
any of the statements within the while loop. As against this, the do-while tests the condition
after having executed the statements within the loop. This means that do-while would execute
its statements at least once, even if the condition fails for the first time. The while, on the other
hand will not execute its statements if the condition fails for the first time.
Sum of n natural numbers (Using do-while loop)
#include <stdio.h>
void main()
{
int num, i, sum = 0; // initialize and declare the local variables
printf("Enter a positive number: ");
scanf("%d", &num); // take a value up to which find the sum of natural number
i = 0;
do
{
sum = sum + i; // store the sum of natural number
i++; // increment by 1
} while (i <= num); // define the while loop and i should be less than num

// print the sum of natural number


printf(" \n Sum of first %d natural number is : %d", num, sum);
}
The for Loop:
The for loop allows us to specify three things about the loop in a single line:
(a) Setting a loop counter to an initial value.
(b) Testing the loop counter to determine whether its value has reached the number of
repetitions desired.
(c) Increasing the value of loop counter each time the body of the loop has been executed.
The general form of for loop is as under:
for (initialize counter; test counter; increment counter)
{
do this;
and this;
}

Sum of n natural numbers (Using For loop)


#include <stdio.h>
void main()
{
int num, i, sum = 0; // declare local variables
printf(" Enter a positive number: ");
scanf("%d", &num); // take any positive number
// executes until the condition remains true.
for (i = 0; i <= num; i++)
{
sum = sum + i; // at each iteration the value of i is added to the sum variable
}
// display the sum of natural number
printf("\n Sum of the first %d number is: %d", num, sum);
}
Nesting of Loops
The way if statements can be nested, similarly while and for can also be nested.

The break Statement


We often come across situations where we want to jump out of a loop instantly, without waiting
to get back to the condition. The keyword break allows us to do this. When break is
encountered inside any loop, control automatically passes to the first statement after the
loop.
The continue Statement
In some programming situations, we want to take the control to the beginning of the loop,
bypassing the statements inside the loop, which have not yet been executed. The keyword
continue allows us to do this. When continue is encountered inside any loop, control
automatically passes to the beginning of the loop.

Decisions using switch


The control instruction that allows us to make a decision from the number of choices is called
a switch, or more correctly a switch-case-default, since these three keywords go together to
make up the control statement. They most often appear as follows:
switch (integer expression)
{
case constant 1 :
do this;
case constant 2 :
do this;
case constant 3 :
do this;
default :
do this;
}
Example:
#include <stdio.h>
int main()
{
int i = 2;
switch (i)
{
case 1 :
printf (“I am in case 1 \n”);
break;
case 2 :
printf (“I am in case 2 \n”);
break;
case 3 :
printf (“I am in case 3 \n”);
break;
default :
printf (“I am in default \n”);
}
return 0;
}
The output of this program would be:
I am in case 2
The goto Keyword
It takes the control to where anywhere in the program that we want. Generally it is avoided.
exit() is a standard library function that terminates the execution of the program. For exit() to
work, we need to #include the file ‘stdlib.h’.
UNIT 4 & 5: Arrays, Pointers and Functions
Functions and pointers
A pointer is a variable whose value is the address of another variable.
Consider
int i = 3;

Q. What is address of i?
Q. What is value at i?

& Address of operator


* Value at address operator

Q. What will &i return?


Q. What will i return?
Q. What will *(&i) return?

Now what about


j = &i;
j stores the address of i.

But we can’t use j in a program without declaring it. And since j is a variable that contains the
address of i, it is declared as,
int *j;
This declaration tells the compiler that j will be used to store the address of an integer value.
In other words, j points to an integer.
How do we justify the usage of * in the declaration?
int *j;
int *j would mean, the value at the address contained in j is an int.
Consider the following program:
main()
{
int i = 3 ;
int *j ;
j = &i ;
printf ( "\nAddress of i = %u", &i ) ;
printf ( "\nAddress of i = %u", j ) ;
printf ( "\nAddress of j = %u", &j ) ;
printf ( "\nValue of j = %u", j ) ;
printf ( "\nValue of i = %d", i ) ;
printf ( "\nValue of i = %d", *( &i ) ) ;
printf ( "\nValue of i = %d", *j ) ;
}

The output of the above program would be:

Address of i = 65524
Address of i = 65524
Address of j = 65522
Value of j = 65524
Value of i = 3
Value of i = 3
Value of i = 3
Functions in C:
A function is a self-contained block of statements that perform a coherent task of some kind.

main( )
{
message( ) ;
printf ( "\n2" ) ;
}
message( )
{
printf ( "\n1" ) ;
}

Output:
1
2
main( ) becomes the ‘calling’ function, whereas message( ) becomes the ‘called’ function.

Why Use Functions?


Writing functions avoids rewriting the same code over and over.

Sum of n natural numbers (using function)


#include <stdio.h>
int natural_no(int num)
{
int i, sum = 0;
// use for loop until the condition becomes false
for (i = 0; i <= num; i++)
{
// adding the counter variable i to the sum value
sum = sum + i;
}
return sum;
}
void main()
{
int num, total; // local variable
printf("Enter a natural number: ");
scanf("%d", &num); // take a natural number from the user
total = natural_no(num); // call the function
printf(" Sum of the %d natural number is: %d", num, total);
}

Recursion
In C, it is possible for the functions to call themselves. A function is called ‘recursive’ if a
statement within the body of a function calls the same function. Sometimes called ‘circular
definition’, recursion is thus the process of defining something in terms of itself.

Factorial using recursion


#include<stdio.h>

long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}

void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);

fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
}

Call by Value and Call by reference:


While calling a function, we may pass values of variables to it. Such functions are known as
“Call by Values”.
While calling a function, instead of passing the values of variables, we may pass address of
variables (location of variables) to the function known as “Call by References”.
In call by values, we cannot alter the values of actual variables through function calls.
In call by reference, we can alter the values of variables through function calls.
Example: Call by value
#include<stdio.h>
void change (int num) {
printf("Before adding value inside function num=%d \n",num);
num=num+100;
printf("After adding value inside function num=%d \n", num);
}
int main () {
int x=100;
printf("Before function call x=%d \n", x);
change(x);//passing value in function
printf("After function call x=%d \n", x);
return 0;
}
Example: Call by reference
#include<stdio.h>
void change (int *num) {
printf("Before adding value inside function num=%d \n",*num);
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}
int main () {
int x=100;
printf("Before function call x=%d \n", x);
change(&x) ;//passing reference in function
printf("After function call x=%d \n", x);
return 0;
}

ARRAY:
Array is a collection of similar elements.
The first element in the array is numbered 0, so the last element is 1 less than the size of
the array. An array is also known as a subscripted variable. Before using an array, its type and
dimension must be declared. However big an array, its elements are always stored in
contiguous memory locations.

Array Declaration
int marks [30];
Here, int specifies the type of the variable, just as it does with ordinary variables and the word
marks specifies the name of the variable. The [30] however is new. The number 30 tells how
many elements of the type int will be in our array. This number is often called the ‘dimension’
of the array. The bracket [] tells the compiler that we are dealing with an array.
Accessing Elements of an Array

All the array elements are numbered, starting with 0. Thus, marks [2] is not the second element
of the array, but the third.

Array Initialisation

int num[6] = { 2, 4, 12, 5, 45, 5 } ;


int n[ ] = { 2, 4, 12, 5, 45, 5 } ;
float press[ ] = { 12.3, 34.2 -23.4, -11.3 } ;

Entering Data into an Array

Here is the section of code that places data into an array:

for ( i = 0 ; i <= 29 ; i++ )


{
printf ( "\nEnter marks " ) ;
scanf ( "%d", &marks[i] ) ;
}

Reading Data from an Array

for ( i = 0 ; i <= 29 ; i++ )


sum = sum + marks[i] ;
avg = sum / 30 ;
printf ( "\nAverage marks = %d", avg ) ;

An entire array or its elements can be passed to a function.


UNIT 6: Basic concepts of object-oriented programming

What is object-oriented programming?


Object-oriented programming (OOP) is a computer programming model that organizes
software design around data, or objects, rather than functions and logic. An object can be
defined as a data field that has unique attributes and behaviour.

What is the structure of object-oriented programming?


The structure of object-oriented programming includes the following:
Classes are user-defined data types that act as the blueprint for individual objects, attributes
and methods.
Objects are instances of a class created with specifically defined data.
Methods are functions that are defined inside a class that describe the behaviours of an object.
Attributes are defined in the class template and represent the state of an object. Objects will
have data stored in the attributes field. Class attributes belong to the class itself.

What are the main principles of OOP?


Encapsulation: This principle states that all important information is contained inside an
object and only select information is exposed.
Abstraction: Objects only reveal internal mechanisms that are relevant for the use of other
objects, hiding any unnecessary implementation code.
Inheritance: Classes can reuse code from other classes.
Polymorphism: Objects are designed to share behaviours and they can take on more than one
form. A child class is created, which extends the functionality of the parent class.

Popular pure OOP languages include: Ruby, Scala, JADE, Emerald


Programming languages designed primarily for OOP include: Java, Python, C++
Other programming languages that pair with OOP include: Visual Basic .NET, PHP,
JavaScript
What are the benefits of OOP?
Modularity: Encapsulation enables objects to be self-contained, making troubleshooting and
collaborative development easier.
Reusability: Code can be reused through inheritance, meaning a team does not have to write
the same code multiple times.
Productivity: Programmers can construct new programs quicker through the use of multiple
libraries and reusable code.
Easily upgradable and scalable: Programmers can implement system functionalities
independently.
Interface descriptions: Descriptions of external systems are simple, due to message passing
techniques that are used for objects communication.
Security: Using encapsulation and abstraction, complex code is hidden, software maintenance
is easier and internet protocols are protected.
Flexibility: Polymorphism enables a single function to adapt to the class it is placed in.
Different objects can also pass through the same interface.

You might also like