POP Module 1
POP Module 1
INTRODUCTION
COMPUTER GENERATIONS
The computer of each generation is smaller, faster and more powerful than preceding
generation. There are five computer generations.
➢ First Generation: The vacuum tubes were used for computation. Magnetic
drums were used for memory requirements. It consumed lot of space, power and
generated lot of power. ENIAC (Electronic Numerical Integrator and Computer) used
18000 vacuum tubes, 1800 acquired sq. ft. room space and consumed 180KW of power.
The machine level language (0s and 1s) was used. Punched cards were used for input
and Paper for output. They were used forscientific work.
➢ Second Generation: The transistors was the most important component which
replaced vacuum tubes. Magnetic cores were used for memory. It were more reliable
than first generation computer. The assembly or symbolic language was used. The input
and output mechanism remained same. The stored program concept was introduced
which stores both data and program.
able to perform parallel processing. The quad-core and octa-core was also introduced.
Neural networks and expert systems have been developed.
COMPUTER TYPES
Apart from being classified by generations, computers can also be categorized by their
size. Thesize of a computer is often an indirect indication of its capabilities.
➢ Supercomputers: These are huge machines having most powerful and fastest
processors. It uses multiple CPUs for parallel data processing. Speeds are measured in
flops (floating point operations per second). The fastest operates at 34 petaflops. They
are used for weather forecasting, analysis of geological data. They have enormous
storage, uses more power and generate lot of heat. They are used by government
agencies.
➢ Mainframes: These are multi-user machines that support many users using the
feature of time sharing. It can run multiple programs even with a single CPU. The
processor speed is measured in MIPS (Million instructions per second). It is used to
handle data, applications related to organization and online transactions in banks,
financial institutions and large corporations.
The ALU is a “super calculator” carrying out all arithmetic tasks and Boolean
operations(like AND, OR and NOT). The CU controls the way data is moved between
the variouscomponents of computer. Both ALU and CU use the service of clock for
synchronizing their Operations.
The CPU uses a few high-speed registers to store the current instruction and its
data. One of the registers, program counter, stores the address of next instruction to be
executed. All program instructions are executed using the fetch-decode-execute
mechanism. An instruction is first fetched from memory, decoded and then executed by
CPU. The CPU can execute one instruction in one clock pulse. Hence, faster the clock,ter
is the execution. The CPUs today are rated in GHz (gigahertz).
PRIMARY MEMORY
Memory: Collection of chips on motherboard, where all computer processing and
programinstructions are stored.
Primary Memory: It is the main memory, which stores data and programs, which are
currently needed by CPU. The size is less than the secondary memory and it is costly.
1. RAM (Random Access Memory): It is the main memory, where the user can
write information into RAM and read information from it. It is accessible to users.
The RAM is randomly accessible by user. It is a volatile memory, which means the
data, or information is retained as long as power supply is ON. There are two types
of RAM: SRAMand DRAM.
3. Cache Memory: It holds those portions of program that are frequently used by
CPU. It acts as a buffer between CPU and RAM. The CPU first looks for the
instructions in cache. It executes faster than RAM, expensive and limited in size. It
has multiple levels:
➢ L1 (Level 1) – smallest and fastest – 32 KB
➢ L2 (Level 2) – present closer to CPU – 256 KB
➢ L3 (Level 3) – shared by cores – 8 MB
4. Registers: The small number of ultra-fast registers integrated into the CPU
represent the fastest memory of the computer. The CPU does all its work here.
Each register has the length of the computer. The data is loaded into register
before processing. Registers are numbered and a program instruction specifies
these numbers. Ex: OR1R2R3 which means multiplication operation is performed
on R1 and R2 is performed and stored in R3.
SECONDARY MEMORY
Secondary memory is not directly connected to CPU. It exists inside the machine and
also externally. It is a non-volatile, offline and long-term storage memory. It is slower,
cheaper thanprimary memory but the capacity is higher.
1. Hard disk/ Hard drive/ Fixed disk: It is the oldest secondary storage device. It
has more capacity but, the cost is less comparatively. It is commonly present in
laptop with 500GB and desktop with 1TB. It contains a spindle, which holds one
or more platters made up of non-magnetic material. It has two surfaces which is
coated with magnetic material. Each surface has serially numbered tracks and
further broken into sectors or blocks. The disk runs with the speed of 5400 and
7200 rpm.
2. Magnetic tape: The magnetic tape is made up of plastic film with one side coated
with magnetic material. It supports 1 TB or more, but 200 TB are also expected.
The device is not fully portable though because, a separate tape drive is required.
The data is accessedsequentially. This makes it unsuitable for backup.
ray disk has the capacity upto 50 GB. A laser beam in their drives controls the
read and write operations. A laser beam is used to construct pits and lands by
burning selected areas along its tracks.
CD-R, DVD-R: Data can be recorded only once.
CD-RW, DVD-RW: Data can be recorded multiple times.
4. Flash Memory: It doesn’t have any moving parts, is based on the EEPROM. It is
available in various forms- pen drive, magnetic card (SD Card), solid state disk
(SSD). They are portable, need little power and quite reliable.
The memory stick or pen drive is the most common type of flash memory
used on the computer. It is a small, removable piece of circuit and it connects to
the USB port of computer.
The solid state disk is a bigger device meant to replace the traditional
magnetic hard disk.
The magnetic card is used mainly in cameras and the most popular is the
micro- SD card.
➢ SERIAL PORT: This port transfers one bit at a time serially. They are offered in 9-
pin and 25-pin configuration. They were used for connecting keyboard, mice, and
modems.
➢ PARALLEL PORT: This port is used to transfer data parallelly 8 bits at a time.
This is implemented using 25 pins and usually for printers.
➢ VGA (Video Graphics Array): This 15-pin port allows transfer of analog video
data to the monitor. This is replaced with DVI (Digital Video Interface) which uses
digital data i.e. usedby flat LCD panels.
➢ RJ45 port: This port is used by Ethernet network. Even though computer
connects wirelessly, the wired RJ45 remains as a useful option.
➢ PS/2 port: This port has replaced serial port. It has 6 pins but occurs as a pair in
two different colors. The ports and connectors for keyboard are purple, while the mouse
uses greenport. USB has invaded this area also.
➢ Pointing Devices: GUI (Graphical User Interfaces) like windows need a pointing
device to control the movement of cursor on the screen. This is implemented as mouse
in desktop and touchpad in laptop. The earliest form has a rotating ball and two buttons.
The left button is used for selecting (by clicking once) and execute (by clicking twice).
The right button is used to check and change attributes. The optical mouse uses infrared
laser/LED, the wireless mouse uses radio frequency technology.
scanners have OCR (Optical Character Recognition) facility which extracts text as a
stream of characters i.e. converting image file to text file and MICR (Magnetic Ink
Character Recognition) reads the codes using hand held barcode readers.
OUTPUT DEVICES
The information produced can be heard or seen with the help of output devices.
Some of theoutput devices are monitor, speaker, printer, plotter etc.
➢ Monitor: The monitor is an integral part of computer which displays both text
and graphics. The performance is measured in terms of image quality, resolution,
energy consumption.
CRT (Cathode Ray Tube) Monitors: The CRT monitors have a rarefied tube containing
three electron guns. The guns emit electrons create images. They usually have
resolution of 640*840 pixels. They are large, heavy, energy efficient and produces lot of
heat.
LCD (Liquid Crystal Display) Monitors: The image is formed by applying voltage on
crystals. The backlight is provided by fluorescent light. They consume less power,
generate less heat andhave increased life span.
➢ Impact Printers: It produces the hardcopy of output. The impact printers are old,
noisy.But, still dot-matrix printer is in usage.
Dot-Matrix Printer: The print head of the dot-matrix printer has either 9 or 24 pins.
When the pins fire against the ribbon, an impression is created on the paper. The speed
is 300 cps and doesn’t produce high quality output. It can produce multiple copies.
Daisy-wheel Printer: It employs a wheel with separate characters distributed along its
outer edge. The wheels can be changed to obtain different set of fonts.
Line Printer: For heavy printing, the line printer is used. It uses a print chain
containing the characters. Hammers strike the paper to print and it rotates at the speed
of 1200 lpm. It is alsonoisy and is of low-quality.
➢ Non-Impact Printers: They are fast, quiet and of high resolution. The most
commonly used non-impact printers are laser and ink-jet printers. The thermal printer
is not discussed here because it uses heat to print on high-sensitive paper.
Laser Printer: It works like a photocopier and uses toner i.e. black magnetic powder. The
image is created in the form of dots and passed from drums on to the paper. It has built-
in RAM which acts as buffer and RAM to store fonts. The resolution varies from 300 dpi
to 1200 dpi and the speed is about 20 ppm.
Ink-jet Printer: These are affordable printers. It sprays tiny drops of ink at high
pressure as it moves along the paper. The separate cartridges are available for different
colors. The resolutionis about 300 dpi, can print 1 to 6 pages/min.
➢ Plotters: The plotter can make drawings. It uses one or more automated pens.
The commands are taken from special file called vector graphic files. Depending on type
of plotter either paper or pen moves. It can handle large paper sizes and it is used for
creative drawings like buildings and machines. They are slow and expensive.
COMPUTERS IN A NETWORK
Most organizations, large or small, no longer have standalone computers. Computers
cooperate with one another by being connected in a network. The hardware resources
can also be shared. A printer can be used by several users if it is connected to a network.
Servers form the backbone of the largest network of all – Internet. Ethernet, token ring
hardware technologies are used to connect.
➢ Network Topology: The ways used to connect the computers. The different
types are: Bus, Star, Ring, and Mesh.
➢ Network Types: Networks are also classified on their size. The most common
types areLAN and WAN. And some other types are: MAN, CAN and PAN.
1. LAN (Local Area Network): They are used in smaller organizations usually
using Ethernet. The usual speed will be 100Mbps.
2. WAN (Wide Area Network): They are used in cities and can connect larger
distance.They use optic fiber cables. Banks, Airline and Hotel reservations use WANs.
3. MAN (Metropolitan Area Network): It is sandwiched between LAN and WAN
and usedfor interconnecting in same cities.
4. PAN (Personal Area Network): This is the smallest network and can connect
only fewmeters. It connects small devices like phones, laptops through Bluetooth.
➢ The Internet and internet: The internet (net) is the largest wide area network on
planet which runs with the help of network protocols. It grows continuously without
disturbing the existing structure. Intranet is a network of computers designed for a
specific group of users and can be accessed from Internet but with restrictions. Internet
is wide network of computers and is open for all and itself contains a large number of
intranets.
Note: The Internet (uppercase-I) is the set of all networks which are interconnected
and interoperate using the IETF standard protocols. An internet (lowercase-i) is any
network of devices which can communicate with each other.
NETWORK HARDWARE
Connecting computers in a network require additional devices that are not part of the
computer’s basic configuration.
➢ Hub and Switch: Computers in a single network is connected to a central device
called hub or switch. HUB accepts network data from computer and broadcasts to the
nodes by checking destination address. SWITCH will have a table which contains MAC
addresses of connected devices. The data is sent after looking up the table for
destination.
➢ Bridge and Router: The network supports many nodes which leads to
congestion. Hence, the network may be split into a number of segments, with a BRIDGE
connecting them. It connects two networks using the same protocol. ROUTER connects
two similar or dissimilar networks separated by long distance. It is a part of two
networks and thus have two addresses.It has a routing table to store address.
SOFTWARE BASICS
➢ Software is a collection of code that drives a computer to perform related group of
tasks.
➢ Programs in software use a language.
➢ The source code is created by programmer using programming languages like
C, C++,Java, Python etc.
➢ The software is developed to operate on multiple platforms.
SOFTWARE TYPES
Computer software can be broadly classified into two types: System software and
ApplicationSoftware.
➢ System Software: Software run by the computer to manage the hardware
connected toit is known as system software. System software examples:
BIOS- It checks the hardware devices and peripherals at boot time.
OS: It manages both hardware and programs running on the computer.
Pseudocode
➢ Pseudocode is a type of structured English written in natural language, to describe
set of rules for step-by-step processes, problem solving operations or other
calculations.
➢ It is informal, high level description of a computer program intended for human
reading rather than machine reading.
➢ The aim for writing pseudocode is to get idea quickly.
➢ There are no structure rules for writing pseudocode and it doesn’t require
program syntax.
➢ It is used in planning of computer program development, for sketching out the
structure of the program before the actual coding takes place.
dvantages:
1. It can be written easily
2. It can be read and understood easily
3. Modification is easy
4. It implements structured concepts easily
Disadvantages:
1. It is not visual
2. There is no standardized style or format, so one pseudocode may vary from other
for same problem statement
Examples:
Start Start
Get the values of number1 and number2 Get length and width
Calculate addition=number1+number2 Calculate area=length*breadth
Print addition Print area
Stop End
HISTORY OF C
➢ C is a general purpose, procedural, structured computer programming
languagedeveloped by Dennis Ritchie in the year 1972 at AT&T Bell
Labs.
➢ C language was developed on UNIX and was invented to write
UNIX systemsoftware.
➢ C is a successor of B language.
➢ There are different C standards: K&R C std,
ANSI C, ISO C.Characteristics of C:
➢ C is easy to learn.
➢ C is a general purpose language.
➢ C is a structured and procedural language.
➢ It is portable.
➢ It can
extend itself.
Examples of C:
➢ Operating system
➢ Language compilers
➢ Assemblers
➢ Text editors
➢ Databases
C Character Set:
➢ A C character set defines the valid characters that can be used
in a sourceprogram. The basic C character set are:
1. Letters: Uppercase: A,B,C,….,D
Lowercase: a,b,c,…..,d
2. Digits: 0,1,2,…..,9
3. Special characters: ! , . # $ ( ) } { etc
4. White spaces: Blank space, Horizontal tab space, carriage
return, new linecharacter, form feed character.
Basic structure of C Program
➢ C program consists of different sections. The structure of C program is
as shownbelow.
➢ Documentation Section: It consists of “comments” which increases
the readability of program. The comments are not processed by the
compiler. Thereare two types of comments:
Documentation section
Link section
Definition section
Global declaration section
main() Function Section
{
Declaration
part
Executable
part
}
Function 1
Function 2
-
-
Function n
Pseudo code solution to problem:
Most of the programming problems are too long and complex to be
translated directly. As a problem solving tool, programmers usually
introduce at least one intermediate step between English and C the one we
use is called pseudo code.
Pseudo code: Pseudo code is a restatement of the problem as list of
steps in an english like statements that are used to define a solution for a
given problem.
Main use of pseudo code is to help us to translate from English to C language.
It is also an outline of the basic structure or logic of the program.
The advantage of pseudo code is that it enables the programmer to
focus on algorithms without concerning about all the syntactic details of
specific programming language.Basic concepts in C program:
This section will introduce a number of features of the C language which
must be included inevery program, even though they do not appear in the
pseudo code. The basic
Structure of C program is shown below
Documentation section
Link section
Definition section
Global declaration section
main() section
{
Declaration part
Executable part
}
Constants: They are data values that do not change during program
execution. Main types ofconstants are:
1. Integer constants
2. Real constants
3. Character constants
4. Enumeration-constant
5. Coding constants
a. Literal constants
b. Defined constants
c. Memory constants
Integer constants are numerals without decimal portions. By default all C
language integers are of signed integer type. An integer constant consisting
of a sequence of digits is taken to be octal if it begins with 0 (digit zero),
decimal otherwise. Octal constants do not contain the digits 8 or 9. A
sequence of digits preceded by 0x or 0X (digit zero) is taken to be a
hexadecimal integer. The hexadecimal digits include a or A through f or F
with values 10 through 15.
An integer constant may be suffixed by the letter u or U, to specify that
it is unsigned. It may also be suffixed by the letter l or L to specify that it is
long. Various integer constants examples are given in the table:
Next is define constants, they are defined in the beginning of program along
with preprocessordirectives like #include<stdio.h>
Examples: #define PI 3.147
#define RATE_INTEREST 10
Once we define such values, we can use names like PI, SQR throughout the C
programs with the specified values. That is wherever PI is used it is
substituted with 3.147 and RATE_INTEREST with 10.
const keyword makes memory location called ‘pi’ to have a constant value
3.147 throughoutprogram execution
Data Types: A data type defines the type of data that is stored in a variable.
A data in a variable can be any type for example data can be either numeric
or string. A data type determines how much storage memory should be
allocated to a variable. ANSI C supports three classes of data type
1. Primary or build in or fundamental data type (int, char, float, double,
void)
2. Derived data type (arrays, structures, functions, pointers, unions)
3. User defined data type (typedef, enum)
Here we will be discussing only fundamental datatype. Other will be
discussed in latter units.All C compiler support five fundamental data types
namely
1. Integer (int)
2. Floating point (float)
3. Character (char)
4. Double precision floating point (double) and
5. void
Integer type: Integers are whole numbers with range of values supported
by particular machine. Data type that can store non-decimal numbers in
memory. The keyword int is used todeclare variables of integer type. For 16
bit machine the range of integer is -32768
to
+32767. In order to control over the range of numbers and storage space, C
has three classes of
ntegers.
Floating point type: data type that can store decimal numbers in memory
locations are called float/real data types. The floating point numbers are
defined in C by the keyword float. If the accuracy provided by float number is
not sufficient, double type can be used. It gives double precision. Following
table gives various sizes available in floating data types.
floa
t
doub
le
long double
Character type: Data type used to store single character in memory
locations is called character type. The keyword char is used for character
type Each of these characters has numerical value associated with them
called ASCII values. (ASCII stands for American Standard Code for
Information Interchange.)
for example: letter ‘a’ has ASCII value 97 (binary equivalent is 0110 0001)
and letter ‘b’ has value 98 (binary equivalent is 0110 0010). In same order
ASCII value of ‘x’ is 120 (0111 1000).
Here are some of the important ranges within the ASCII
character set:48 – 57: the digits ‘0’ through ‘9’
65 – 90: the capital letters ‘A’ through ‘Z’
97 – 122: the lowercase letters ‘a’ through ‘z’
Void type: It is a special data type that has no value but can be used for only
one operation thatis assignment. It can also be used as generic type.
Declaration of variables
There are two methods of declaration of
variables1 . Primary type declaration
2. User defined type declarationVariables
Variables are named memory locations that have type such as integer or
character to store data values, these data values will change during program
execution. Variables are also called identifier, because it is used to identify
value.
Rules for naming variable
1) The first character must be an alphabetic character (lower-case or capital
letters) or an underscore ‘_’.
2) All characters must be alphabetic characters, digits, or underscores.
3) The first 31 characters are significant; however length should not be
more than 8characters.
4) Cannot duplicate a reserved word. A reserved word is one which has
special meaning to C.
5) Uppercase and lowercase are significant.
6) White space is not allowed
The latter form takes more space, but is convenient for adding a comment
to each declarationfor subsequent modifications.
a 25 x 55 p 25.5 ch A
Examples
1. typedef int units;
2. typedef float marks;
units symbolizes int and marks symbolizes float. i.e., units batch1,batch2; and
marks n1, n2;
Note: 1. In Logical AND operator output is TRUE only if both inputs are TRUE.
2. In Logical OR operator output is TRUE if any of the inputs are TRUE.
3. In Logical NOT operator output is TRUE if input is FALSE
and vice versa.Here are some examples on logical expressions:
Example1: int A=5, B=10, X=20, Y=5;
What is truth value of expression: ( A ) && ( B )?
(5) && (10) both are non-zero number: 1 && 1
= 1 (True)(Note: Any non-zero number is treated as
1)
Where
Expression1 is Condition
Expression2 is Statement Followed if
Condition is TrueExpression2 is Statement
Followed if Condition is False
Meaning of Syntax:
1. Expression1 is nothing but Boolean Condition i.e it results into either TRUE
or FALSE
2. If result of expression1 is TRUE then expression2 is executed
3. Expression1 is said to be TRUE if its result is NON-ZERO
4. If result of expression1 is FALSE then expression3 is executed
5. Expression1 is said to be FALSE if its result is ZERO
2 : Comma as
Operatork = (a ,
b);
Different Typical Ways of Comma as Operator :
int
a=1,b=2,c;
Way 1 :
c = (a , b);
c = Value Stores in b = 2
Way 2 :
c = a , b;
c = Value Stores in a = 1
Let us say: B=5, C=7, D=9 and F=3, then value of A is:
A= 5+7*9/3
This expression is evaluated in following steps:
A=5+
(7*9)/3A=
5+(63/3)
A=5+21
A=26
Associativity: If two operators with same precedence accur in a complex
expression, another attribute of an operator called associativity takes
control. Associativity is the parsing direction used to evaluate an expression.
It can be either left to right or right to left .
For example: X= Y/Z*P%Q
Here ‘/’, ‘*’, and ‘%’ are operators at same level. But we evaluate this
expression from LEFTto RIGHT (i.e. Associativity is from Left to Right).
- Unary minus
++ Increment
-- Decrement
! Logical
~ negation Ones
* complement
& Pointer to
Sizeo reference
f Address
(typ Size of an object
e) Type cast
(conversion)
* Multiplication Left to right 3
/ Divisio
% n
Modul
us
+ Addition Left to right 4
- Subtraction
<< Left shift Left to right 5
>> Right Shift
< Less than Left to right 6
<= Less than or
> equal toGreater
>= than
Greater than or
equal to
== Equality Left to right 7
|= Inequality
& Bitwise AND Left to right 8
^ Bitwise XOR Left to right 9
| Bitwise OR Left to right 10
&& Logical AND Left to right 11
|| Logical OR Left to right 12
?: Conditional Right to left 13
expression
= Assignment Right to left 14
*= /= %= operators
+= -= &=
^= |=
<<= >>=
, Comma operator Left to right 15
Evaluation of Expressions
Based on the Precedence and Associativity of operators here we discuss
evaluating varioustypes of expressions.
int a=10, b=7, c=8, d=2;
– a + b / c - d
2 1 3
10 + (7/8) – 2
(10+ 0) - 2
(10 – 2)
8
– a + b && c - d
3
1 2
Example-3:
int a=10, b=7, c=8,
d=2;
(a+b)* (c-d)
1 2
3
(10+7)*(8-2)
1 2
Types of Conversions: Whenever mixed data occurs ‘type conversion’ comes into
picture.Two types of data type conversions are:
1. Automatic type conversions (Implicit conversions)
2. Manual type conversions (Explicit conversions)
In automatic conversion the operand/variable of smaller data type is automatically
converted todata type of larger size.
That is: char int long int float double- long double
Example:
int a=25; float
x=5,z; z=x/a;
printf(“%f”,z);
In this example ‘x’ is float and ‘a’ is integer, a gets automatically converted to float and
answeris: z= (5.0/25.0) 0.2
Note: This type of explicit conversion is also referred to as TYPE CASTING in ‘C’
Another example of side effects in type conversions is
here:Example:
float a=25, b=4;
int x; x=a/b;
The problem here is though 25.0/4.0 will result in 6.25, it is stored in an
integer variable ‘x’. As a result 6.25 is truncated to 6! Therefore we have to be careful
when mixed data types are used.