Pari Module1
Pari Module1
Fundamentals of computers.
Definition: “Computer is an electronic machine that can store, recall and process
data. It can perform tasks or complex calculation according to a set of instructions
or programs.
Characteristics of Computer:
1. Speed:
The computer works very fast. The speed of Computer is measured in terms of MIPS
(Million Instructions per Second) or BIPS (Billion Instructions Per Second).
2. Storage:
The computer can store a large volume of data and information. The storage capacity
of the computer is measured in terms of Bytes. A group of 8 Bits is called a Byte.
3. Accuracy
The computer generated results are exact and without any mistakes with high rate of
consistency.
4. Diligence
Unlike human beings, a computer does not suffer from limitations like tiredness and
lack of concentration. It can work for hours without making any errors.
5. Versatility
Computers are capable of performing any task. Multi-processing features of computer
make it quite versatile in nature. The computer can be adapted to any field easily. It is
used for scientific calculations, business processing, for playing games, teaching, training
etc.
6. Flexibility
Flexibility would involve the number of things you can do with a computer. While
some are best used for simple business tasks, and filing of tasks, others are good for
multimedia, gaming, and so on.
7. Cost effectiveness
Computers reduce the amount of paper work and human effort, thereby reducing costs.
Hardware
Software
Example Operating System, TUX Paint, Office Packages, Nudi, Adobe Reader,
Computer Games etc.
1. System Software: It is a type of software that is designed to control and work with
computer hardware. It acts as a interface between the user, the application software and
hardware.
Example: Microsoft Windows, Linux, DOS etc.
Data
Data is a collection of unprocessed items, which can include text, numbers, audio
or video. Data is the raw information or basic facts that computer can process.
For Example: “PARAM” 16
The computer processed data is called information, which gives particular meaning.
For Example: Name=“PARAM” Age=16.
Process the data as per instructions given by the program and convert it into
useful information.
1. Input Unit
2. Central Processing Unit(CPU)
Control Unit
Arithmetic and Logic Unit (ALU)
3. Memory Unit
4. Output Unit
Input Unit
. The Input Unit basically links the external world or environment to the computer
system. It is a device that allows entering the data and instructions into a computer.
It is the main part of a computer system like the heart of a human being. Most
computers are identified by the type of CPU that is present in them. The function of the
CPU is to interpret the instructions in the program and execute them one by one. It
consists of two major units.
It controls and directs the transfer of program instructions and data between
various units. The main activity is to monitor operations of ALU,MU, input and output
devices.
Arithmetic and Logic Unit performs arithmetic and logical operations and
controls the speed of these operations. Arithmetic operations like addition, subtraction,
multiplication and division (+,-,*, /) and logical operations like AND, OR, NOT and
relational operations like (<,>, <=,>=) are being carried out in this unit.
Memory Unit
The data and the instructions required for processing have to be stored in the
memory unit before the actual processing starts. In a similar manner, the results generated
from processing have to be preserved before it is displayed. The memory units thus
provide space to store input data, intermediate results and the final output generated.
Secondary storage devices are additional memory (storage) devices such as floppy
disks, magnetic tapes, Hard Disk Drive (HDD), Compact Disk (CD), Digital Versatile
Disk (DVD) etc., which are used to store huge information for future use.
Note: The input unit, an output unit, and secondary storage devices are together known as
Peripheral Devices.
Output Unit
It is used to print or display the results, which are stored in the memory unit.
Thus, the output unit links the computer to the outside world. The Monitor and Printer are
the most commonly used output devices.
Evolution of computer:
Abacus:
Around 2500 BC the Chinese invented the Abacus. It was the first machine used
for counting and calculating. It is made of a wooden frame, metal rods, and wooden
beads Abacus was mainly used for addition, subtraction and later for division and
multiplication. Today, the abacus is still used widely in China and other Asian countries
to count and calculate, just as we use calculators.
Napier’s bones:
In the early 17th century, John Napier, a Scottish mathematician, invented
another calculating tool. “Napier’s bones” was based upon manipulation of rods with
Adding Machine-Pascaline:
In 1642, at the age of 19, a French mathematician by the name of Biaise Pascal
invented the Pascaline. The Pascaline is known as the first mechanical and automatic
calculator. The Pascaline was a wooden box that could only add and subtract by means of
a series of gears and wheels. It had a box with eight movable wheels called dials. When
each wheel rotated one revolution, it would then turn the neighboring wheel.
Leibniz Calculator:
Mathematician Gottfried Leibniz built a calculator in 1650 that could
add,substract, multiply and divide the numbers.
Jacquard loom:
In 1801, Joseph Mary Jacquard invented the Jacquard loom. A poweed loom
that used punched wooden cards to automatically weave incredibly detailed patterns
including pictures and text. This can be taken as the first “Read only Memory” device.
Generations of Computer
ENIAC:
It stands for Electrical Numerical Integrator and Computer.
It used a word of ten decimal digits instead of binary ones like previous
automated calculators/computers.
EDVAC
It stands for Electronic Discrete Variable Automatic Computer.
It was to be a vast improvement upon ENIAC. Mauchly and Eckert started
working on it two years before ENIAC even went into operation.
This idea was to have the program for the computer stored inside the computer.
UNIAC
Universal Automatic Computer was the first commercial computer produced in
the United States.
Classification of Computer:
Classification based on Principles of Operation:
1. Analog Computers
2. Digital Computers
3. Hybrid Computers
Analog Computers
Analog computers work upon continuous data. Analog computer operates by
measuring rather than counting. The analog computers are that all calculation takes place
in parallel, hence faster. Modern analog computers usually employ electrical parameters,
such as voltages, resistances or currents, to represent the quantities being manipulated.
Computations are carried out with the physical quantities, such as voltages, length,
current, temperature etc. The devices that measure such quantities are analog devices.
Digital Computer
Hybrid Computers
Hybrid computer are the combination of both analog and digital computer. They
accept both the analog and digital data for processing. Hybrid computers incorporate the
measuring feature of an analog computer and counting feature of a digital computer.
Hybrid computers are best used in the hospital where the analog part is
responsible for measurement of patient’s heart beat, blood pressure, temperature and
other vital signs and then the operation is carried out in a digital fashion to monitor
patient’s vital signs. Hybrid Computers are also used in weather forecasting.
Based on the performance, size, cost, capacity, the digital computers are classified into
four types:
1. Micro Computers
2. Mini Computers
3. Mainframe Computers
4. Supercomputers
Micro Computers
Also, know as PC (Personal Computer), it was introduced in [Link] number of
processors in microcomputers will be one or two processors. It contains input devices,
output devices, storage device and processor. The number of processor will be one or
two. It is used by one person at a time.
Example: Desktops (PC, Macintosh), Laptops, Notebooks, Tablets, Palmtops, Smart
Phones.
Mini Computers:
Mini computers were introduced in the 1960’[Link] is larger and more
powerful than personal computer. It can execute five million instructions per second. It
generally consists of two or more processors. Minicomputer can serve up to 4000
connected users simultaneously. It is normally accessed by users via personal computer
or terminal. A device with a monitor and keyboard is called terminal. It is also known as
dumb terminal. It has no processing power and cannot work as stand-alone computer.
Mainframe Computers:
Supercomputers:
Uses of Supercomputers:
Weather Forecasting
Animated Graphics like Hollywood Movies
Nuclear energy research
Space Science
Weapons and Missile design
Applications of computers:
Chapter-2
INPUT DEVICE:
Example for Input Device: Light pen, Bar Code Reader, OCR, OMR, MICR etc.
Keyboard
A keyboard typically has characters engraved or printed on the keys and each
press of a key typically corresponds to a single written symbol.
The special keys perform specific tasks. Some of the special keys on the keyboard
are. Enter or return key. Tab key, alt key ctrl or control key, del key, insert key, shift key.
Num lock key caps lock key and so on.
Types of keyboard:
1. Standard keyboard: The standard keyboards have their basic layout. The average
number of keys on a regular keyboard is 105/108; QWERTY keyboards are the most
common and have the six alphabets Q, W, E, R, T, and Y in the first row.
2. Ergonomics: It refers to study of method that can reduce stress on muscles to avoid
repetitive strain injury. It mostly deals with optimizing posture and technique while
working, so the work can be carried out in the easiest manner.
3. Wireless keyboard: It is a keyboard that does not need to connect to the computer via a
wire. This makes very convenient for the use the keyboard comfortably. Wireless
keyboard use Bluetooth, Infrared (IR) to connect to the computer.
4. Virtual keyboard: It is a software device that led to use input data just like hardware
keyboard. They open up as an application and can be controlled by a mouse or wire touch
screen.
5. Compact keyboard: These keyboards are slim and usually do not have the numerical
keypad that is present on the right side of the keyboard these are typically used in laptops.
Mouse
Mechanical: This mouse has a small rubber ball underneath that moves against
two rollers as it passes across a flat surface. Mechanical sensors detect the movement of
the rollers as x and y axis and the cursor on the screen moves accordingly.
Optomechanical: As the rollers have wheels on the end of them with evenly
spaced holes. As the wheels spin, a light sensitive optical device counts number of holes
that pass and convert those numbers to an x and y-axis.
Optical: This mouse more accurate or precise and has no moving parts. It uses
the laser to detect movement and has to be paired with special mat.
JOYSTICK:
A joystick is an input device consisting of a stick that pivots on a base and reports
its angle or: The joystick can be moved in all four directions. The function of the
joystick is similar to that of a direction to the device it is controlling. Joysticks are also
used for controlling machines such as cranes, trucks, underwater unmanned. It is mainly
used in playing computer games.
SCANNER: The scanner captures images from the source which are then converted
into the digital form for further manipulation.
PRINTERS:
A printer is an output device that prints characters, symbols, and perhaps graphics
on paper. The printed output is generally referred to as hardcopy because it is in
relatively permanent form. Softcopy refers to temporary images such as those displayed
on a monitor. Printers can be divided into two main categories:
1. Impact Printers
2. Non Impact Printers.
Impact printers use a print head containing a number of metal pins, which strike an inked
ribbon. It includes printers that print by striking device against inked ribbon. Impact
printers, Line printers, dot-matrix printers are some of the impact printers.
1. In impact printers, there is physical contact with the paper to produce an image.
2. Due to being robust and low cost, they are useful for bulk printing.
3. Impact printers are ideal for printing multiple copies because they can easily print
through many layers of papers.
Line printer:
It can print large volume of text data very fast compared to the other printers. The
print quality is low and they are noisy to operate. The limitations of line printers are they
can print only one font, they can’t print graphics. A line printer can print 150 lines to
3000 lines per minute. Line printers are high speed printers capable of printing an entire
line at a time.
It uses multi part stationeries to prepare copies of a document. The printing speed
is around 300 characters per second. They are similar to typewriters. They are normally
slow. It prints one line of 8 or 14 points at a time, with print head moving across a line.
The most popular serial printer is the dot matrix printer.
The ink or semi-solid ink is stored in the printer cartridges and the flow of ink is
controlled by the processor. The impact printer don’t use striking device. It is much
faster and can print color, different font and size also.
Laser printers
Laser Printer is a page printer and utilizes a laser beam to produce an image on a
drum. The light of the laser alters the electrical charge on the drum wherever it hits. The
drum is then rolled through a reservoir of toner, which is picked up by the charged
portions of the drum. Finally, the toner is transferred to the paper through a combination
of heat and pressure. This is also the way copy machines work. Because an entire page is
transmitted to a drum before the toner is applied, laser printers are sometimes called page
printers. One of the chief characteristics of laser printers is their resolution – how many
dots per inch (dpi) they lay down. The available resolutions range from 300 dpi at the low
end to 1,200 dpi at the high end
Because laser printers are non-impact printers, they are much quieter than dot
matrix or daisy-wheel printers. They are also relatively fast, although not as fast as some
dot matrix or daisy-wheel printers. The speed of laser printers ranges from about 4 to 20
Ink-Jet Printer: It prints characters by spraying patterns of ink on the paper from a
nozzle or jet. It prints from nozzles having very fine holes, from which a specially made
ink is pumped out to create various letters and shapes. The ink comes out of the nozzle in
a form of vapors. After passing through a reflecting plate, it forms the desired letter/shape
at the desired place.
Plotter
Speaker
It is an output device, which converts audio signals into sound. The sound signals
from analog/ digital are converted in to audible frequency in the speakers and produce
voice output [audio data].
Computer memory
1. Static RAM- Retains information as long as the power supply is on. It is costlier.
2. Dynamic RAM- it loses its information in a very short time (a few milliseconds)
even though the supply is on. It is to be refreshed periodically. It is cheaper.
PROM- Programmable ROM: The user can store permanent programs, data or any other
kind of information in a PROM. The information can be written only once.
Secondary memory
Magnetic disks
Magnetic disks are thin circular plastic plates on which some magnetic material is
coated; the appearance is somewhat similar to a gramophone plate. Magnetic disks come
in various sizes and materials. They use the properties of magnetism to store the data on a
magnetic surface.
Hard disk
A hard disk drive (HDD) also hard drive or hard disk is a non-volatile. The hard disk is
the primary storage unit of the Computer. A hard disk consists of a stack of disk platters
that are made up of aluminum alloy of glass coated with a magnetic material.
The surface of a disk is divided into imaginary tracks and sectors. Tracks are
concentric circles where the data is stored. These tracks are numbered from the outermost
ring to the innermost ring, starting from zero. Disk sectors refer to the number of fixed
size areas that can be accessed by one of the disk drive’s read/write heads, in one rotation
of the disk, without the head having to change its position
The time taken to access a particular block consists of
1. Seek time- time to move heads to the right track.
Floppy disk
Floppy disk contains a single flat piece of circular plastic plate coated with metal oxide
and enclosed in vinyl or plastic cover. Disks are available in various sizes. Its capacity is
1.44MB. These are cheap when compared to other storage devices.
Optical disk:
To date, many forms of optical disc have been developed. Each generally enjoys a
span of popularity of use before newer discs with greater capacity and capability are
introduced into the market.
CD-ROM
It is a read only optical storage medium capable of holding 682MB of data. Its
data storing capacity is more compared to floppy disk. To read CD-ROM, a CD-ROM
drive is needed. Any information can be written and erased using CD-writer. There are
two types of CD-ROMs.
CD-R: Data once written cannot be erased. It is written once and can be read again and
again.
CD-RW: this disk allows the user to erase previously recorded information and then
record new information onto the same physical location on the disk.
It is referred as BD. It consists of a thickness of 1.1mm of the recording layer. it can store
23 to 27GB of data. Blue violet colored laser beam is used to read and write the data.
Cache memory:
The cache memory is placed in-between the CPU and the main memory. it is
much faster than the main memory. Its access time is much less compared to that of the
main memory. The cache is an intermediate memory and is not accessible to users. It
stores information and data, which are to be immediately executed. It is used to reduce
the average access time reading data, which are normally stored in the main memory.
Chapter 3
Number systems are basically divided into two types. They are,
The non-positional number system consists of different symbols that are used to represent
numbers. Roman number system is the best example for the non-positional number
system.
Decimal, binary, octal and hexadecimal number systems are some of the examples of this
type of binary [Link] base or radix of a number system is the total number of
digits present in that system.
This is the most commonly used number system in our daily life. It has 10
numbers from 0 – 9, hence its radix is 10. The positional values are expressed in powers
of 10.
Ex: 542.76(10)
It can be represented as, 5X102+4X101+2X100+7X10-1+6X10-2
Ex: 654.52 can be represented as ,
Digital computers cannot process the decimal numbers; hence they require binary number
representation ( 0& 1). The base of binary number system is 2. The positional values are
expressed in terms of power of 2.
Ex: 11011.101(2) can be represented as,
1X24+1x23+0X22+1X21+1X20+1X2-1+0X2-2+1X2-3
In a binary number the leftmost bit is called as MSB (most significant bit)
Rightmost bit is called as LSB (left significant bit).
The octal number system has 8 digits, 0,1,2,3,4,5,6,7. Its radix or base is 8. The positional
values are expressed in powers of 8.
Weight 16n ........ 162 161 160 . 16-1 16-2 16-3 ……. 16-n
s
25 24 23 22 21 20 Positional value
1 1 1 0 1 1 111011(2)=
1X25+1X24+1X23+0X
22+1X21+1X20
=1X23+0X22+1X21+0X20+1X2-1+0X2-2+1X2-3
=16+0+4+0+1+0.5+0+0.125
=21.625(10)
1375(8)=1X83+3X82+7X81+5X80
= 512+192+56+5
= 765(10).
735.46(8)= 7X82+3X81+5X80+4X8-1+6X8-2
= 448+24+5+0.5+0.09375
=477.59375(10)
BAD(16) =BX162+AX161+DX160
= 11X256+10X16+13X1
=2816+160+13
=2989(10)
Decimal to binary conversion:
2 53
53(10)=110101(2)
This procedure multiplies the decimal fraction successively by radix 2 and collects all the
numbers to the left of the decimal point (integral part). The reading of the integer part is
from top to bottom.
integer Fraction
0.3125(10)=0.0101(2)
Decimal to octal conversion:
A decimal fraction can be converted by repeated division method that we used in the
decimal –to-binary conversion. Since the radix of octal numbers is 8 the number is
divided by 8.
Example: 765(10)= ?
8 765
8 95 remainder 5
8 11 remainder 7
8 1 remainder 3
=1375(8).
0.3125X8=2.5000
0.3125(10)=0.24(8).
A decimal fraction can be converted by repeated division method that we used in the
decimal –to-binary conversion. Since the radix of hexadecimal numbers is 16 the number
is divided by 16.
16 559
16 34 remainder 15 this can be written as F
16 2 remainder 2
559(10)=22F(16)
The bits of the binary number are grouped into groups of three bits starting at the
[Link] convert each group of bit into its octal equivalent.
Octal digit 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111
equivalent.
1 2 7
Adding a leading 0 to MSB of whole number and adding trailing 0 to LSB of fractional
number does not change the value.
4 5 6
FACE(16)= ( ? )(2).
F= 1111
A=1010
C=1100
E=1110
FACE(16)= 1111101011001110(2).
Representing signed numbers:
The sign bit is used to indicate the positive or negative nature of the stored binary
number. Remaining bits are magnitude bits that represent the binary equivalent of the
decimal value being represented.
0 1 1 0 0 1 1
= + 51
The above picture is the memory where left most bit is the sign bit which stores the sign
and the remaining six bits are the magnitude of the number 110011 which is equal to
decimal value 51.
If the sign bit is 0 it represents a positive number.
If the sign bit is 1 it represents a negative number.
1 1 1 0 0 1 1
= -51
1’s complement:
2’s complement:
It is formed by taking the 1’s complement of the number and adding 1 to the least
significant bit position.
Binary Addition:
Binary subtraction:
Examples:
Example:Subtract 4 from 9
1001
1011
10100
Example: Subtracting a larger number from the small.( subtract 13 from 9).
1001
0010
No carry 1011 now take 1’s complement of this number and place a negative sign
in front. The result is -0100= -4.
BCD code:
BCD code stands for Binary coded decimal. It is the one of the early computer code.
5 3 7
0101 0011 0111
Excess-3BCD Code:
5 3 7
0101 0011 0111
0011 0011 0011…….ADD 3 (0011)
1000 1010 0110->Excess-3 BCD Code
ASCII table :
SOFTWARECONCEPTS
Introduction
A computer system has three components viz.
Hardware:It consists of the physical components of a computer.
Types of Software:
Software is broadly classified into two categories namely,
1. System Software
2. Application Software
System software:
System software is the collection of system programs to perform common tasks.
System software is hardware dependent and not portable. System software provides a
convenient environment for program development and execution.
Application Software:
Application software that has been written to process performs a specific job.
Application software is generally written in high level languages. It focus is on the
application, not the computing system.
Operating system:
An operating system is a set of program modules which provides a friendly interface
between the user and the computer resources. It acts as an interface between user and the
hardware.
Language translators.:
The translator translates the high-level language to low level language. There are
three types of translators: Compilers, Interpreters, and Assemblers.
Assembler:
Assembler:
Assembler is system software which translates an assembly language program
into its machine language. It recognizes the mnemonics used in the assembly level
languages and substitutes the required machine code for each instruction.
Compilers:
Interpreters:
An Interpreter reads once a statement of a high-level language program at a time
and translates it into machine level language and executes it immediately. It continues to
read, translate and execute the statements one by one until it reaches the end of the
program.
Therefore, it is slower than a compiler.
A linker is system software that links (combines) smaller programs to form a single
program.
A loader is system software that loads machine code of a program into the system
memory and prepares these programs for execution.
Utility Software:
Utilities are those helpful programs that assist the computer by performing
helpful functions like backing up disk, scanning/cleaning viruses etc. Utility software is
generally called as Application oriented readymade programs. Ex: text editor, notepad,
WordPad etc.
1. Memory management
2. Processor management
This is well suited for applications with large computation time and no user
interaction. Payroll, forecasting, statistical analysis are programs example for its usage.
Multi-user Operating:
A multi-user operating system allows multiple users on different computers or
terminal to access a single system with one OS on it. It creates and maintains individual
user environments, individual authentication and security level privileges, provides per
user resource usage accounting.
Time sharing:
Time-Sharing operating system allows many users to share the computer resource
simultaneously. Time sharing refers to the allocation of computer resource in time slots to
several programs simultaneously. Large CAD and text processing systems belong to
timesharing OS.
Most of the time-sharing operating systems adopted time slicing/ round robin
scheduling algorithm. Each user/process will receive a portion of the time slot.
UNIX, Windows Server is the example for multiprogramming, multi-use and time
sharing systems.
CUI Interface:
CUI interface allows the user to interact with a computer through text terminal.
It is a Non-graphical and text-based user interface.
MS-DOS is an operating system which provides a CUI.
The commands must be given at the command prompt ( C:\>)
GUI Interface:
The GUI was first introduced in 1984 by Apple with Macintosh.
GUI is an interface where the commands are selected from menus and icons rather the
typing them from the keyboard.
It allows user to click on the required icon, with the help of Mouse.
Windows Operating System is the most popular OS based on GUI.
CUI GUI
Chapter 5.
1. Problem definition
2. Problem analysis
3. Design of a solution using tools such as flowcharts and algorithms
4. Programming the computer
5. Checking and correcting errors
6. Program documentation
7. Program enhancement or maintenance.
Problem definition
It is the basic stage. The problem should be clearly defined to make the user understand
the problem correctly. It should be in the user language and may include charts, tables
and equations.
Problem analysis
The problem analysis makes the user to understand the requirement of the problem. This
is the first step towards the solution of the problem. This specifies the input and output
requirement of the problem. They are,
Algorithms and Flowcharts are the two design tools used in designing the problem. Here
the complex problems are divided into sub-problems. This approach is called as the
divide and conquers technique.
Algorithm
Advantages:
1. Easy to understand
2. Since it has got definite procedure it can execute with the fixed time
3. Easy to convert into flowchart
4. Independent of programming language used
5. Easy for debugging
Disadvantage:
It is time consuming
Characteristics of algorithms:
Analysis of algorithm:
There may be more than one approach to solve a problem. The choice of a particular
algorithm depends on the following performance analysis and measurements.
1. Space complexity: The amount of memory needed by the algorithm to complete
its run.
2. Time complexity: The amount of time, the algorithm needed to complete its run.
Pseudo code: A narrative description of the flow and logic of the intended program,
written in plain language that expresses each step of the algorithm.
Step1: START.
Flowchart:
Advantages of flowchart.
Easy to understand
Easy to convert into a program
It is independent of program
Easy for debugging
Disadvantages of flowcharts:
Time consuming.
Difficult to represent complex logic.
Alteration and modifications are difficult because we have to redraw the
flowchart.
Debugging:
It is the process of detecting the errors in a program. The process of debugging
verifies and ensures that the program does what the programmer intended to do.
Program documentation:
The written text and comments that make a program easier for the others to
understand use and modify is called documentation.
Program maintenance:
The process of updating or providing new versions of a program so that the
program meets the present day requirements of the user is called program maintenance.
It is required for following reasons,
1. To detect new errors that was detected during the usage of the program.
2. To make changes according to changing requirements and needs of user.
3. Modifying to provide additional information.
start
Read a,b,c
T F F
If T
If b>c
a>c
Print a
Print b Print c
stop
1. Sequential construct
2. Selection construct
3. Iteration constructs.
Sequence construct.
It is the ability of a programming language to execute the statements one after the other
from beginning to the end.
Selection statements:
If statement
If (expression)
statement;
If statement:
A program to find the biggest between the two numbers. (if statement)
#include<conio.h>
#include<iostream.h>
void main()
{
int big, a ,b;
clrscr();
cout<<“enter the two numbers”;
cin>>a>>b;
big=b;
if(a>big)
big=a;
cout<<” biggest among the two numbers=”<<big;
getch();
}
if else statement
If the condition is true then the statement1 or statements in the true block gets executed.
If the condition is false then the statement2 or the statements in the false block gets
executed.
#include<conio.h>
#include<iostream.h>
void main()
{
int big, a ,b;
clrscr();
cout<<“enter the two numbers”;
cin>>a>>b;
if(a>b)
cout<< a is greater”;
else
cout<<“ b is greater”;
getch();
}
A if else statement may contain one or more if else statement inside of it, it is known as
nested if else statement.
if(expression1)
if(expression2)
Statement1;
else
Statement2;
else
if(expression3)
statement3;
else
statement4;
if(a>b)
if(a>c)
cout<<“ a is greater”;
else
cout<<“ c is greater”;
else
if(b>c)
cout<<“ b is greater”;
else
cout<<“ c is greater”;
It is series of if conditions. If any of the condition gets true then the statements in that
condition block is executed. If none of the condition gets true then the default statement
i.e. the statement after else is executed.
If(condition1)
{
statement1;
}
else if(condition2)
{
statement2;
}
else if(condition3)
{
statement3;
}
else .if(condition..n)
{
statement..n;
}
else
statement;
}
Series of condition are checked for true status. If none of them gets true then default
statement is executed.
#include<conio.h>
Switch / Case:
The Switch Case structure is similar to a host of if statements. The switch case structure
may have a default condition that is executed if none of the statements match. A
switch/case structure is used when one statement must be chosen from many.
}
The value in the expression is compared with case labels. If it matches with the
any case label then the statements in that case block gets executed. If none of case labels
matches with the value of expression, then ultimately the default statement will be
executed.
#include<conio.h>
#include<iostream.h>
void main()
{
char code;
clrscr();
cout<<“ enter the colour code”;
cin>>code;
switch(code)
{
case ‘y’:
cout<<“\n yellow”;
break;
case ‘w’:
cout<<“\n white”;
break;
case ‘b’:
cout<<“\n blue”;
break;
default:
cout<<“\n invalid code entered”;
}
Iteration construct:
While Loop:
In a While Loop, the expression is evaluated when the program enters the top of the
loop. If the expression is true, the statements within the loop are executed. As long as the
conditional is evaluated as true, the process repeats. IF the conditional is evaluated as
false, then the code block is skipped.
Syntax:
while (condition)
{
statement block;
}
The while tests its condition at the top of the loop. Therefore, if the condition is false to
begin with, the loop will not execute at all.
#include<conio.h>
#include<iostream.h>
void main()
{
int I=2;
clrscr();
while(I<=10)
{
cout<< I<<”\n”;
I=I+2;
}
getch();
This is very similar to the while loop except that the test occurs at the end of the loop
body. This guarantees that the loop is executed at least once before continuing. The loop
repeats till the test condition is true. If test condition is false the loop will not repeat.
do
{
statement block;
} while (condition);
#include<conio.h>
#include<iostreamo.h>
void main()
{
int I=2;
clrscr();
do
{
cout<<I<<”\n”;
I=I+2;
}
while(I<=10);
getch();
}
If the statement block is only one statement, the braces are not necessary. This
statement is normally used when we know how many times the statement is to be
repeated. For statement can be used as increment or decrement loop. The loop repeats set
of statements a specified number of times to the counter value in the condition. When the
condition gets false the repeated execution stops.
#include<conio.h>
#include<iostream.h>
void main()
{
intI,n;
clrscr();
cout<<”enter the value for n”;
cin>>n;
for(I=2;I<=n;I=I+2)
cout<<I<<”\n”;
getch();}
The (ternary condition) operator is a more efficient form for expressing simple if
statements. It has the following form:
Example:
big= (a>b) ? a : b;
if a is greater than b then ‘a’ will be assigned to big , if the condition is false then ‘b’ will
be assigned to big.
Syntax error:- Each programming language have the set of rules and the program
written should follow the rules. Violating the rules makes a syntax error.
Logical error:- Even though the correct translation of algorithm causes the program to
produce wrong result then it is said to be having logical error.
Run-time error:-Errors that are detected during the execution of the program is called as
run time error.
Stepwise refinement: - The process of breaking down the problem at each stage to
obtain a computer solution is called stepwise refinement.
Programming techniques:
Unstructured programming: - The main program includes data and statements which
work on that. The main program directly operates on the global data. When the program
becomes too large it is not good to hold this concept.
Procedural programming:- The main contains sub procedures. The main program is
responsible to pass data to the procedures. The data is processed in the procedures and
when program execution is finished the resulting data is presented.
Modular programming:-The process of splitting the large programs into smaller units
(modules) is called modularization and programming with such an approach is called
modular programming.
Advantages ,
1. Reusability: The module can be reused according to the requirement of the user
which avoids rewriting of the functions saving the time.
2. Debugging: It is easy to locate the error and correct them since program contains
modules.
3. Building library: It is easy to build the library of commonly used functions by the
user to help reusability.
4. Portability: It is easy run the function on different operating systems without much
or no modifications.
Chapter 6
It is a concept that combines both the data and the functions that operate on that
data into a single unit called the object. An object is the instance of class. The functions
of an object called member functions in c++, typically provides the only way to access
the data of that object. The member functions have the right to access the data of its
object. So the data is always hidden and safe from accidental alteration.
Object X Object y
data data
functions functions
Object Z
data
functions
OOPs characteristics:
3. Data Encapsulation: The wrapping up of data and functions into a single unit called
as class. This concept is known as encapsulation.
4. Inheritance: The objects of one class acquire the properties of another class is called
inheritance. New class (derived class) can be derived from the old ones (base class).
A Base class
A function with same name with different parameters can perform different type of tasks
is known as function overloading.
[Link] binding:means that the code associated with a given procedure call is not
known until the time of the call at run time.
[Link] passing: it means the request for execution of a procedure for an object.
Therefore a message invokes a procedure in the receiving object to generate the desired
output.
Benefits of OOP’s.
Applications:
1. Real-time systems
2. Simulation and modeling
3. Object oriented databases
Disadvantages: