0% found this document useful (0 votes)
20 views228 pages

CS1 Final

The document is a comprehensive overview of computer science topics, including operating systems, data structures, C++, and HTML. It details the functions and services of operating systems, features of various OS like Windows 98, Windows NT, and Linux, as well as file systems and process management. Additionally, it includes questions for each module to reinforce learning.
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)
20 views228 pages

CS1 Final

The document is a comprehensive overview of computer science topics, including operating systems, data structures, C++, and HTML. It details the functions and services of operating systems, features of various OS like Windows 98, Windows NT, and Linux, as well as file systems and process management. Additionally, it includes questions for each module to reinforce learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 228

COMPUTER SCIENCE

INDEX
CHAPTER CHAPTER NAME PAGE NO.
NO.
1 Operating System 3-60

2 Data Structure 61-106

3 C++ 107-188

4 HTML 189-228

VICKY CHAUHAN (MVC) 9920644662 1


COMPUTER SCIENCE

2 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CHAPTER 1:

OPERATING
SYSTEM

VICKY CHAUHAN (MVC) 9920644662 3


COMPUTER SCIENCE

MODULE 1:
INTRODUCTION
TO OPERATING
SYSTEM

4 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

OPERATING SYSTEM AND ITS


FUNCTION
Operating system:
An operating system is a program, which acts as an
interface between the user of computer and the computer
hardware.
The OS can be viewed as set of software programs,
normally supplied along with hardware for effective and
easy use of machine.

Functions of OS:
1. To make hardware convenient to use.
2. To help user to executes programs.
3. To control execution of program to prevent errors
and improper use of computer.
4. To make provision for security of information to
users.
5. It provide facilities to share same hardware among
the users.
6. Proper scheduling of resources among users.

VICKY CHAUHAN (MVC) 9920644662 5


COMPUTER SCIENCE

SERVICES IN OS
Operating system provides services in following areas:

Ø Information managements (IM)


Ø Process managements (PM)
Ø Memory managements (MM)

Information managements: IM provides facilities to


store, retrieve, modify the information on various devices.
Services under IM are:
• Create a files or directory
• Open a file or explore directories
• Delete, copy or close files
• Change working directory.

Process managements: Services under PM are:


• To keep track of all running programs (called process)
• In multiuser operating system, number of users
located at different terminals may executes
different programs at a time. In such OS keeps track
of all processes. It schedules them and dispatches
them one after another.

Memory managements: Services under MM are:


• To keep track of all memory locations
• It determines memory allocation policy and uses
various techniques and algorithms.

6 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

SYSTEM CALL
System call provides the interface between a process and
the OS. These calls are generally available as assembly
language instructions.

System calls are used different ways as:


• Some system may allow system calls to be made
directly from a higher-level language program. In this
calls are predefined function or subroutine.
• Some languages(C, PERL) allow system call to be made
directly.
• Some system (fORTRAN) provides set of library
routines.

How does an application program (AP) use system call


during execution?
• To prompt a message on the terminal AP uses system
call.
• Read from terminal AP uses another system call.
Similarly for each and every task, program uses various
system calls.

VICKY CHAUHAN (MVC) 9920644662 7


COMPUTER SCIENCE

LIST OF SYSTEM CALL IN EACH


SERVICE OF OS:
IM PM MM
• Create a file • Read a process • To allocate chunk
• Create directory • Block a process of memory to a
• Open file for • Resume a process process
read/write • Terminate a • To free chunk of
purpose process memory from a
• Explore directory • Suspend a process process
• Close a file • Delay a process
• Read data from • Change priority of
file to buffer a process
• Write data from • Generate a
buffer to file process
• Move file pointer
• Create a link
• Change working
directory

QUESTIONS FORM MODULE 1:


1. What is operating system? Write its functions.
2. Which are the three areas in which the operating system
divides its services? Give examples.
3. What is mean by system calls? How it is used? How does an
application program use these calls during execution?

8 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 2:
OVERVIEW OF
OPERATING
SYSTEM

VICKY CHAUHAN (MVC) 9920644662 9


COMPUTER SCIENCE

FEATURES OF WINDOW 98
Ø Easier to use:
• Window 98 is a single user multitasking operating
system.
• Navigating around the computer screen is easier.
• A file can be opened by single click.
• Window 98 allows us to use multiple monitors with
single computer.
• New hardware can be easily installed.
• We can use digital cameras and other digital imaging
devices.

Ø Faster:
• Window and programs open faster than Window 95.
• The computer speed and efficiency can be easily
improved by simple maintenance.

Ø True web integration:


• Window 98 can be easily connected to Internet.
• Web pages can be viewed in any window.
• Using Microsoft Outlook Express, E-mails and
messages can be send to Internet newsgroup.

Ø More entertaining:
• Window 98 supports DVD and digital audio. User can
play quality digital movies and audio on computer.
• The television broadcast can also be seen.

10 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

FEATURES OF WINDOW NT
• Windows NT is multitasking, multiuser and
multithreading operating system.
• A user will get faster response even though multiple
applications are running.
• Windows NT supports virtual memory management
system to allow multiprogramming.
• Symmetric multiprocessing in window NT allows it to
schedule various tasks on any CPU in a multiprocessor
system.
• Windows NT is a 32-bit operating system.
• Windows NT uses New Technology File System
(NTFS), which implements fault tolerance, security
and has supports for very large files.

FEATURES OF LINUX
• Linux is multiuser, operating system with a full set of
Unix compatible tools.
• Linux runs on a wide variety of platforms. It was
developed exclusively PC architecture.
• It provides as much as functionality from limited
resources. It can run on machine having 4MB of RAM.
• Linux supports a wide base of applications
• Linux is free software. Free in the sense that people
can copy it, modify it, and use it in any manner they
want.

VICKY CHAUHAN (MVC) 9920644662 11


COMPUTER SCIENCE

COMPONETS OF LINUX
Kernel: Kernel maintains all-important abstractions of the
operating system, such as processes and virtual memory.

System libraries: System libraries define a standard set


of function through which applications can interact with
the kernel, and which implements much of OS
functionality.

System utilities: These are programs that perform


individual, specialized management tasks. Some system
utilities may be invoked just once to initialize and
configure some aspects of system.

System User User Compiler


Management Processes utility
Programs programs

System shared libraries

Linux kernel

Loadable kernel module

QUESTIONS FORM MODULE 2:


1. What are the features of Window 98?
2. What are the features of Window NT?
3. What are feature of LINUX.
4. What are components of Linux system.

12 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 3:
INFORMATION
MANAGEMENT

VICKY CHAUHAN (MVC) 9920644662 13


COMPUTER SCIENCE

FILE SYSTEM:
The file system related to IM allows the user to define
files and directories and allocate/deallocate disk space to
each file. The collection of related information i.e. data or
a program is called file. Each file has a specific name,
which is used to refer that file. For convenient use of
computer system, the OS provides a uniform logical view
of information storage. The OS manages mass storage
devices to implement the abstract concept of files.

Two types of file system:


• Tape-based system
• Disk-based system

Tape-based system: Tape-based systems are simple but


inefficient. In these systems, files are stored on to reels
of physical tapes. Generally one or more files are stored on
to one tape. Tapes are used for transport of data from one
computer to another.

Disk-based system: Each disk is divided into tracks and


each track is divided into number of sectors. Number of
sectors and size of sectors is variable. A disk has device
directory, indicating, which files are on the disk. The
directory lists the file name, starting address, file length,
type of file, time of creation and time of last update.

14 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

FILE OPERATIONS:
Create a file: For creating a file, first whether sufficient
space is available for that file is checked. If it is available,
entry for new file must be made in directory.

Write to a file: for writing to a file, there is command in


which name of the file is given. Then OS search for that
file in directory entry and write to it.

Reading a file: for reading a file, there is command in


which name of the file is specified. Then OS search for
that file in directory entry and read it.

Rewind a file: The directory is searched for appropriate


entry and file is reset to the beginning of file

Delete a file: To delete a file, directory entry is searched


and if file is found, it releases the memory space and that
directory entry now become invalid.

VICKY CHAUHAN (MVC) 9920644662 15


COMPUTER SCIENCE

IMPORTANT TERMS RELATED TO


MAGNETIC DISK

Track and Sectors: Magnetic disk surface is made up of


concentric circles called tracks. The number of tracks
varies depending on the disk type. A track is further
divided into smaller areas called sectors. Sector is
smallest unit of information, which can be read from, or
write to the disk.

Sector varies from 32 bytes to 4096 bytes.


Track varies form 75 to 500.
Disk contains 4 to 32 sectors per track.

Seek time: The time required for read/write heads to


move to the correct track is called as seek time.

Transmission time: The time required for activate


read/write head for appropriate surface and read data is
called as transmission time.

Latency time/ Rotation delay: The time required for


requested sector on track to rotate below the head is
called as latency time or rotational delay.

16 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

VISUAL DISPLAY UNIT (VDU)

Visual display unit (VDU) or terminal is nothing but a


common I/O medium. There are generally two parts of I/O
hardware:
• Input unit e.g. keyboard
• Output unit e.g. screen

There are two types of terminals:


• Dumb terminal
• Intelligent terminal

Dumb terminal: A dumb terminal consists of


microprocessor on which small program can run and limited
amount of memory. It is responsible for basic I/O
operations. A dumb terminal does no processing on input
character.

Intelligent terminal: An intelligent terminal has powerful


hardware than a dumb terminal. It also has more amount of
memory. It can carry out some process on input character
also it can process program independently.

VICKY CHAUHAN (MVC) 9920644662 17


COMPUTER SCIENCE

VIDEO RAM
...
Attribute Data Attribute Data Attribute Data
byte 0 byte 0 byte 1 byte 1 byte 79 byte 79

. . . . . . .
. . . . . . .

... ... ... ... ...


Attribute Data
byte 1999 byte
1999

• The video RAM is basically memory that the terminal


hardware itself has.
• Any time all the characters stored in the video RAM
are displayed on the screen by the video controller
using display electronics.
• All particular information (attributes) are stored in
the video RAM.
• Video RAM consists of 2000 data bytes (0-1999)
preceded by 2000 corresponding attribute bytes (0-
1999) as shown in above fig.
• A typical alphanumerical screen can display 25 lines
each consisting of 80 characters i.e. 25 x 80 = 2000.

Data byte: All 2000 characters are stored in video RAM.


To display any specific character on the screen at specific
position all ASCII or EBCDIC code for that character is to
move in video RAM.
18 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

Attribute byte: There is one attribute byte for each data


byte. This byte tells the video controller how the
character is to be displayed i.e. bold, underline, blinking
etc.

VICKY CHAUHAN (MVC) 9920644662 19


COMPUTER SCIENCE

KEYBOARD AS MEMORY MAP


TERMINAL
Terminal has video RAM generally with 2000 data bytes
preceded by 2000 corresponding attribute bytes. Anytime
all 2000 character (25lines x 80columns) stored in video
RAM are displayed on the screen by video controller. The
video RAM is treated as part of main memory only.
Therefore for moving any data from in or out of the video
RAM ordinary load and store instructions are sufficient.
So, keyboard is referred as memory map terminal.

MEMORY LOCATION INVOLVED


IN I/O OPERATION BETWEEN
KEYBOARD AND SCREEN
a) Small memory within keyboard itself: when a
character is keyed in, the 8-bit ASCII or EBCDIC
code is generated which is stored temporarily in
memory of the terminal itself.
b) The video RAM (data and attribute bytes): The
ASCII or EBCDIC code for the character is to move
to the video RAM.
c) The operating system buffers: The OS has one
buffer for each terminal and two separate buffer for
input and output operations.
d) The I/O area of the application program: When
the user finishes keying in the data, the data stored
in OS buffer for that terminal is flushed out to the
I/O area of the application program which wants that
data.

20 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

QUESTIONS FORM MODULE 3:


1. Explain file system related to information management
with file operations only.
2. Explain the following terms in case of magnetic disk
1) Track and sectors.
2) Seek time.
3) Transmission time.
4) Latency time/ Rotational delay.
3. What is VDU? Explain the following terms:
i Dumb terminal.
ii Intelligent terminal.
4. Explain the term use of video RAM. Explain data byte and
attribute bytes.
5. Why keyboard is referred as memory map terminal?
Explain the multiple memory location involved in the input-
output operations between the keyboard and screen.

VICKY CHAUHAN (MVC) 9920644662 21


COMPUTER SCIENCE

MODULE 4:
PROCESS
MANAGEMENT

22 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

PROCESS:
A Process is defined as a program under execution, which
competes for CPU time and other resources. In simple
term, a program does not compete for computing resources
such as CPU time or memory, whereas a process does. A
program may be present on paper or reside on disk. It may
be compiled or tested but still does not compete for
computing resources. Once user wants to execute a
program, it is located on the disk and loaded in main
memory, at that time, it becomes a process, because it
then compete for CPU time and other resources.

DEGREE OF
MULTIPROGRAMMING
Multiprogramming is the concept of increasing utilization
of CPU by always having something for CPU to execute.
The number of processes running simultaneously and hence
competing for CPU is known as degree of
multiprogramming.

VICKY CHAUHAN (MVC) 9920644662 23


COMPUTER SCIENCE

CONTEXT SWITCHING:
Multiprogramming is the concept of increasing utilization
of CPU by always having something for CPU to execute. In
multiprogramming system, multiple processes are run at
the same time such that when process 1 wait for an I/O,
process 2 executes and vice versa. When CPU switches
from one process to another the time required for
switching is called as context switching.

EXAMPLE
// A. CPP //B. h

# include <iostream.h> #include <iostream.h>


# include <B. h> int add(int x, int y)
void main( ) {
{ return(x+y);
int a = 10, b = 20; }
cout << add(a,b);
}

Explanation of example:
Here A and B are the two processes, where process A is
depending on B. When process A is being executed, CPU
executes instructions one by one. When it comes to the
instruction cout << add(a,b); it stops execution because the
output of this instruction depends on output of process B.

Thus there is need of execution of process B. so CPU


stores the contents of register and flag of process A in
RSA (Register Save Area). It then load process B in

24 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

memory. The time required for this known as context


switching

STATES OF PROCESS
Running state: There is only one process, which is
executed by CPU at any moment. This process is called as
running process. In multiprocessor systems, with multiple
CPUs, there are many running processes at a given moment.
The operating system keeps track of all of them.

Ready state: The process which is not waiting for an


external event such as an I/O operation, but which is not
running is said to be in ready state. Actually, a process in
ready state could have been running. But the fact that,
there is only one CPU, which is executing some other
process, while this process is waiting for CPUs attention
towards it.

Blocked state: When a process is waiting for an external


event such as I/O operation, the process is said to be
blocked state.

The major difference between blocked and ready process


is that a blocked process cannot be directly schedule even
if CPU is free, whereas a ready process can be scheduled
if the CPU is free.

VICKY CHAUHAN (MVC) 9920644662 25


COMPUTER SCIENCE

PRIORITY
The concept of arranging ready processes in a queue so
that they can be dispatched one after another for
execution depending on some policy is know as priority.
Due to many processes competing for the same available
resources like CPU and memory, concept of priority is
used.

TYPES OF PRIORITY:
Ø External priority: User specifies an external
priority, externally generally at the time of initiating
the process. In many cases, the OS allows user to
change its priority externally even during its
execution. If user does not specify any external
priority at all, the OS assumes a certain priority,
called the default priority.

Ø Internal priority: The concept of internal priority is


used by scheduling algorithms. They base their
calculations on the current state of the process e.g.
each user, while firing a process, can be forced to
specify the expected time that process is likely to
take for completion. The OS can then set internal
priority, which is highest for shortest job, so that
only little extra cost to large job, many short jobs
will complete. But if a steam of short jobs keeps
coming on, an important large job may suffer from
indefinite postponement. To avoid this set higher
external priority to important large job.

26 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Ø Purchase priority: This priority is normally used in


some data center situations where each user pays for
the time used. Highest priority process are charged
at highest rate to prevent each user from firing his
job at the highest priority. OS keeps track of the
time used by each process and the priority.

Time slice: In multiprogramming process many processes


are waiting in ready state. Each processes normally given
certain time to run irrespective of its importance. This is
known as time slice. Time slice is given to each process so
that a single process does not use the CPU indefinitely.
(Time slice is not based on priority).

QUESTIONS FORM MODULE 4:


1) What is process?
2) Explain context switching at process level in
multiprogramming system with example.
3) Explain Running, Ready and Blocked process states in
process management. Or discuss various process states with
suitable examples.
4) Explain following terms in case of process scheduling
i Turnaround time ii Waiting time
iii Terminal response time iv Event response time
5) What is priority? Explain internal and external priorities.
6) With reference to process management explain the terms:
i External priority ii Purchased priority
iii Internal priority iv time slice
7) Explain the term multitasking with suitable example.

VICKY CHAUHAN (MVC) 9920644662 27


COMPUTER SCIENCE

MODULE 5:
MEMORY
MANAGEMENT

28 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

FUNCTIONS OF MEMORY
MANAGEMENT OF OS
In general, the memory management modules performs
following functions
• To keep track of all memory locations free or
allocated and if allocated, to which process and how
much.
• To decide memory allocation policy i.e. which process
should get how much memory when and where?
• To use various techniques and algorithms to allocate
or deallocate memory locations. Normally this is
achieved with the help of some special hardware.

MEMORY MANAGEMENT SYSTEM


A. Contiguous, Real memory management system:
a) Single contiguous
b) Fixed contiguous
c) Variable contiguous
B. Non-contiguous, Real memory management system:
a) Paging
b) Segmentation
c) Combined
C. Non-contiguous, virtual memory management system:
a) Virtual memory.

VICKY CHAUHAN (MVC) 9920644662 29


COMPUTER SCIENCE

MEMORY MAP OF SINGLE USER


OS
Free memory
Process
Command interpreter
Kernel

The OS like MS-DOS is single user OS. The memory map


of such OS consists of program to be executed i.e.
process, free memory command interpreter and kernel.

Command interpreter: The command interpreter of the


single user OS is invoked when the computer is started.
Command interpreter interprets the command.

Process: This OS loads program to be executed in main


memory and assigns as much memory as possible to it. It
then sets instruction pointer and executes program.

Free memory: If program is terminated then it is removed


from memory.

Kernel: The kernel of OS provides basic operating system


services.

30 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

PARTITIONING
Certain OS uses partitioned memory management to allow
multiprogramming. Partitioning means dividing main memory
into various sections. These sections are called partition.

TYPES OF PARTITIONS:
Fixed partition: Also called static partition. In these
method partitions could be of different sizes. But once
decided, their size cannot be changed. In these method
partitions are fixed at the time of system generation. On
declaring fixed partitions, the OS system creates
Partition Description Table (PDT).

Variable partition: in variable partitioning number of


partitions and their sizes are variable. They are not
defining at the time of system generation. OS creates
these partitions at run time. At any time, partition may be
free or allocated to some process. In these technique
starting address of partition is not fixed.

VICKY CHAUHAN (MVC) 9920644662 31


COMPUTER SCIENCE

VARIOUS STEPS INVOLVED IN


ALLOCATION OF FIXED
PARTITION
When process is to be allocated a partition following takes
place:
1. The long-term process scheduler of PM decides which
process to be brought in to the memory.
2. It then finds out the size of the program to be loaded
by consulting the IM potion of the OS.
3. Then makes a request to the partition routine of the
MM to allocate a free partition, with the appropriate
size. The Partition Description Table (PDT) is useful for
this procedure.
4. With the help of IM module it now loads the binary
program in the allocated partition.
5. It then makes an entry of partition ID in PCB (Process
Control Block).
6. The routine in the MM now redefines partition
description table and marks the status of that partition
as allocated (ALLOC)
7. The PM eventually schedules this process.
PDT Fixed Partition
P0
partition Partition
0K

ID
100K

P1 Process A
Starting Size status
address
P2 Process B
0 0 100K FREE
400K

1 100K 300K ALLC


2 400K 200K ALLC
600K

3 600K 300K FREE P3

4 900K 100K ALLC


P4 Process C 900K

1000K

32 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

SINGLE CONTIGUOUS MEMORY


MANAGEMENT SYSTEM
In this memory management system, the physical memory
is divided into two contiguous areas. One is permanently
allocated to the resident portion of the operating system
and the remaining used for user process.

As shown in the fig. Operating system may be loaded at


lower addresses i.e. 0 to P. At any time, only one user
process is in the memory. This process is run to completion
and then the next process is brought in the memory.

OS 0
(MONITOR)

P
USER PROCESS
AREA

Max

VICKY CHAUHAN (MVC) 9920644662 33


COMPUTER SCIENCE

PAGING
Ø Partitions suffer from external fragmentation
because of available memory is not contiguous.
Ø Paging permits a program’s memory to be non
contiguous allowing a program to be allocated physical
memory wherever it is available.
Ø Physical memory is broken into fixed-size blocks
called Page frames. Logical memory is also broken into
of the same size called Pages.
Ø When program is to be executed its pages are loaded
into any available frames and the page map table is
defined to translate from user pages to memory
frames.
Ø The page size are define by hardware. It is typically
power of 2

Page 0
Page Page 0 Page 3
Page 1 #p frame
F 1 Page 0
Page 2 0 1
2
1 4
Page 3 2 3 3 Page 2
3 0
4 Page 1

Logical page map table (PMT)


Memory physical memory

34 VICKY CHAUHAN (MVC) 9920644662


1
2

COMPUTER SCIENCE

physical
Logical address
address

CPU
CCPU P d f d
Physical
Memory

f√

PMT

Every address generated by CPU is divided in two parts :a


page number (p) and a page offset (displacement). If we
are searching for some page into the physical memory then
its corresponding page frame (f) is searched in page map
table (PMT), on adding displacement (d) to page frame (f)
we can obtain exact location of required page in physical
memory.

VICKY CHAUHAN (MVC) 9920644662 35


COMPUTER SCIENCE

SEGMENTATION:
• Segmentations are logical division of programs and
hence are normally of variable sizes.
• Segmentation is memory management scheme which
support user’s view of memory.
• Each segments has number and length.
• Each program is executable form can be considered
to be consisting of different segments. Such as code,
data and stack. Each of these further divided into
new segments.
• A program normally contains main program, some
subprograms and few predefined and precompiled
functions. Each of these belongs to different
segments.
• An application programmer does not necessarily have
to declare different segments in the program, the
complier does it by its own.

Followings are the jobs of compiler:


Ø Recognize different segments.
Ø Number those segments.
Ø Define segment table.
Ø Produce an executable image.

36 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Main program O 0
Sub_program 0

Segment 0 segment 1
999 399

Stack area 0
Data_area 0

Segment 2 segment 3
299 199

Segment # Limit Base 0 oooooo 0000000 0

0 1000 1400
1 400 3400
Segment 3 500
2 300 2900
700
3 200 500

Segment 0 1400

2400

Segment 2 2900

3200

Segment 1 3400

3800

Physical memory

VICKY CHAUHAN (MVC) 9920644662 37


COMPUTER SCIENCE

VIRTUAL MEMORY
Virtual memory is attempt, which makes the execution of
the processes possible, which may completely not in the
main memory. Some part of the process may be on disk.

Need of virtual memory: The MM techniques are simple


to implement but the major drawback is that if the
physical memory is limited then it can hold less number of
processes at a time. Hence degree of multiprogramming
gets reduces. For this concept of virtual memory
introduced.

Advantage of virtual memory:


• The main advantage of virtual memory is user can
execute programs, whose size may be greater than
the physical memory.
• Degree of multiprogramming increases.

How it is implemented? :
Virtual memory is difficult to implement. It can be
implemented by paging, segmentation or combined
schemes. Mostly virual memory system are
implemented by paging.
• A program consists of number of logical or virtual
pages. To start execution of program some of the
pages are loaded into specific page frames.
• If a page is not loaded into memory and a location for
that page is referenced, at that time page fault is
arises. When page fault arises the OS loads the
referenced page in memory from disk.

38 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CONCEPT RELATED TO VIRTUAL


MEMORY

Locality of reference: The basic principle behind virtual


memory is called locality of reference. It gives idea,
whether a page likely to be referenced in the near future
or not, depending on its behavior in past. Thus it helps to
decide whether the page should be thrown out from
memory to make space for new page or not. If this
principle is not valid, user cannot throw any page out of the
disk from memory.

Page fault: In many system, when a process is executing


with only few pages in memory and when an instruction is
encountered which refers to any instruction or data in
some other page which is outside the main memory, a page
fault is occurs. At this stage, OS must bring the requested
page into the memory before the execution of that
instruction can restart.

Working set: At any time, a process has a number of


pages in the physical memory. Not all these are actively
referred. The set of pages in physical memory actively
referred to at any moment is called working set. This has
significant bearing on the policy of bringing in pages from
disk to the main memory.

VICKY CHAUHAN (MVC) 9920644662 39


COMPUTER SCIENCE

Dirty page/ dirty bit: The page, which is modified after


it is loaded in main memory from disk, is called dirty page.
The OS maintains one bit for each physical page frame to
devote whether a page has become dirty of not. This bit is
called dirty bit. If page is modified after it is loaded in
main memory then dirty bit is set.

Page replacement policy: As the number of processes and


the number of pages in the main memory increase, all the
page frames occupied. At this time, if new page is to be
brought in, OS has to overwrite some existing page in
memory. The page to be overwritten is selected by “page
replacement policy”. There are many algorithm to
implement page replacement policy.

Demand paging: In demand paging, a page is brought in


only when demanded. Consider a process is created with no
pages in main memory. When process is dispatched initially,
the program counter will have been loaded with the
address of first instruction, this address belongs to the
page outside the main memory, page fault will occur and
OS bring that page in memory. In this way as page fault
occurring, OS brings new pages. This is called demand
paging

40 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

QUESTIONS FORM MODULE 5:


1) What functions are performed by memory management of
operating system? state any four memory management
systems.
2) Explain memory map of single user operating system.
3) What is partitioning? Explain fixed and variable portioning.
4) State the various steps involved in the allocation of
partition in case of fixed partition memory management.
5) Explain the single contiguous memory management system
with suitable memory mapping diagram.
6) What is paging? Explain in detail.
7) What is segmentation?
8) Explain concept of virtual memory in brief.
9) Explain the following terms:
i Locality of reference
ii Page fault
iii Working set
iv Page replacement policy
v Dirty page/ dirty bit
vi Demand paging

VICKY CHAUHAN (MVC) 9920644662 41


COMPUTER SCIENCE

MODULE 6:
GRAPHICAL
USER
INTERFACE
(GUI)

42 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

GUI
The interface, which replaces cryptic commands by their
graphical representation, is called Graphical User
Interface (GUI). Window operating system is GUI based
operating system.

ADVANTAGES OF GUI:
• With GUI, commands are replaced by graphics. Hence
it is not necessary to remember the command and its
meaning
• With GUI, user can several programs simultaneously.
• User can communicate and exchange data between
programs without transferring or copying files
• Easy to use, consistent GUI for virtually all programs.

FEATURES OF GUI:
1. Replacement of command with icon: This allow the
user to select a command using a cursor and simply
clicking on it
2. Provide on-line help: GUI based applications provide
“HELP” about various features of the application.
HELP can assist the user in knowing everything about
the application

VICKY CHAUHAN (MVC) 9920644662 43


COMPUTER SCIENCE

ESSENTIAL COMPONENTS OF
GUI
• Menu bar
• Scroll bar
• Control: (push button, option button, radio button,
check button, list button, entry box combo box)
• Dialogue boxes
• Feedback pointer

Menu bar: menu bar normally appears at the top of the


window title. Some commonly used menu bar options are
File, Edit, View, and Help etc. When one of these options is
selected, a pulldown menu appears in the screen.

Scroll bar: Scroll bar allows user to scroll window


horizontally or vertically. Scroll bar are generally used to
look at the information, which is not currently visible on
screen. A scroll bar consists of horizontal and vertical
scroll area with a slider box and an arrow in box at each
end.

Dialogue boxes: Dialogue box is a window, used by the


application to interact with the user. A dialogue box can
also be used to display information or to get user input and
also for a combination of these two functions.
Dialogue boxes are of two types:
i) Modal dialogue box, ii) Modeless dialogue box.
Modal dialogue box: A dialogue box where a application can
continue only after the user has responded to the dialogue.
Modeless dialogue box: A dialogue box which allows user to
continue without responding.
44 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

OPERATION PERFORMED ON A
WINDOW

Title bar Menu bar minimizing/maximizing/


Close buttons

M.S. Office − ✕

File Edit View Run Help ^

< >

Arrow
Slider box
Horizontal Vertical
scroll bar scroll bar

VICKY CHAUHAN (MVC) 9920644662 45


COMPUTER SCIENCE

Dragging a window:
• The position of window on a screen can be changed by
dragging it.
• To drag a window select a window by clicking mouse,
keep the left button of the mouse pressed with
mouse pointer on the title layer of the windows.
E.g. on the layer in which “M.S. Office” is written in
diagram.
• Move the mouse pointer to new position; it will find
that new window is shifted to new position.

Resizing window: Making change in size of window is called


resizing window.
A window can be resized as follows:
• Move the mouse pointer to right/left side border of
windows.
• Observe that the shape of mouse pointer gets
changed to left/right arrow.
• Now press the left button of the mouse and move the
mouse arrow to right/left side to a new position.
Observe that right/left border of window moved.
• Similarly we can move top/bottom border of window.

Minimizing/ Maximizing and closing window: we can


minimize/ maximize or close window by pressing minimize/
maximize or close button respectively, which are present
at the top in right corner of the window.

46 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

IMPORTANT PROGRAM OF MS-


WINDOWS
Program Manager:
The program manager starts executing along with MS-
Windows. This provides user interface to start and stop
applications. It is used to organize various applications into
different groups. It also indicates how each contents are
controlled and displayed on the screen. It is also used to
end MS-Windows session.

File Manager:
This helps organize user files and directories. This is used
to traverse through the file system and change drives, to
search, copy, move, create or delete files and directories.
Application can be started directly from the file manager.

Control Panel:
It can be used to choose or change the color schemes in
applications, select and display the background of the
screen, select border width and other border
characteristics, cursor size and shape etc. font also
managed by control panel. It is also used to configure
printer and other ports on the PC.

VICKY CHAUHAN (MVC) 9920644662 47


COMPUTER SCIENCE

QUESTIONS FORM MODULE 6:


1. What is GUI? State any four advantages of GUI.
2. Explain in brief any two features of GUI.
3. What are the essential components of GUI? Explain any
three.
4. Explain in short the function of menubar and scroll bar
component od GUI.
5. Explain different operation performed on a window.
6. Explain in brief the following program of MS- Window
i Program manager
ii File manager
iii Control panel

48 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 7:
ACCESS AND
SECURITY
ASPECTS OF
OS.

VICKY CHAUHAN (MVC) 9920644662 49


COMPUTER SCIENCE

SCURITIES
• Security is concerned with the ability of the
operating system to enforce control over the storage
and transportation of data in and between the
objects, that the operating system supports.
• In multiuser operating system, the concept of
security and protection are very important. User
program should not interface with one another or
with the OS.

ELEMENTS OF SECURITY
Confidentiality: Confidentiality ensures that information is
not accessed in an unauthorized manner. It is generally
related to the Read operations.

Integrity: Integrity ensures that the information is not


amended or deleted by an unauthorized manner. It is
generally related to Write operations

Availability: Availability ensures that information is


available to the authorized users at right time.

50 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

ATTACKS:
The security of system can be attacked and penetrated in
number of ways as follows:

Authentication: authentication means verification to the


system resources. Following are some of the ways in which
authentication may take place:
• By stealing somebody else’s password and then use it.
• Use of vendor supplied password, which can be used
by only system administrator.
• Finding password by trial and error method.
• If a user logs on and then goes off, an intruder can
use that terminal.
• Writing dummy login program to fool the user.

Browsing: In some system, there exist files with access


control, which are very permissive. One can brows through
the system files to get this information, after which,
unprotected files/ databases be easily accessed.
Confidential information could be read or even modified.

Trap door: sometimes, software engineer leaves some


secret entry point to modify their programs. These are
called trap door. Others can misuse them.

Electric data capture: Use of active or passive wire traps,


or mechanism to pick up the screen radiation and to
recognize what is displayed on screen is called electric
data capture.

VICKY CHAUHAN (MVC) 9920644662 51


COMPUTER SCIENCE

Invalid parameters: Passing invalid parameters may cause


serious security violations.

Line trapping: A special terminal is used to tap into a


communication line. It causes access to confidential data.

Waste recovery: By using technique, deleted files can be


recovered, password may be recollected.

Rouge software: certain programs like worms, viruses


attack on system

COMPUTER WORMS
A computer worm is a complete program by itself. It is
written in such a way that it spreads to other computers
over a network. But, while doing this, it consumes the
network resources to a very large extent. A computer
worm can potentially bring the entire network to a halt.

Modes of operation: usually a computer worms does not


harm other program or data. It just spread, thereby
consuming large resources.
• A computer worms usually operates on a networks.
Each node on a network maintains a “mailing list”,
which gets access to this list and using this, sends
copy of itself to all addresses.
• If worm is intelligent, after reaching a node it check
whether a copy of itself already exists there or not.
if exists, it does not create one more copy.

52 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

• If the worm is dumb, it just copies itself to all nodes.


So, if one node’s address is at several places in
network, then it would have several copies of the
worm

Safeguard against worms: a worm can be prevented by


strong security and various check points on the
communication system.

VIRUSES
• A Computer virus is part of computer program, which
is written with clear intension of infecting other
program
• A computer virus is not complete program by itself.
It cannot act independently.
• A computer virus causes direct harm to the system.
It can corrupt code as well as data.
• Classification of virus is based on what do it affects
or where the virus resides

Types of viruses
Ø Boot sector virus
Ø Memory resident virus
Ø File specific virus
Ø Command processor virus
Ø General purpose virus

VICKY CHAUHAN (MVC) 9920644662 53


COMPUTER SCIENCE

METHODS BY WHICH VIRUS


INFECT OTHER PROGRAM
1) Append: In this method the viral code appends itself
to the unaffected programs.

2) Replace: In this case, the viral code replaces the


original executable program completely or partially to
carry out some undesirable actions.

3) Insert: In this case, the viral code is inserted in the


body of an executable code to carry out undesirable
actions.

4) Delete: In this case, the viral code deletes some


code from the executable program.

5) Redirect: This is an advanced approach employed by


the authors of sophisticated viruses. The normal
control flow of a program is changed to execute some
other code, which could exist as an appended portion
of normal program.

54 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

VIRUS DETECTION, REMOVAL


AND PREVENTION
Virus detection: Normally, a virus detection program
checks the integrity of the binary files. The program
maintains a check sum on each file. A mismatch in it
indicates virus. Some program resides in the memory and
continuously monitors certain memory and I/O operations
for guarding against any suspicious behavior.

Virus removal: A generalized virus removal program is very


difficult to imagine due to the multiplicity of the viruses
and creativity with which they are constructed. However,
for some viruses, bit pattern in code can be predicted. In
this case, virus removal program scans the disk for the
patterns of known viruses. On detection, it removes them.
But, if the viruses have already damaged data, then
recovery of data is almost impossible.

Virus prevention: User cannot recover data after viral


affection. Hence the best way is to prevent viruses for
this user must buy official, legal copies of software from
reliable sources. One should be extremely careful about
picking up free, unreliable or illegal software. Frequently
back-ups and running of monitoring program also help in
detection, and thus subsequent prevention of different
viruses.

VICKY CHAUHAN (MVC) 9920644662 55


COMPUTER SCIENCE

DIFFERENCE BETWEEN WORMS


AND VIRUSES
Worms Viruses
A computer worm is a A computer virus is not a
complete program. complete program, but a
part of program.
A computer worm can act A computer virus cannot act
independently. independently.
It do not cause direct harm It causes direct harm to the
to the computer system. computer system.
It just goes on spreading on A computer virus corrupts
the network and consumes code and data.
network resources to a large
extent

QUESTIONS FORM MODULE 7:


1. Define “security” with respect to an operating system.
Explain the different elements of security.
2. What are attacks on security? Explain in short the ways in
which a system can be attacked.
3. What are compute worms? Explain its mode of operation.
4. What is computer virus? State various types of viruses and
the basis on which they are classified.
5. What are different methods by which virus can infect
other programs?
6. Discuss virus detection, removal and prevention
philosophies.
7. Differentiate between computer worms and computer
viruses.
8. What is the difference between a worm and a virus?
Explain how these can be prevented.
56 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

Select the correct alternative and rewrite the


following.

1. Operating system is _____.


a) hardware b) software c) input device
d) output device
2. ____ is service in operating system.
a) information management b) process c) G.U.I.
d) none of these.
3. Window NT is _____ operating system.
a) single user operating system b) multiuser
operating system. c) time sharing d) none of these.
4. Linux is a _____ software.
a) public domain b) free c) paid d) private.
5. Window 98 is _____ operating system.
a) single user multitasking b) multiuser c) time
sharing d) multithreading.
6. The time required for read-write head to move to the
correct track is _____.
a) seek time b) rotational delay c) device driver
d) information management.
7. Termination of a process is done by _____
a) memory management b) process management
c) device driver d) information management
8. The time lost in turning the attention of process
from one process to other is called as _____.
a) circuit switching b) Band width c) context
switching d) none of these.
9. _____ is a function of memory management.
a) creation of file b) halting process c) paging
d) none of these

VICKY CHAUHAN (MVC) 9920644662 57


COMPUTER SCIENCE

10. If the page size of 2 MB memory is 2 kB, then the


number of higher order bits on address bus, used to
denote page number is _____
a) 11 b) 10 c) 9 d) 8
11. Wastage of memory space within the partition is
called as _____.
a) Internal fragmentation b) external fragmentation
c) compaction d) none of these
12. If a page is modified after it is loaded in main
memory, then it is called as _____
a) page fault b) dirty page c) paging d) locality of
reference.
13. Page are physical in nature, while segments are ____
a) logical b) virtual c) either physical or logical d)
either virtual or physical
14. Following is not a process state _____
a) ready b) blocked c) resumed d) running
15. Widows NT is _____ operating system.
a) multiuser b) multitasking c) multithreading d) all
of these.
16. _____ is not an operating system.
a) UNIX b) LINUX c) MS-DOS d) C++
17. _____ spread more rapidly but causes less damage to
compute networks.
a) virus b) worms c) Bombs d) none of these
18. ____ are the operating system programs.
a) Application program b) user program c) process
management program d) antivirus program
19. ____ is given to each process so that a process does
not use CPU indefinitely.
a) context switching b) time slice c) token time d)
purchased priority

58 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

20. In information management _____ service is


provided by operating system.
a) change the priority of process
b) to allocate a chunk of memory to process
c) open a file (for read, write or both)
d) wait for a child process to terminate.

Answers:
1 b 11 a
2 a 12 b
3 b 13 a
4 b 14 c
5 a 15 d
6 a 16 d
7 c 17 b
8 c 18 c
9 c 19 b
10 b 20 c

VICKY CHAUHAN (MVC) 9920644662 59


COMPUTER SCIENCE

60 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CHAPTER 2:

DATA
STRUCTURE

VICKY CHAUHAN (MVC) 9920644662 61


COMPUTER SCIENCE

MODULE 1:
INTRODUCTION

62 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

INTRODUCTION TO DATA
STRUCTURE
Data: Data are simply values or set of values.

Group item: Data item, which are divided into sub items,
are called group items. For example date may be divide
into three sub-items – day, month and year. So date is
group item.

Elementary item: Data items, which are not divided into


sub-items, are called as elementary item.

Entity: An entity is something that has certain attributes


or properties, which may be assigned values. The values
may be numeric or nonnumeric.
Example: a bio-data,

Name Age Sex Education


Govardhan 17 M HSC
Here, first row represent attributes and second row
represent values of attributes

Field: Field is a single elementary unit of information


representing an attribute of an entity.

Record: Record is a collection of field values of a given


entity.

File: File is the collection of records of the entities in a


given entity set.

VICKY CHAUHAN (MVC) 9920644662 63


COMPUTER SCIENCE

Example:
Serial Number Name Address Telephone
001 Ram Mumbai 9920872345
002 Ali Ahmedabad 9812830457

Record Field

DATA STRUCTURE
A data structure is a particular way of organizing data in a
computer so that it can be used efficiently. General data
structure types include the array, the file, the record, the
table, the tree, and so on. Data structure is the way in
which different data elements are logically related. The
data structure should be simple and it should show the
relationship between elements.

Types of data structure:


• Linear data structure.
• Non-linear data structure.
In linear data structure, data elements are stored in
consecutive memory locations or by using linked
representation. Example: array, linked list.
In non-linear data structures, the linear order cannot be
maintained between data elements. Generally data
elements have hierarchical relationship between them.
Example: trees.

64 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

QUESTIONS FORM MODULE 1:


1. Define the following terms: field, record, file.
2. What is data structure?

VICKY CHAUHAN (MVC) 9920644662 65


COMPUTER SCIENCE

MODULE 2:
FLOW CHART
ALGORITHM

66 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

DATA STRUCTURE OPERATIONS


1. Traversing: Accessing each record or element exactly
once, so that it can be processed is called traversing.
2. Inserting: Adding a new record to the existing structure
is called inserting.
3. Searching: Finding the location of record with given key
values or finding the location of all records, which
satisfy one or more conditions is called as searching.
4. Sorting: Arranging records in some logical order is called
as sorting.
5. Merging: Merging means combining the records in two
different sorted files into a single sorted file.
6. Deleting: Removing an element from the existing
elements of an array.

CONTROL STRUCTURES:
Sequence logic:
In sequence logic module are executed sequentially, one
after another. The sequence may be present explicitly by
means of numbered step or by the order in which modules
are written.

Module A

Module B

Module C

VICKY CHAUHAN (MVC) 9920644662 67


COMPUTER SCIENCE

Selection logic:
Selection logic uses number of conditions, which cause
selection of one out of several alternative modules.
a) Single alternative: If the condition is satisfied then
module A, which consists of number of statements, is
executed. Otherwise module A is skipped and next
module is executed.

If
No
Condition
?

Yes

Module A

b) Double alternative: if the condition is satisfied,


then module A will executed. Otherwise module B will
executed

If
No
Condition
?

Yes

Module A Module B

68 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Iteration logic:
Here certain module is executed repeatedly until condition
satisfies.
At first, the body of loop i.e. module will be executed with
K = R and then with K = R + T, then with K = R + 2T and so
on until K = S. The loop ends when K > S.

KßR

is
Yes
K > S?

No

Module

KßK+T

The repeat-while structure has of the form.

Here, module is executed until No


Condition
condition is satisfed
?
Yes

Module

VICKY CHAUHAN (MVC) 9920644662 69


COMPUTER SCIENCE

LINEAR ARRAY:
A data structure is said to be linear if its elements form a
sequence. A linear array is the data structure which
consists of finite, ordered set of homogeneous data
elements such that:
• The elements of array are referenced respectively by
an index set (subscript) consisting of “n” consecutive
numbers.
• The elements of the array are stored respectively in
successive memory locations.
• The number “n” of t he elements is called length or
size of array. In general, the size or length of the
array can be obtained from the index set by the
formula:
Length = UB – LB + 1
Where UB – the largest index called Upper Bound.
LB – the smallest index called Lower Bound.

Example: let DATA be 5 elements linear array as follows:

DATA
1 456
2 789
3 654
4 223
5 777

The elements of an array may be denoted by the subscript


notation such that: DATA [4] = 223.
In C++, array is declared as: int data [100]; which specify
an array data of 100 integer.
70 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

TRAVERSING AN ARRAY:
Accessing each record or element exactly once, so that it
can be processed is called traversing.

Algorithm:
Here LA is a linear array with lower bound LB and upper
bound UB. Algorithm applies operation PROCESS to each
element of LA.

Step 1: [Initialize counter]


Set K := LB
Step 2: Repeat step 3 and 4 while K ≤ UB
Step 3: [Visit element]
Apply PROCESS to LA [K]
Step 4: [Increment counter]
K := K + 1
[End of step 2 loop]
Step 5: Exit

VICKY CHAUHAN (MVC) 9920644662 71


COMPUTER SCIENCE

INSERTING ELEMENTS
Adding a new record to the existing structure is called
inserting. The element can be easily inserted at the end of
array. But for insertion in the middle of array, it is
required to move the elements of array one byte forward.

Following algorithm insert a data element ITEM into the


Kth position in an array LA with N elements.

Algorithm:
INSERT (LA, N, K, ITEM)
Here LA is a linear array with N elements and K is positive
integer, such that K ≤ N. This algorithm insert an element
ITEM at the Kth position in LA.

Step 1: [Initialize counter]


Set J := N
Step 2: Repeat step 3 and 4 while J ≥ K
Step 3: [Move Jth element forward]
Set LA[J+1] := LA[J]
Step 4: [Decrement counter]
J := J - 1
[End of step 2 loop]
Step 5: [Inert the element]
Set LA [K] := ITEM
Step 6: [Reset N]
Set N := N + 1
Step 7: Exit

72 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

DELETING ELEMENTS
Removing an element from the existing elements of an
array. The element can be easily deleted from the end of
array. But deletion from the middle of array, it is required
to move the elements of array one byte backward.

Following algorithm delete a data element ITEM from the


Kth position in an array LA with N elements.

Algorithm:
DELETE (LA, N, K, ITEM)
Here LA is a linear array with N elements and K is positive
integer, such that K ≤ N. This algorithm delete an element
ITEM from the Kth position in LA.

Step 1: Set ITEM := LA [K]


Step 2: [Initialize counter]
Set J := K
Step 3: Repeat step 3 and 4 while J ≤ N
Step 4: [Move Jth element backward]
Set LA[J] := LA[J+1]
Step 5: [Increment counter]
J := J + 1
[End of step 2 loop]
Step 6: [Reset N]
Set N := N - 1
Step 7: Exit

VICKY CHAUHAN (MVC) 9920644662 73


COMPUTER SCIENCE

BUBBLE SORT:
Arranging elements of an array in ascending or descending
order is called sorting.

Following algorithm sort linear array LA with N elements.

Algorithm:
BUBBLE_SORT (LA, N)
Here LA is a linear array with N elements. This algorithm
sorts elements of LA in ascending order.

Step 1: Repeat step 2 and step 3 for I := 1 To N - 1


Step 2: [Initialize counter]
Set J := 1
Step 3: Repeat while J ≤ N – I
a) If LA [J] > LA [J + 1],
Then interchange LA [J] and LA [J + 1]
[End of If structure]
b) [Increment counter]
Set J := J + 1
[End of inner loop]
[End of outer loop]
Step 4: Exit

Explanation:
Suppose LA IS an array of N elements. Sorting these
elements in ascending order means arranging the elements
such that: LA[1] ≤ LA[2] ≤ LA [3] ≤ … ≤ LA[N].

74 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

In bubble sort, compare LA[1] with LA[2] and exchanged


them if LA[1] > LA[2]. Next LA[2] is compared with LA[3].
They are exchanged if necessary. This process is repeated
till LA[N - 1] is compared with LA[N].
One make N – 1 comparisons, this is called pass. After the
first pass the largest element is bubbled to the last
position.

During the next pass, compare elements up to N – 2. In


this way reduce one element for comparison in every pass.
After N – 1 passes, all the elements are sorted.

Example: consider LA with 5 elements: 5, 12, 3, 9, 16


Here, we have to make 4 passes.

Pass 1: (4 comparisons)
● 5, 12, 3, 9, 16
○ the list stays the same because 5 is less than 12.
● 5, 3, 12, 9, 16
○ 3 and 12 are switched because 3 is less than 12
● 5, 3, 9, 12, 16
○ 9 and 12 are switched since 9 is less than 12
● 5, 3, 9, 12, 16
○ 12 and 16 do not switch because 12 is less than 16

Pass 2: (3 comparisons)
● 3, 5, 9, 12, 16
○ 3 is less than 5, so they switch
● 3, 5, 9, 12, 16
○ 5 is less than 9 so they remain in the same places
● 3, 5, 9, 12, 16
○ 12 is greater than 9 so they do not switch places

VICKY CHAUHAN (MVC) 9920644662 75


COMPUTER SCIENCE

Pass 3: (2 comparisons)
● 3, 5, 9, 12, 16
○ 3 is less than 5, so they do not switch
● 3, 5, 9, 12, 16
○ 5 is less than 9 so they remain in the same places

Pass 4: (1 comparison)
● 3, 5, 9, 12, 16
○ 3 is less than 5, so they do not switch

In this way after complete execution of this algorithm,


the array gets sorted in ascending order.

SEARCHING:
Searching means to find out particular element from s
given list of elements or check whether required element
is present or not in an array. There are two type of
searching algorithm as follows:
1. Linear search
2. Binary search

Linear search: In linear search algorithm desire element


is compare with all the elements in an array until the match
is found.

Binary search: In binary search desire element is compare


with value of midpoint. If the value is less than midpoint
value then first half is checked, otherwise second half is
checked until search is successful or interval is empty. For
doing this array has to be sorted in ascending order.

76 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

LINEAR SEARCH:
In linear search algorithm desire element is compare with
all the elements in an array until the match is found.

Algorithm:
LINAER (LA, N, ITEM, LOC)
Here LA is linear array with N elements and ITEM is given
element. This algorithm finds the location LOC of ITEM in
LA or set LOC = 0, if search is unsuccessful.

Step 1: [Insert IEAM at the end of LA]


Set LA [N + 1] := ITEM
Step 2: [Initialize counter]
Set LOC := 1
Step 3: [Search for ITEM]
Repeat while DATA [LOC] ≠ ITEM:
Set LOC := LOC + 1
[End of loop]
Step 4: If LOC = N + 1, then:
Set LOC := 0
Step 5: Exit

Example:
Let LA has following 5 elements:

9 14 26 37 45
Suppose ITEM = 26

Step 1: Set LA [6] := 26 ∴ List becomes


9 14 26 37 45 26
Step 2: Set LOC := 1

VICKY CHAUHAN (MVC) 9920644662 77


COMPUTER SCIENCE

Step 3: Since LA [1] = 9 ≠ 26


Since LA [2] = 14 ≠ 26
Since LA [3] = 26 = 26 = ITEM
Step 4: Hence ITEM = 26 found at position LOC = 3
Step 5: Exit

BINARY SEARCH:
Binary search algorithm is used to search an element from
sorted array. In binary search desire element is compare
with value of midpoint. If the value is less than midpoint
value then first half is checked, otherwise second half is
checked until search is successful or interval is empty.

Algorithm:
BINARY (LA, LB, UB, ITEM, LOC)
Here LA is sorted array with lower bound LB and upper
bound UB. ITEM is given element. BEG denotes beginning,
MID denotes middle and END denotes end location of LA.
This algorithm finds the location LOC of ITEM in LA or
sets LOC = NULL, if search is unsuccessful.

Step 1: [Initialize variables]


Set BEG := LB, END := UB and
MID := INT ((BEG + END)/2)
Step 2: Repeat step 3 and 4
While BEG = END AND LA [MID] ≠ ITEM
Step 3: If ITEM < LA[MID], then:
Set END := MID – 1
Else:
Set END := MID + 1
[End of if structure]

78 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Step 4: Set MID := INT ((BEG + END)/2)


[End of step 2 loop]
Step 5: If LA [MID] = ITEM, then:
Set LOC := MID
Else:
LOC := NULL
Step 6: Exit

Example:
Let LA has following 13 elements:

9 14 26 37 45 67 78 89 90 97 100 105 150


Suppose ITEM = 45

Step 1: Initially BEG = 1 and END = 13


Hence MID = INT ((1+13)/2) = 7
and so LA[MID] = LA[7] = 78
Step 2: Since 47 < 78, END has its value changed by
END = MID – 1 = 7 – 1 = 6
Hence MID = INT((1+6)/2) = 3
and so LA[MID] = LA[3] = 26
Step 3: Since 45 > 26, BEG has its value changed by
BEG = MID + 1 = 3+1 = 4
Hence MID = INT((4+6)/2) = 5
and do LA[MID] = LA[5] = 45
∴ Found ITEM in location LOC = MID = 5

VICKY CHAUHAN (MVC) 9920644662 79


COMPUTER SCIENCE

ADVANTAGES OF BINARY
SEARCH:
1. Binary search algorithm is efficient as the search
scope gets reduced to half the size of the array, with
each iteration.
2. The number of comparison required are
approximately equal to log2n which are less than linear
search.
3. For example:
Let LA has following 13 elements:
9 14 26 37 45 67 78 89 90 97 100 105 150
Suppose ITEM = 45
Step 1: Initially BEG = 1 and END = 13
Hence MID = INT ((1+13)/2) = 7
and so LA[MID] = LA[7] = 78
Step 2: Since 47 < 78, END has its value changed by
END = MID – 1 = 7 – 1 = 6
Hence MID = INT((1+6)/2) = 3
and so LA[MID] = LA[3] = 26
Step 3: Since 45 > 26, BEG has its value changed by
BEG = MID + 1 = 3+1 = 4
Hence MID = INT((4+6)/2) = 5
and do LA[MID] = LA[5] = 45
∴ Found ITEM in location LOC = MID = 5
In above example only two comparisons are required
because in each iteration MID is calculated only one
half is checked.
In the same example, for linear search, 5 comparison
are required.

80 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

DISADVANTAGES OF BINARY
SEARCH:
1. The given list must be sorted.
2. The access of list must be random means the middle
element can be accessed.
3. At each iteration, middle entry calculation is
required.

QUESTIONS FORM MODULE 2:


1. Explain in brief any six data structure operations.
2. Explain with flowchart the following control structures:
sequence logic, selection logic, Iteration logic.
3. What is linear array?
4. What is traversing an array? Give example for traversing
a linear array.
5. What is inserting? Write an algorithm for inserting an
element to an array.
6. What is deleting? Write an algorithm for deletion of an
array.
7. Explain bubble sort algorithm with suitable example.
8. What do you understand by the searching? Which are
the different types of searching algorithms? Explain
linear searching algorithm.
9. Write an algorithm for binary search technique with
suitable example.
10. Explain the advantages of binary search algorithm
with suitable example. State any two disadvantages or
limitation of binary search.

VICKY CHAUHAN (MVC) 9920644662 81


COMPUTER SCIENCE

MODULE 3:
REPRESENTATION
OF DATA
STRUCTURE

82 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

POINTER ARRAY:
An array is called pointer array, if element of that array is
pointer. An element is called pointer, if it points to another
variable i.e. it contains memory address of another
variable.
Example: Consider an organization, which divides its
employee list into four groups.
Group 1 Group 2 Group 3 Group 4
Deepak Swapnil Amol Yashwant
Nitin Amit Yogesh Chintamani
Vivek Shekhar Kishore
Ravi Rohit
If these groups are to be presented in memory, the most
efficient way is to use arrays. The first is Employee array,
which contains list of Employees in all four groups
sequentially, while the second array is group array, which is
a pointer array, which contains starting address of each
group in the Employee array, respectively.
Employee
1 Deepak
Group 1 Nitin
2
3 Swapnil
4 Amit Group: pointer array
Group 2
5 Vivek 1 1
6 Ravi 3 2
7 Amol 7 3 n
Group 3 8 Yogesh 10 4
9 Shekhar
10 Yashwant
11 Chinatamani
Group 4
12 Kishore
13 Rohit
VICKY CHAUHAN (MVC) 9920644662 83
COMPUTER SCIENCE

RECORD:
• A record is collection of relative data item, each of
which is called as field or attribute.
• Collection of records is known as files. Collection of
data is frequently organized into a hierarchy of fields,
records and files.
• A record may contain non-homogeneous data i.e. data
items of record need not be of same data type. In a
record, natural ordering of elements is not possible.
The elements in record can be described by level
number.
Example: An organization keeps records of its Employees.
It contains following data items- Name, Sex, Birthday,
Address. Name is group item consisting of First name,
Middle name and last name. Also, Birth date and address
are group items.
The structure of this record is shown in figure below.
1. Employee
2. Name
3. First name
3. Middle name
3. Last name
2. Sex
2. Salary
2. Birth date
3. Date
3. Month
3. Year
2. Address
3. City
3. Pin code

84 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

• The number to the left of each variable indicates level


number.
• Employee (30) – This indicates a file of 30 records.
• To access first name of 3rd employee, we should write
Employee(3).Name.First_name. In this way we can
access variables in records.

DIFFERENCE BETWEEN RECORDS


AND LINEAR ARRAY

Records Linear array


A record is a collection of An array is list of
fields. homogeneous data elements.
A record may contain non- An array always contains
homogeneous data i.e. data homogeneous data.
elements may be of
different data types.
Natural ordering of Elements can be naturally
elements is not possible. ordered.
Elements of record are Elements of an array can be
referenced by level number, referenced by an index set
of consisting of “n”
consecutive number.

VICKY CHAUHAN (MVC) 9920644662 85


COMPUTER SCIENCE

REPRESENTATION OF RECORD
IN MEMORY USING ARRAY
Consider a record, whose structure is given below:
1. Employee
2. Name
3. First name
3. Last name
2. Sex
2. Address
3. City
3. Pin code
2. phone no.
To represent this record in memory, linear array are used.
One separate linear array is used for each elementary
item of record such as First name, Last name, Sex, City,
Pincode, Phone no.
Following figure shows representation of above record
using parallel linear arrays.
First name Last name Sex City Pincode Phone no.
Record [1]
Record [2]

The records are stored in memory using parallel linear


arrays such that for an index K of all records, First name
[K], Last name [K], Sex [K], City [K], Pincode[K], Phone no
[K] belongs to the same records in a file (i.e Kth record in
the file).

86 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

LINKED LIST
• A linked list is a linear collection of data elements,
called nodes, where the linear order is maintained with
the help of pointers. Linked list is also called one way
list.
• Each node in linked list is divided into two parts. First
part is called INFO part, which contain the information
about the element or actual element and second part is
called LINK part, which is next pointer field i.e. it
contains the address of next node in the list.

Example:
Info Link (Pointer to next node)
Start v v
v 12 A 15 B 24 C 33 D 38 E X
12 15 24 33 38

• The above figure shows a linked list having 5 nodes.


• The left part of the node is called info part, which
contains information of the element, while the right
part is link part, which is next pointers field i.e. it
points to next node.
• An arrow is drawn from link part of one node to the
next node to indicate link
• The address of the list is stored in Start of the list.
• The link part of last node is NULL pointer i.e. it
contains nothing.
• To trace the linked list, we just required the address
of start.

VICKY CHAUHAN (MVC) 9920644662 87


COMPUTER SCIENCE

ADVANTAGES OF LINKED LIST


• To store array in memory, required consecutive
memory locations, while to store linked list,
consecutive memory locations are not required.
• Arrays can not be easily extended, while linked list
can be easily extended.
• There is very complicated procedure to insert an
element in an array. One can easily insert an element
in an linked list.
• Similarly, deletion of an array is very complicated,
while deletion from linked list is easy.
• Linked list can be easily implemented and maintained
in computed memory.

88 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

REPRESENTATION OF LINKED
LIST IN MEMORY
Lined list can be represented in memory by using two
arrays respectively known as INFO and LINK, such that
INFO[K] and LINK[K] contains information of element and
next node address respectively.
The list also requires a variable ‘Name’ or ‘Start’, which
contains address of first node. Pointer field of last node
denoted by NULL which indicates the end of list e.g.
consider linked list given below:

Start
v
5 A 9 B 4 C 1 D X
C 1

The linked list can be represented in memory as:

Start INFO LINK


v 1 v D v 0
5
2
3
4 C 1
5 A 9
6
7
8
9 B 4

VICKY CHAUHAN (MVC) 9920644662 89


COMPUTER SCIENCE

STACK AND QUEUE

LIFO SYSTEM
• LIFO system is first in first out system. In this system,
the element which is inserted at last, will be deleted
first.
• Stack is an example of LIFO system. It is a linear
system in which insertion and deletion takes place only at
one end i.e. top of the list.
• The insertion operation is referred to as push and
deletion as pop.

Example: consider a stack of dishes. If we want to add


new dish to this stack then it is added at the top of the
stack also deletion takes place from the top.

FIFO SYSTEM
• A FIFO system is first in first out system. In this type
of system, the element which is inserted first in the list
will also deleted first.
• Queue is an example of FIFO system. A queue is a linear
list, in which insertion takes place only at one end of the
list known as ‘rear’ of the list and deletion takes place at
the other end known as ‘front’ of the list.

Example: A queue for ticket in a cinema hall.

90 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

QUESTIONS FORM MODULE 3:


1. What are pointer arrays?
2. What is record? How it differs from a linear array?
3. How records are represented in memory using array?
4. Show representation of records in memory considering
suitable example of tree records and tree fields.
5. What are linked list? Show a linked list with suitable
example having six nodes with a properly labeled
diagram.
6. How linked list are represented in memory?
7. Explain stack and queue with suitable example.
8. Explain LIFO and FIFO system with suitable examples.

VICKY CHAUHAN (MVC) 9920644662 91


COMPUTER SCIENCE

MODULE 4:
TREE

92 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

TREE:
Tree is a non-linear hierarchical data structure which
consists of finite set of one or more nodes (i.e. collected
data items).

There is specially designated node called the root.


The remaining nodes are partitioned into finite disjoint
set. For e.g. figure shows tree, which has 11 nodes, each
item of data, being a single letter.

Root: A node which has no parent. Generally first node is


called as “root node”. In figure, the node A is the root of
the tree.
Leaf: The node which has no child or children. Such nodes
have degree zero. In figure D, I, F, J, K are the leaf
nodes. Also called a terminal node.
Child: the nodes which are reachable from a node, say u,
through a single edge are called the children of u. e.g. in
figure the children of node C are F, G and H.
Sibling: children of the same parent are said to be siblings
e.g. The nodes D and E are both children of node B. So D
and E are siblings.
AZ

B C

D E F G H

J K
I

VICKY CHAUHAN (MVC) 9920644662 93


COMPUTER SCIENCE

IMPORTANT TERMS RELATED TO


TREE:
Level number:
Each node of tree is assigned a level number. Generally,
the level number of root ‘R’ of the tree is zero and every
other node is assigned to level number which is one more
than the level of its parent.
Example:
A Level 0

B C Level 1

D E F G Level 2
Degree:
The number of sub-trees of a node is called degree of a
node. The degree of a tree is the maximum degree of the
node in a tree.
Example:
AZ
Node Degree
A 2
B C
B 2
C 3
D E F G H D,E,F,G,H 0

Depth / height:
Depth of a tree is defined as maximum level of any node in
a tree. If root is level 0 then depth or height of tree is
equal to 1 + largest level number.
Example: Depth of above tree is 3.
94 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

BINARY TREE:
Binary tree is a finite set of elements called nodes such
that is:
1. It may be empty or
2. It is partitioned into three disjoint subsets:
• There is a single distinguished element called the
root of tree.
• Other two subsets are themselves binary tree
called left sub-tree and right sub-tree of the
original tree.
A left and right sub-tree can be empty. In binary tree,
there is no node with degree greater than two.
Example:
A

B C

D E F G

BASIC TERMINOLOGY: Consider the above example:


The binary tree contains 8 nodes (A to H). Root A is at the
top of tree
1. Left successor: B is left successor of node A.
2. Right successor: C is right successor of node A.
3. Left sub-tree: Left sub-tree consists of nodes B,D,E.
4. Right sub-tree: Right sub-tree consists of nodes
C,F,G and H.
5. Terminal node: D,E,H and G are terminal nodes.
6. Binary tree T1 and T2 are similar if they have same
structure.

VICKY CHAUHAN (MVC) 9920644662 95


COMPUTER SCIENCE

RELATION BETWEEN TOTAL


NUMBER OF NODES AND DEPTH
OF A TREE:
Depth of tree means maximum level of any node in a tree.
Maximum number of nodes of binary tree with depth n is
2n – 1
Example: Depth
Consider following tree with depth
A 1
3
So with depth 3, the total number
of B C 2
node in a given tree is
2 n – 1 = 23 – 1 D E F G 3
=8–1
=7

TERMS RELATED TO BINARY


TREE:
Complete binary tree:
If all leaf nodes of a binary tree have same level number
and every non-leaf node has non-empty left and right sub-
trees then the tree is called as complete binary tree.

Left sub-tree A Right sub-tree

B C

D E F G

96 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Extended binary tree or 2-tree:


A binary tree T is said to be a 2-tree or an extended
binary tree if each node N has either 0 or 2 children. The
nodes with 2 children are called internal node and the node
with 0 children are called external nodes.

Internal node

External node
Binary search tree:
It is a binary tree in which each node N of tree has the
property that the value at N is greater than the value in
the left sub-tree of N and is less than or equal to every
node value in the right sub-tree of N.

28

19 30

10 20 22 35

15

VICKY CHAUHAN (MVC) 9920644662 97


COMPUTER SCIENCE

REPRESENTATION OF BINARY
TREE IN MEMORY
A binary tree can be represented in memory by two types
of representation:
• Linked representation
• Sequential representation

Linked representation:
Linked representation uses three parallel arrays INFO and
LEFT and RIGHT and pointer variable ROOT such that for
an index K, INFO[K] contains actual element, LEFT[K]
contains address of left child and RIGHT[K] contains
address of right child.

Example: consider binary tree as below:

Root
A

B C

X D X X E X F G

X H X X I X X J X

98 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

The above tree can be represented in memory as:

INFO LEFT RIGHT


1 B 7 14
2 G 12 13
3 0
4 E 11 0
Root 5 A 1 9
6 3
7 D 0 0
8 6
9 C 14 2
10 8
11 H 0 0
12 I 0 0
13 J 0 0
14 F 0 0

Sequential representation:
For sequential representation, only one linear array is used.
This array is generally known as TREE such that:
• The root R of the tree is stored in TREE[1].
• If a node N of tree stored in TREE[K], then,
Its left successor is stored in TREE[2*K] and right
successor stored in TREE[(2*K) + 1]
Example: consider binary tree as below:

B C

D E F
VICKY CHAUHAN (MVC) 9920644662 99
COMPUTER SCIENCE

The above tree can be represented in memory as:

TREE
1 A
2 B
3 C
4 D
5 E
6 -
7 F
8 -
9 -
10 -

In general, the sequential representation of a tree with


depth d will require an array with approximately 2d+1
elements

100 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Draw binary tree structure for the following expression:


1) E = (a + b) / [(c * d) - e]

E /

- +

a b * e

c d

2) (2x + y)(a – 7b)3

* y - 3

2 x a *

7 b

VICKY CHAUHAN (MVC) 9920644662 101


COMPUTER SCIENCE

3) [(a + b) * c ] / [a * ((b - c) + a)]

* **

+ c a +

a b - a

b c

4) X = (p + q) / ((r + s) + t)

X /

+ +

p q + t

r s

102 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

5) E = (2X + Y) / (5A – B)3

E /

* Y - 3

2 X * *B

5 A

QUESTIONS FORM MODULE 4:


1. What is tree? What do you mean by root, leaf, siblings
and child about tree?
2. What is binary tree? With suitable example, explain the
terminology describing family relationship between the
elements of a binary tree.
3. What is binary tree? With suitable example, show the
relationship between total numbers of nodes and depth
of a tree.
4. How binary tree are represented in memory?

VICKY CHAUHAN (MVC) 9920644662 103


COMPUTER SCIENCE

Select the correct alternative and rewrite the


following.

1. Finding location of given element is called as ____


a) traversing b) insertion c) search d) none
2. Data item that are divided into sub items are called
as ____.
a) group items b) elementary items c) nodes
d) array
3. In linked list, link field contains ____.
a) value of next node b) address of next node
c) value of previous node d) none
4. A records is a collection of ____
a) files b) array c) field d) maps
5. The time required to execute bubble sort algorithm
having “n” input items is directly proportional to ____
a) n2 b) n c) log2n d) logen2
6. Maximum number of nodes of symmetric binary tree
with depth n are ____
a) 2n b) log2n c) n2 d) 2n - 1
7. Maximum number of symmetric binary tree with
depth 5 are ____
a) 5 b) 25 c) 31 d) 32
8. Accessing each node in an array only once is called __
a) searching b) inserting c) deleting d) traversing
9. The elements of record are ____
a) homogeneous b) similar c) non-homogeneous
d) identical
10. The most efficient search algorithm is ____
a) binary b) reverse c) linear d) pointer
11. The number of comparisons required for bubble
sorting of an array of n elements is ____.
a) n(n - 1)/2 b) n/2 c)log2n d) log10n

104 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

12. finding the location of record with a given key value is


known as ____
a) traversing b) searching c) sorting d) inserting
13. maximum number of nodes in a symmetric binary tree
with depth four are ____
a) 4 b) 15 c) 16 d) 5
14. In ____ data structure, an element may be inserted
or deleted only at one end called top.
a) queue b) array c) stack d) tree

1 c 8 d
2 a 9 c
3 b 10 a
4 c 11 a
5 c 12 b
6 d 13 b
7 c 14 c

VICKY CHAUHAN (MVC) 9920644662 105


COMPUTER SCIENCE

106 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CHAPTER 3:

C++

VICKY CHAUHAN (MVC) 9920644662 107


COMPUTER SCIENCE

MODULE 1:
INTRODUCTION
TO C++

108 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

C++
PROGARAMMING
C++ is object oriented programming
language. Initially C++ was named as
“C with classes”. C++ was developed
by Bjarne Stroustrup at AT & T Bjarne Stroustrup
Bell Laboratories, USA, in the early
eighties

ADVANTAGES OF C++
The advantages of C++ are:

• C++ is increment version of C. Almost all C programs can


also run in C++ compiler
• The important facilities added to C++ are classes,
function overloading, operator overloading.
• C++ supports polymorphism.
• Any real life application system such as editor, compiler,
databases, communication systems can be built by C++.
• Object oriented libraries can be built by C++.
• C++ program can be easily implemented, maintained and
expanded.
• A complex data type is provided.

VICKY CHAUHAN (MVC) 9920644662 109


COMPUTER SCIENCE

DIFFERENCE BETWEEN
TRADITIONAL PROCEDURAL AND
OBJECT ORIENTED
PROGRAMMING LANGUAGE
Traditional Procedural Object Oriented
Programming Programming
In this approach, the In this approach, the
problem is viewed as a problem is decomposed into
sequence of things to be a number of entities called
done. objects and then builds data
and function around these
entities.

Emphasis is on doing things. Emphasis is on the data


rather than procedure

Large programs are divided Programs are divided into


into smaller program known entities known as objects
as function.

Data move openly around the Data is hidden and cannot be


system from function to accessed by external
function function.

Employ top-down approach in Employ bottom-up approach


program design. in program design.

110 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

BASIC DATA TYPE IN C++

Basic data type

integral void floating

int char float double

Integral type: It includes integer (int) and character


(char). An int variable requires 2 bytes to store, while a
character variable required 1 byte.
Integer variable are also of 2 type: a) short int (2 bytes)
b) long int (4 bytes).

Void: To specify the return type of a function when it is


not returning any value. It is used to indicate an empty
argument list to a function. Also used to declare generic
pointer.

Floating type: there are two types of floating type: float


and double. A float variable required 4 bytes, while double
requires 8 bytes to store in memory

There are another kind of double namely long double (10


bytes).

VICKY CHAUHAN (MVC) 9920644662 111


COMPUTER SCIENCE

The following table shows all basic data types and its size
in terms of bytes:

Type Bytes
char 1
int 2
short int 2
long int 4
float 4
double 8
long double 10

112 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

SCOPE RESOLUTION OPERATOR


The operator :: is called scope resolution operator. C++ is
block structured language i.e. a C++ program may contain
one block within another block. When a variable is declared
in program, scope extends from the point of declaration
till the end of the block in which it is defined. The same
variable name can be used to have different meaning in
different block.

Consider following example:


# include <iostream.h>
int num = 10;
void main( )
{
int num = 20;
cout << “Local = ”<< num << endl;
cout << “Global =” << ::num;
}

Here num with value 10 is called global variable which is


hidden from main function with num = 20 (local variable).
Scope resolution operator is used to uncover a hidden
variable

Therefore, first cout statement will print 20 as output,


while second cout statement will print 10 as output as
scope resolution operator (::) before num i.e ::num

Output:
Local = 20
Global = 10

VICKY CHAUHAN (MVC) 9920644662 113


COMPUTER SCIENCE

MEMORY MANAGEMENT
OPERATORS
C++ provides two memory management operator:
new and delete

New: The new operator obtains memory block from OS


and return pointer to its starting point. The new operator
returns NULL, if memory allocation is unsuccessful.
The general format of new operator:
DataType *new DataType[size in integer];

Delete: The delete operator is used to return the memory


allocated by the new operator back to the memory pool.
Thus released memory will be reused by other parts of the
program.
The general format of delete operator:
Delete pointervariable;

Example:
# include <iostream.h>
# include <string.h>
void main( )
{
char *str = “COMPUTER”;
int len = strlen(str);
char * ptr = new char [len+1];
strcpy(ptr, str);
cout << “ptr = ” << ptr;
delete ptr ;
}
114 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

In the above example, the new operator returns a pointer


that points to a memory section large enough to hold the
string str plus extra byte for null character. Then use of
memory delete operator released memory.

VICKY CHAUHAN (MVC) 9920644662 115


COMPUTER SCIENCE

FUNCTION OVERLOADING
• The use of same function name to create functions that
perform a variety of different tasks is called as
function overloading.
• Overloading refer to the use of same thing for
different purposes.
• Using the concept of function overloading, create a
family with one function name but with different
argument lists.
• The function would perform different operation,
depending on argument list in function call.
• The correct function to be invoked is determined by
checking the number and the type of the arguments and
not on the function type.

Consider following example:


# include <iosteam.h>
int area (int l, int b); int area (int l, int b)
int area (int s); {
return (l*b);
main ( ) }
{ int area (int s)
cout << area(10); {
cout << area(5, 10); return (s*S);
} }

In the above example the function area( ) is overloaded.


The first function is used to calculate area of rectangle.
It has two integers parameter. The second function is
used to calculate area of square. It has one integer
parameter.

116 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

How complier identifies function?


When a function is called, the compiler first matches the
prototype having same number and type of arguments and
then calls appropriate function for execution. A best batch
must be unique.

VICKY CHAUHAN (MVC) 9920644662 117


COMPUTER SCIENCE

POINTERS
A pointer is a variable, which holds the memory address of
other variable. “ * ” Operator is used to declare pointer
variable.
The general format of pointer declaration is:
DataType * VariableName;

e.g. int *ptr;

The above declaration will create a variable ptr, which is a


pointer variable and which will point to a variable, whose
data type is integer. Data type of ptr is note an integer
but data type of variable to which ptr pointing is integer.

Advantages of using pointer:


• It allows passing variables, arrays, functions, string,
structures, and objects as function arguments
• It allows to return structure variables from function.
• It supports dynamic allocation and dellocation of
memory segments.
• By using pointer, variables can be swapped, without
physically moving them
• It allows to establish link between data elements or
objects.

118 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CALL BY VALUE AND CALL BY


REFERENCE
Call by value:
• When a portion of the program invokes a function,
control will be transferred from the main program to
the calling function and value of actual arguments is
copied to the function.
• Within function the actual value may be altered or
changed
• When the control is transferred back from function to
the program, altered values are not transeferred back.
This type of passing formal argument to a function is
called as call by value.

Example:
# include <iostream.h>
int sum (int x, int y)
void main( )
{
int a, b;
cout<< “enter 2 nos”;
cin >> a >> b;
cout << sum(a,b);
}
int sum (int x, int y)
{
return (x+y);
}
In above example, we are calling function sum by passing
values of a and b as parameter, which gets copied into x
and y. hence whatever calculation is done that will be with
respect to x and y only not w.r.t a and b.
VICKY CHAUHAN (MVC) 9920644662 119
COMPUTER SCIENCE

Call by reference:
• In call by reference, when a function is called by a
program the address of the actual arguments are copied
on to the formal arguments. i.e. the formal and actual
arguments are referring to same memory location.
• Therefore change in value of formal argument affects
the value of actual arguments.
• The content of a variable that are altered within the
function are return to calling portion of a program in the
altered form.

Consider following example:


# include <iostream.h> void swap(int *x, int *y)
void swap(int *x, int *y); {
void main ( ) int temp;
{ int a, b; temp = *x;
cout << “Enter 2 numbers”; *x = *y;
cin >> a >> b; *y = temp;
cout << “a=”<< a << “b=” << b; }
swap (&a,&b);
cout << “After swapping”;
cout << “a=”<< a << “b=” << b;
}
In above example, we are calling function sum by passing
address of a and b as parameter, which gets copied into
pointer variables x and y. hence we are swapping the actual
variable not it’s dummy.
OUTPUT Enter 2 numbers
56
a=5b=6
After swapping
a=6b=5

120 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

QUESTIONS FORM MODULE 1:


4. What is C++? What are the advantages of C++?
5. Differentiation between traditional procedural language
programming approach and object oriented programming
approach.
6. Enlist the basic data types used in C++ with the size of data
in terms of byte for each.
7. Explain the use of scope resolution operator and memory
management operator with examples.
8. Explain the concept of function overloading with suitable
example.
9. What are pointers? Give the advantages of using pointer.
10. What are pointers in C++? Explain the use of pointer
variables for function definitions using call by value and call
by reference.

VICKY CHAUHAN (MVC) 9920644662 121


COMPUTER SCIENCE

MODULE 2:
INTRODUCTION
OOPS

122 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

PRINCIPLE OF OBJECT
ORIENTED PROGRAMMING:
Definition of OOP:
• “Object oriented programming is an approach that
provides a way of modularizing programs by creating
partitioned memory area for both data and functions
that can be used as templates for creating copies of
such modules on demand.”
• In object oriented programming, the program is designed
around the data being operated upon rather than upon
operations themselves.
• It ties data more closely to functions that operate on it.
OOP allows decomposing a problem into a number of
entities called objects and then builds data and
functions around these entities.

Features of OOP:
• Emphasis is on data rather than procedure.
• Programs are divided into number of objects.
• Data structures are designed such that they
characterized the object.
• Functions that operated on the data of an object are
tied together in the data structure.
• Data is hidden and cannot be accessed by other external
functions.
• Objects may communicate with each other through
function.
• New data and functions can be easily added wherever
required.

VICKY CHAUHAN (MVC) 9920644662 123


COMPUTER SCIENCE

CONCEPT RELATED TO OOP


Objects:
• Objects are basic runtime entity in object-oriented
system. For e.g. they may represent a person, place, a
bank account or any item that the program must handle.
• Programming problem is analyzed in terms of objects and
nature of communication between them.
• Program objects should be chosen such that they match
closely with the real-world objects.

Classes:
• Class is a way to bind data and its associated function
together.
• The entire set of data and code of an object can be
made a user define data type with the help of a class.
• In fact an object is nothing but a variable, whose data
type is class.
• Once a class has been defined, user can define any
number of objects belonging to that class.
• A class is a collection of objects of similar type.

Inheritance:
• The mechanism of deriving a new class from existing one
is called as inheritance.
• Inheritance is the process by which object of one class
can acquire the properties of objects of another class.
• In OOP, inheritance stands for reusability. This means
that additional feature can be added to an existing class
without modifying it.

124 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Polymorphism:
• Polymorphism is an important OOP concept.
Polymorphism means ability to take more than one form.
• Polymorphism plays an important in allowing objects
having different internal structures to share the same
external interface.
• This means that a general class of operation may be
accessed in the same manner even though specific
actions associated with each operation may differ.
• Polymorphism is extensively used in implementing
inheritance.

Data abstraction:
• Abstraction refers to the act of representing essential
features without including the background details of
explanations.
• Classes are the concept of abstraction and are defined
as a list of abstract attributes and functions to operate
on these attributes.
• They encapsulation all the essential properties of the
object that are to be created.

QUESTIONS FORM MODULE 2:


1. What is object-oriented programing? Enlist the feature of
object-oriented programming.
2. Explain following OOP concepts with an example of each:
1. Inheritance 2. Polymorphism 3. Data abstraction.

VICKY CHAUHAN (MVC) 9920644662 125


COMPUTER SCIENCE

MODULE 3:
INTRODUCTION
CLASS

126 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CLASS
Class is a way to bind data and its associated function
together. It allows the data and function to be hidden, if
necessary, from external use. When defining a class, a new
abstract data type that can be created that treated like
any other build-in data type.

Generally, a class specification has two parts:


• Class declaration
• Class function definition

Class declaration:
The class declaration describes the type and scope of its
members.
Syntax:

class class_name
{
private:
declaration of variable;
declaration of function;
public:
declaration of variable;
declaration of function;
};

• The keyword class specifies that class_name is abstract


data type.
• The body of class is enclosed within braces and
terminated by a semicolon.

VICKY CHAUHAN (MVC) 9920644662 127


COMPUTER SCIENCE

• The body of the class contains declaration of class


members, which are variable and function they are
generally grouped under two sections private and public,
which are known as visibility labels. (These keywords are
followed by a colon).
• private: The members, declared as private can be
accessed only from within the class. It hides data from
external use.
• public: The public member can be accessed from outside
the class also.
• If both the visibility labels are missing then by default,
the members of the class are private

Class function definition:


The class function definitions describe how class functions
are implemented.

Example
class item
{
private:
int number;
float cost;
public:
void getdata(int a, int b);
void putdata(void);
};

128 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

WAY OF DEFINING MEMBER


FUNCTIONS:
Member function of the class can be defined at two
places:
• Outside the class definition
• Inside the class definition

Outside the class definition:


Syntax:
return-type class-name :: function-name(argument list)
{
Function body
}

The member function incorporates an identity label or


membership label (i.e. class-name ::).

This label tells complier the class to which the function


belongs and restricts the scope of that function the
object of the class “class-name” specified in header line.

Example
class add void add :: sum(int x, int y)
{ {
private: z = x + y;
int z; cout <<”Total is”<< z;
public: }
void sum(int x, int y);
};

VICKY CHAUHAN (MVC) 9920644662 129


COMPUTER SCIENCE

Inside the class definition:


In this method, we replace the function declaration by
actual function definition.

Example
class add
{
private:
int z;
public:
void sum(int x, int y)
{
z = x + y;
cout <<”Total is”<< z;
}
};

When function is defined inside a class, it is treated as an


inline function. Normally, only small function are defined
inside the class definition.

QUESTIONS FORM MODULE 3:


1. What is class? Explain general form of class declaration.
2. Describe how member functions of class can be defined
outside the class definition and inside the class
definition.

130 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 4:
FRIEND FUNCTION
STATIC DATA
MEMBER

VICKY CHAUHAN (MVC) 9920644662 131


COMPUTER SCIENCE

FRIEND FUNCTIONS
C++ allows the common function to be made friendly with
more than one class, thereby allowing the function to have
access to the private data of classes. Such a function need
not be a member of any classes.
Non-member function cannot have access to the private
data of a class. However, there could be a situation where
user would like two classes to share a particular function.
At this situation friend function is used.

The general format of friend function:


class class-name
{
private:
…….
…….
public:
…….
friend return-type function-name (argument list);
};

The keyword “friend” declares that the function to be


friend with that class. This function is defined as normal
C++ function. The function definition does not use class-
name, keyword friend or scope resolution operator.

132 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CHARACTERISTICS OF FRIEND
FUNCTION:
1) It is not in the scope of the class to which it has
been declared as friend.
2) Since it is not in the scope of the class, it cannot be
called by using object of that class. It is called like
normal C++ function.
3) It can be declared either in public or private part of
a class without affecting its meaning.
4) Usually, it has the objects as arguments.
5) It cannot access the member function directly and
has to use an object name and dot operator with each
member name.

CHARACTERISTICS OF STATIC
DATA MEMBER IN CLASS:
1) It is initialized to zero when the first object of its
class is created. No other initialization is permitted.
2) Only one copy of that class member is created for
the entire class and is shared by all the objects of
that class, no matter how many objects are created.
3) It is visible only within the class, but its lifetime is
the entire program.

VICKY CHAUHAN (MVC) 9920644662 133


COMPUTER SCIENCE

QUESTIONS FORM MODULE 4:


1. What are friend functions? Give the characteristics of a
friend function.
2. Explain in short the three special characteristics of a
static data member in a class.

134 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 5:
CONSRUCTOR AND
DESTRUCTOR

VICKY CHAUHAN (MVC) 9920644662 135


COMPUTER SCIENCE

CONSTRUCTOR AND
DESTRUCTOR
Constructor:
Definition: “It is special member function of a class. Its
task is to initialize the objects of its class.”

Explanation:
• It is special because its name is same as that of the class
to which it belongs.
• The constructor is invoked whenever an object of its
associated class is created.
• It is called constructor because it construct the values of
data member of the class.
• A constructor can never return any value. Hence, it is
written with no return type (even void is not written).

Example
class abc
{
private:
int m, n;
public:
abc (void);
};
abc :: abc (void) // constructor defined
{ m = 0;
n = 0;
}
void main ( )
{
abc p;
}
136 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

Whenever a class contains a constructor like one above, it


will be initialized automatically, whenever an object of that
class is created.
i.e. the declaration abc p;
This not only creates the objects “p” of type abc, but also
initialized its data members m and n to zero.

Parameterized constructor:
Generally a constructor initializes the class object to
predetermined values. But, in practice, it may be necessary
to initialize data elements of objects to different values.
To achieve this we are using parameterized constructor.

Example
class abc
{
private:
int m, n;
public:
abc (int x, int y);
};
abc :: abc (int x, int y) // constructor defined
{ m = x;
n = y;
}
void main ( )
{
abc p(0,1);
}
This creates the objects “p” of type abc, also initialized its
data members m to 0 and n to 1.

VICKY CHAUHAN (MVC) 9920644662 137


COMPUTER SCIENCE

CHARACTERISTICS OF
CONSTRUCTOR:
• The constructor name is always same as the class name.
• They do not have return types, not even void and
therefore, they cannot return values.
• They cannot be static or virtual.
• They should be declared in public section.
• They cannot be inherited.
• Like other C++ functions, they can have default
arguments.
• We cannot refer to their address.
• An object with a constructor cannot be used as member
of union.
• They make implicit calls to the operators ‘new’ and
‘delete’ when memory allocation required.
• When a constructor is declared for a class, initialization
of class objects become mandatory, since constructor is
invoked automatically when the objects are created.

[Above points are syntax rules for constructor.]

Destructor:
Definition:
A destructor is used to destroy the objects that have
been created by constructor.

Explanation:
The destructor is invoked implicitly by the compiler upon
exit from the program to clean up storage that is no longer
accessible. It is good practice to declare destructor in a
program.
138 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

Syntax rule for writing a destructor function:


• A destructor function name is same as that of its class
name, but it is preceded by a tilde. e.g. ~abc( );
• It is declared with no return type since it can never
return any value.
• It takes no arguments.
• It should have public access in the class declaration.

QUESTIONS FORM MODULE 5:


1. What is a constructor? Why it is called so?
2. Give characteristics of constructor function. What are the
syntax rules for writing constructor?
3. What is destructor? Give syntax rule for writing
destructor function.

VICKY CHAUHAN (MVC) 9920644662 139


COMPUTER SCIENCE

MODULE 6:
OPERATOR
OVERLOADING

140 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

OPERATOR OVERLOADING
Definition:
The mechanism of giving some special meaning to an
operator is called as operator overloading.

Explanation:
C++ permits to add two variables of user-defined data
types with the same syntax as the basic types. This means
that C++ has the ability to provide operator with a special
meaning for a data type. This is nothing but operator
overloading.

• With the help of operator overloading we can create new


definitions for most of the C++ operators.
• When operator is overloaded, its original meaning is not
lost. For instance, the operator+ has been overloaded to
add two complex numbers can still be used to add two
integers.
• To give additional task to an operator, special function
called “operator function” is used.

Three steps involving in operator overloading:


1. First create a class that defines the data type that is
to be used in the overloading operation.
2. Declare the operator function operator op ( ) in the
public part of the class. It may be either a member
function or friend function
3. Define the operator function to implement the
required operations.

VICKY CHAUHAN (MVC) 9920644662 141


COMPUTER SCIENCE

Operator function: To give additional task to an operator,


special function called “operator function” is used.

The general format of operator function:


return-type class-name :: operator op(argument list)
{
function body
}

Where return-type is the type of value returned by the


specified operation and op is the operator being
overloaded. Operator is preceded by the keyword
operator. Operator function must be either member
functions or friend functions.

Basic difference between operator function as friend


function and as member function:

Operator function as Operator function as


friend function member function
Friend function will have Member function will has no
only one argument for unary argument for unary operator
operator and two arguments and one arguments for
for binary operator binary operator

Advantages of operator overloading:


• Operator overloading concept extends capability of
operators to operate on user-define data.
• It can also be applied to data conversion.
• Using operator-overloading technique, user-defined data
types behave in much the same way as the build-in type.

142 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Rules for overloading operators:


1. Only existing operator can be overloaded. New
operators cannot be created.
2. The overloaded operator must have atleast one
operand that is of user-defined type.
3. The basic meaning of operator cannot change.
4. The overloaded operator follows the syntax rules of
original operators.
5. Following are some operators that cannot be
overloaded
Size of Size of operator
. Membership operator
* Pointer to membership operator
:: Scope resolution operator
?: Conditional operator

6. Following operators cannot be overloaded using friend


function but member function can be used to overload
them
= Assignment operator
( ) Function call operator
[ ] Subscripting operator
-> Class member access operator

7. Unary operator, overloaded by means of a member


function, take no argument.
8. Unary operator, overloaded by means of a friend
function, take one argument.
9. binary operator, overloaded by means of a member
function, take one argument.
10. binary operator, overloaded by means of a friend
function, take two arguments.

VICKY CHAUHAN (MVC) 9920644662 143


COMPUTER SCIENCE

Example
# include <iostream.h>
class counter void main( )
{ {
private: counter c1, c2;
int count; cout <<“c1=”<<c1.get_count( );
public: cout<<“c2=”<<c2.get_count( );
counter ( ) c1++;
{ c2++;
count = 0; ++c2;
} cout <<“c1=”<<c1.get_count( );
int get_count( ) cout<<“c2=”<<c2.get_count( );
{ }
return count;
}
void operator ++ ( )
{
count++;
}
};

In the above program, two objects of class counter : c1


and c2 are created. They are initially display 0. Then using
overloading ++ operator, increment c1 once and c2 twice
and display resulting values.

OUTPUT c1=0 …….


c2=0
c1=1
c2=2

144 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

DATA TYPE CONVERSION


Three type of data conversion in C++ are as follows:
• Conversion from built-in type to class type.
• Conversion from class type to built-in type.
• Conversion from one class to another class.

Buit-in to class type: The constructor can be used for


default type conversion from argument’s type to the
constructor’s class type.
Example
# include <iostream.h>
class time void main( )
{ {
private: time t1
int hr, min; int duration = 90;
public: t1 = duration
time (int t) }
{
hr = t/60;
min = t%60;
}
};
After execution of above program, the hr member of t1
will contain value 1 and min contain.

Class to built-in type: Overloaded casting operator is


used to convert a class type
General format:
Operator typename( )
{
function statement
}

VICKY CHAUHAN (MVC) 9920644662 145


COMPUTER SCIENCE

The conversion function must satisfy following condition:


• It must be a class member.
• It must not specify a return value.
• It must not have any arguments.

Example
# include <iostream.h> void main( ) ………
class time {
{ time t1;
private: int m = t1;
int hr, min; }
};
time :: operator int( )
{
int min1 = hr * 60;
min1 = min1 + min;
return min1;
}

After execution of above program 1hr 30 mins can be


converted into 90 min.

One class to another class:


Use one argument constructor or conversion function
depends upon the defining conversion routine insource
class or destination class.

Example:
obj A = obj B

Destination Source

146 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

QUESTIONS FORM MODULE 6:


1. What is operator overloading? Explain with suitable
example.
2. What are advantages of operator overloading.
3. What is operator overloading? State three steps involving
in operator overloading.
4. What is operator overloading? Described the syntax of an
operator function. Explain the difference between
operator function as member function and friend function.
5. State any eight rules for operator overloading.
6. Explain the three-type conversion in C++ with suitable
example.

VICKY CHAUHAN (MVC) 9920644662 147


COMPUTER SCIENCE

MODULE 7:
INHERITANCE

148 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

INHERITANCE
Definition:
The mechanism of deriving a new class from an old one is
called as inheritance. The old class is called base class and
new is called derived class.

Explanation:
C++ supports the concept of reusability. Once class has
been written and tested, same class ca be used by other
programmer to suit their requirement.
This can be done by creating new classes, reusing the
properties of existing ones.
Because of reusability one can save time and efforts for
development of same class.

Figure shows inheritance:

Feature A Feature C

Feature B Feature A

Base class Feature B

Derived class

VICKY CHAUHAN (MVC) 9920644662 149


COMPUTER SCIENCE

Syntax:
class derived-class-name : visibility-mode base-class-name
{
//Members of derived class
};
Where visibility mode is optional and if present may be
either public or private.

Example
# include <iostream.h>
class base void main( )
{ public: { derived p;
void showbase( ) p.showderived;
{ }
cout<< “BASE”;
}
};
class derived:public base
{ public:
void showderived( )
{
showbase( );
cout<<“DERIVED”;
}
};

By creating object of derived we can call function


showbase ( ).

OUTPUT BASE
DERIVED

150 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

TYPES OF INHERITENCE

Single inheritance: A derived class with only one base


class is called as single inheritance.

It has the form:


A Base class
class B : visibility-mode A
{
//Members of B
B Derived class
};

Multilevel inheritance: The mechanism of deriving one


class from another derived class is multilevel inheritance.

It has the form


class B : visibility-mode A Grand father
A
{
//Members of B
}; father
B
class C : visibility-mode B
{
//Members of C
C child
};
C

VICKY CHAUHAN (MVC) 9920644662 151


COMPUTER SCIENCE

Multiple inheritance: When a class is derived from several


classes, it is called as multiple inheritance

It has the form


class D: visibility-mode B1, visibility-mode B2,…
{
//Members of D
};

B1 B2 .... Bn
Base class
2 B1

D Derived class

Hierarchical inheritance: The traits of one class may be


inherited by more than one classes. This process is known
as hierarchical inheritance.

It has the form


B Base class
class D1 : visibility-mode B
{ A
//Members of D1
};
class D2 : visibility-mode B
{ D1 D2 D3 Dn
....
//Members of D2 C D2 33
}; Derived classes
.
.
.

152 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Hybrid inheritance: The inheritance which involves more


than one inheritance is called hybrid inheritance.

EXAMPLE: B

A C
A

D
A

class A : visibility-mode B
{
//Members of A
};
class C : visibility-mode B
{
//Members of C
};
class D : visibility-mode A, visibility-mode C
{
//Members of D
};

Above figure involves hierarchical, multiple and multilevel


inheritance and the resultant inheritance is called hybrid
inheritance.

VICKY CHAUHAN (MVC) 9920644662 153


COMPUTER SCIENCE

QUESTIONS FORM MODULE 7:


1. What is inheritance? Explain with suitable example.
2. Explain different types of inheritance with suitable
diagram.

154 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 8:
POLYMORPHISM

VICKY CHAUHAN (MVC) 9920644662 155


COMPUTER SCIENCE

POLYMORPHISM
Polymorphism refers to identically named methods that
have different behavior depending on the type of object
they refer.
Polymorphism simply means “one name, multiple forms”.

Polymorphism

Compile time Runtime


Polymorphism Polymorphism

Function Operator Virtual


overloading overloading function
Types of polymorphism

Compile time polymorphism:


• Function overloading and operator overloading are
examples of compile time polymorphism.
• In this case, the overloaded member functions are
selected for invoking by matching arguments, both type
and number.
• This information is known to compiler at the compile
time and, therefore the compiler is able to select the
appropriate function for a particular call at the compile
time itself.
• Compile time polymorphism is also called early binding or
static binding or static linking

156 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Runtime polymorphism:
In some situation, it is nice to select appropriate member
function to be invoked while the program is running. This is
known as runtime polymorphism.

Example
class A class B: public A
{ {
private: private:
int x; int y;
public: public:
void show( ) void show( )
{…} {…}
}; ……. };

Here show( ) function is used to print values of object of


both the classes A and B. the prototype of show( ) is the
same in both places, the function is not overloaded and
therefore static binding does not apply.
• In such situation, the appropriate member function can
be selected at runtime and it is known as runtime
polymorphism.
• To achieve this C++ supports mechanism of virtual
functions.
• At runtime, it is known what class objects are under
consideration, appropriate version of function is called.
• Since the function linking is done much after its
compilation, this process is also called late binding or
dynamic binding.

VICKY CHAUHAN (MVC) 9920644662 157


COMPUTER SCIENCE

Hence in dynamic binding, classes are defined as:


class A class B: public A
{ {
private: private:
int x; int y;
public: public:
virtual void show( ) void show( )
{…} {…}
}; };

RULES FOR VIRTUAL


FUNCTIONS
1. The virtual function must be member of some class.
2. They cannot be static.
3. They are accessed by using object pointer.
4. A virtual function can be friend of another class.
5. A virtual function in a base class must be defined, even
though it is not used.
6. The prototype of the base class version of virtual
function and all derived class version must be identical.
Otherwise C++ considers them as overloaded functions
and not virtual function.
7. We cannot have virtual constructor, but we can have
virtual destructors.
8. Virtual functions are define in base class, they need not
be define in derived class.
9. A base pointer points to any type of derived object, the
reverse is not true. i.e. we cannot use pointer to derived
class to access an object of the base type.
10. When a pointer points to an derived class,
incrementation and decrementation is only relative to its
base class.
158 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

QUESTIONS FORM MODULE 8:


1. What is polymorphism? Explain runtime and compile time
polymorphism.
2. State any eight rules for virtual functions that satisfy the
complier requirements.

VICKY CHAUHAN (MVC) 9920644662 159


COMPUTER SCIENCE

MODULE 9:
WORKING WITH
FILES:

160 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

INPUT AND OUTPUT STREAMS:


Input stream

Read Data
data input

Disk
files Program

Data
Write Output stream
output
data

• The I/O system of C++ handles file operations, which are


very similar to console input output operations.
• It uses file stream as an interface between the program
and the files.
• The stream that supply data to the program is known as
input stream, while the stream that receive data from
program is known as output stream.
• In other word input stream read data from files and
output stream write data to a file.
• Input operation involves the creation of an input stream
and linking it with the program and the input files
• Output operation involves establishing an output stream
and linking it with the program and the output files.

VICKY CHAUHAN (MVC) 9920644662 161


COMPUTER SCIENCE

VARIOUS CLASSES AVAILABLE


FOR FILE OPERATIONS
• The I/O system of C++ contains a set of classes that
defines the file handling methods. These includes:
ifstream, ofstream and fstream.
• These classes are derived from fstreambase and the
corresponding iostream.h class as shown figure.
• These classes designed to manage the disk files, are
declared in fstream.h and therefore, we must include this
file in any program that uses files.

iostream.h file
ios

istream streambuf ostream


nstreamb streambuf

iostream

ifstream fstream ofstream filebuf

fstream base
fstream.h file
base

162 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

The detail of file stream classes is given in the following


table

Classes Contents
1. filebuf It perpose is to set the file buffer to read
and write. Contains ‘openprot’ constant and
used in the “open( )” of file stream class.
Also contains close( ) and open( ) as
members.
2.fstreambase Provides operations common to the file
streams serves as base class for fstream,
ofsream and ifsream class.
Contains open( ) and close( ) functions.
3. ifstream Provides input operations and contains
open( ) with default input mode. Inherits
get( ), getline( ), read( ), seekg( ), and
tellg( ) from istream.
4. ofstream Provides output operations and contains
open( ) with default output mode. Inherits
put( ), write( ), seekp( ), and tellp( ) from
ostream.
5. fstream Provides support for simultaneous input
and output operations. Contains open( )
with default input mode. Inherits all the
function from istream and ostream classes
through iostream.

VICKY CHAUHAN (MVC) 9920644662 163


COMPUTER SCIENCE

FILES MODES
Parameter Meaning
ios::app Append to end of file.
ios::ate Go to end of file on opening.
ios::binary Binary file.
ios::in Open a file for reading only.
ios::nocreate Open a fails if the file does
not exist.
ios::noreplace Open a fails if the file
already exist.
ios::out Open a file for writing only.
ios::trunc Delete content of file, if
exist.

164 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

HOW TO OPEN AND CLOSE ANY


FILE IN C++
Opening a file:
The general format for opening a file:
file-stream-class stream-object;
stream-object.open(“file-name”);
Here ifstream class is used to read a steam of object
from a file and ofstream class is used to write a stream of
object in a file.

Example
Open a file to read strean object from “data”:
ifstream p;
p.open(“data”);

Open a file to write strean object from “data”:


ofstream q;
q.open(“data”);

Closing a file:
Function close( ) is used to close s file, which is opened for
read or write operation
The general format for opening a file:
stream-object.close( );
Here stream-object is object created to open any file. In
above example we opened file data for writing purpose by
creating object q, which can be closed as q.close( ).

VICKY CHAUHAN (MVC) 9920644662 165


COMPUTER SCIENCE

QUESTIONS FORM MODULE 9:


1. What are input and output streams?
2. Describe the various classes available for file operation.
3. State the details of the following file stream: 1. ifstream
2. ofstream
4. What are classes in C++ for file stream operation? How do
you open and close file in C++? Explain any four file modes.

166 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

MODULE 10:
IMPORTANT
PROGRAMS

VICKY CHAUHAN (MVC) 9920644662 167


COMPUTER SCIENCE

Program1: Write a program to find GCD of


two numbers

#include<iostream.h>

void main( )
{
int a, b;

cout<<”Enter two numbers”<<endl;


cin>>a>>b;

while(a!=b)
{
if(a>b)
a = a – b;
else
b = b – a;
}

cout<<”GCD of two number is”<<a;


}

168 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program2: Program to find GCD of two


numbers using OPPs

#include<iostream.h>
class gcd
{
public:
void gcd1(int x, int y);
};

void gcd : : gcd1(int x, int y)


{
while(x!=y)
{
if(x>y)
x = x - y;
else
y = y - x;
}
cout<<”gcd of entred number is”<<x;
}

void main( )
{
int a,b;
gcd p;

cout<<”enter two integers”;


cin>>a>>b;
p.gcd1(a,b);
}

VICKY CHAUHAN (MVC) 9920644662 169


COMPUTER SCIENCE

Program3: Read 10 nos to an array and calculate


their sum and average.

#include<iostream.h>
void main( )
{
int a[10], i, sum=0;
float avg;

cout<<”Enter 10 numbers”<<endl;
for(i=0; i<10; i++)
{
cin>>a[i];
}

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


{
sum = sum + a[i];
}

avg = sum/10.0;

cout<<”sum of 10 numbers is”<<sum<<endl;


cout<<”average of 10 number is”<<avg;
}

170 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program4: Print first n numbers of Fibonacci


series

#include<iostream.h>

void main( )
{
int f0=0, f1=1, f, n, i;

cout<<”Enter how many number of Fibonacci series”;


cin>>n;

cout<<”\n Fibonacci series is”<<endl;


cout<<f0<<f1;

for(i=0; i<n-2: i++)


{
f = f0 + f1;
cout<<f;
f0 = f1;
f1 = f;
}
}

VICKY CHAUHAN (MVC) 9920644662 171


COMPUTER SCIENCE

Program5: Write a program to count number of


words in given text

#include<iostream.h>
#include<stdio.h>
#include<string.h>

void main( )
{
int l, count=0, i;
char a[100];

cout<<”Enter any text”<<endl;


gets(a);

l = strlen(a);

for(i=0; i<l, i++)


{
if(a[i]==” ”)
count++;
}

cout<<”number of words in entered text are”<<count;

172 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program6: Write a program to calculate factorial


of a number

#include<iostream.h>

void main( )
{
int f=1, n, i;

cout<<”which factorial you want to calculate”<<endl;


cin>>n;

for(i=1; i<=n; i++)


{
f=f * i;
}

cout<<”factorial of entered number is”<<f;


}

VICKY CHAUHAN (MVC) 9920644662 173


COMPUTER SCIENCE

Program7: Write a program to sort numbers in


ascending order.

#include<iostream.h>

void main( )
{
int i, j, a[100],n;

cout<<”Enter how many numbers”<<endl;


cin>>n;

cout<<”Enter numbers you want to sort”<<endl;


for(i=0; i<n; i++)
{ cin>>a[i]; }

cout<<”Numbers before sorting”<<endl;


for(i=0; i<n; i++)
{ cout<<a[i]; }

for(i=1; i<=n-1; i++)


{
for(j=0; j<n-i; j++)
{
if(a[j]>a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = a[j];
}
}
}

174 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

cout<<”Number after sorting”<<endl;


for(i=0; i<n; i++)
{ cout<<a[i]; }
}

VICKY CHAUHAN (MVC) 9920644662 175


COMPUTER SCIENCE

Program8: Write a power function that calculate


value of xp, function prototype should be double
power(double x, double y).

#include<iostream.h>
double power(double x, double y);

void main( )
{
double a, b, c;

cout<<”Enter base and power”<<endl;


cin>>a>>b;

c=power(a,b);
cout<<a<<”^”<<b<<”=”<<c;
}

double power(double x, double y)


{
double p=1;

for(i=1; i<=y; i++)


p = p * x;

return p;
}

176 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program9: Write a program to check if given


number is prime number

#include<iostream.h>

void main( )
{
int n, flag = 0, i;

cout<<”Enter any number”;


cin>>n;

for(i=2; i<n; i++)


{
if(n%i==0)
{
flag = 1;
break;
}
}

if(flag==0)
cout<<”Number is prime”;
else
cout<<”Number is not a prime”;

VICKY CHAUHAN (MVC) 9920644662 177


COMPUTER SCIENCE

Program10: Write a program to calculate volume


and surface area of sphere. The fuction prototype
is
void ComputeSphere(float &s, float &v, float r)

#include<iostream.h>
void ComputeSphere(float &s, float &v, float r);

void main( )
{
float s, v, r;

cout<<”Enter radius of shere”<<endl;


ComputeSphere(s, v, r);

cout<<”The area of sphere is”<<s;


cout<<”The volume of sphere is”<<v;
}

void ComputeSphere(float &s, float &v, float r)


{
float pi = 3.14;
s = 4.0 * pi * r * r;
v = s * r/3.0;
}

178 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program11: Implement class circle with a


function area to calculate area.

#include<iostream.h>

class circle
{
private:
float pi=3.14, a;

public:
float area(float r)
{
a = pi * r * r;
return a;
}
};

void main( )
{
float rad;
circle p;

cout<<”Enter radius of circle”<<endl;


cin>>rad;

cout<<”radius of circle is”<<p.area(rad);


}

VICKY CHAUHAN (MVC) 9920644662 179


COMPUTER SCIENCE

Program12: Write a program with function


computeTriangle() to calculate area and
perimeter of triangle given three sides.
void ComputeTriagle(float &a, float &p, float x, float y,
float z)

#include<iostream.h>
#include<math.h>
void ComputeTriagle(float &a, float &p, float x, float y,
float z);

void main( )
{
float a, p, x, y, z;

cout<<”Enter three sides of triangle”<<endl;


cin>>x>>y>>z;

ComputeTriangle(a, p, x, y, z);

cout<<”Area of triangle is”<<a;


cout<<”Perimeter of trangle is”<<p;
}

void ComputeTriagle(float &a, float &p, float x, float y,


float z)
{
p = x + y + z;
float s = p/2.0;
a = sqrt(s*(s-x)*(s-y)*(s-z));
}

180 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

program13: Write a program to replace space


with “–“.

#include<iostream.h>
#include<string.h>
#include<stdio.h>

void main( )
{
char a[100];
int l;

cout<<”Enter any text”<<endl;


gets(a);

l = strlen(a);
for(i=0; i<l; i++)
{
if(a[i]==” ”)
a[i] = - ;
}

cout<<”New text with hyphen”<<endl;


puts(a);
}

VICKY CHAUHAN (MVC) 9920644662 181


COMPUTER SCIENCE

Program14: Write a program to right


align(justify) lines of text.

#include<iostream.h>
#include<string.h>

void main( )
{
string line[100], s;
int n = 0, len, maxl = 0, i;

while(!cin.efo( ))
{
getline(cin,s);
len = s.length ( );
if(len > maxl)
maxl = len;
line[n++] = s;
}
--n;
for(i=0; i<n; i++)
{
s = line[i];
len = s.length( a)
cout<<string(maxl_len,’ ’)<<s<<endl;
}
}

182 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Select the correct alternative and rewrite the


following.

1. Float *ptr
In above declaration, data type of ptr is ____ and
type of variable pointed by ptr is ____.
a) float, float b) float, int c) int, float d) pointer,
float.
2. When a function is called by reference, it can work
an ____ variables in the calling program.
a) original b) virtual c) copies of d) none
3. *ptr ++ means____.
a) Increment the content of ptr by size of data
type to which ptr is pointer
b) Increment the content of ptr by one.
c) Increment the content of memory location
pointed by ptr by one.
d) None of these
4. Last character of a string is____.
a) O b) \O c) \n d) end
5. When we use string functions such as strlen( ) etc.
then it must include file____.
a) # include <string.h> b) # include <iostream.h>
c) # include <fstream.h> d) # include <iostring.h>
6. Objects are basic ____ in object oriented
programming.
a) run time entities b) compile time entities c) both
d) none
7. Object is variable, whose data type is ____.
a) integer b) class c) structure d) float
8. ____ is not visibility label.
a) public b) private c) separate d) protected

VICKY CHAUHAN (MVC) 9920644662 183


COMPUTER SCIENCE

9. The member declare under ____ visibility label are


hidden from external use.
a) public b) private c) both d) none
10. If all visibility labels are missing, then by default
members of class are ____.
a) public b) protected c) private d) any of these
11. When a member function is defined inside the class,
then it is treated as a ____ function.
a) inline b) outline c) external d) vitual
12. A class is defined as follows,
Class abc
{
private: int a;
public: friend void getdata(void)
};
the correct header for defining getdata() function
outside the class is____
a) friend void abc::getdata(void)
b) void abc::getdata(void)
c) friend void getdata(void)
d) void getdata(void)
13. A constructor can never return a value. Hence it has
____.
a) no return type. b) void return type
c) int return type d) any of these
14. A constructor is invoked implicitly by compiler upon
____ the program.
a) entry in b) exit from c) mid point of d) none of
these.
15. A special function, which is used to define as
additional task to an operator is called as ____.
a) operator overloading b) operator function
c) friend function d) constructor

184 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

16. Operator function as a member function will have only


one argument for ____ operators.
a) unary b) binary c) sizeof d) none of these
17. ____ is the operator which cannot be overloaded.
a) scope resolution b) binary c) unary d) none
18. The derivation of one class from another class is
called as ____.
a) multiple inheritance b) single inheritance
c) multilevel inheritance d) hybrid inheritance
19. When a class is made ____ the compiler takes
necessary care to see that only one copy of that class
is inherited in derived classes.
a) virtual base class b) base class
c) derived class d) single class
20. In early binding, the correct function to be invoked is
selected at ____.
a) runtime b) polymorphism time
c) compile time d) none of these
21. To achieve run-time polymorphism, C++ supports
mechanism of ____.
a) function overloading b) operator overloading
b) virtual function d) both a and b

22. ____ stream extracts data from the file


a) input b) output c) input/output d) none of these
23. The class ____ is not derived from stream base
class.
a) filebuf b) fstream c) ifstream d) ofstream
24. ios::in means ____.
a) open a file for writing
b) b) open a file for reading
c) open fails if file already exists
d) open a file in binary mode

VICKY CHAUHAN (MVC) 9920644662 185


COMPUTER SCIENCE

25. C++ was developed by Bjarne stroustrup at ____.


a) Xerox corporation b) AT & T Bell laboratories
c) Polo Alu Research center d) none of these
26. ____ is not a built-in data type.
a) void b) float c) char d) class
27. The do-while statement is ____.
a) entry control loop b) conditional statement
c) an exit control loop d) none of these
28. Function overloading is an example of ____.
a) inheritance b) Run-time polymorphism
c) compile-time polymorphism d) all of these.
29. The range of signed short is ____
a) -128 to 127 b) -32768 to 32767 c) 0 to 125
d) 0 to 65535
30. If the value of a = 4 and b = 7, then the value of p
after execution of the statement p = --b + a ++ is
____.
a) 10 b) 11 c) 9 d) 12
31. To read data from a file, the file should be open in
____ mode.
a) inpur b) output c) append d) none
32. The ability to take more than one form is called ____
in object-oriented programming.
a) inheritance b) encapsulation c) polymorphism d)
data abstraction.
33. Which of the following is not a feature of OOPs?
a) Follows bottom-up approach in program design.
b) Object may communicate with each other through
function.
c) Follows top-down approach in program design.
d) Program are divided into what are known as objects
34. Programming using C++ using class is called ____
programming.

186 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

a) procedural b) event driven c) object oriented d)


database
35. ____ is not a derived data type in C++
a) class b) array c) function d) pointer
36. ____ is not the feature of OOPs.
a) polymorphism b) inheritance c) data abstraction
d) top-down approach.
37. A derived class with several base classes is _____
inheritance.
a) single b) multiple c)multilevel d) hierarchical.
Answers:
1 d 20 c
2 a 21 c
3 c 22 a
4 b 23 a
5 a 24 b
6 a 25 b
7 b 26 d
8 c 27 c
9 b 28 c
10 c 29 b
11 a 30 a
12 d 31 a
13 a 32 c
14 b 33 c
15 b 34 c
16 b 35 a
17 a 36 d
18 c 37 b
19 a

VICKY CHAUHAN (MVC) 9920644662 187


COMPUTER SCIENCE

188 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

CHAPTER 4:

HTML

VICKY CHAUHAN (MVC) 9920644662 189


COMPUTER SCIENCE

MODULE 1:
INTRODUCTION
TO HTML

190 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

HTML
• HTML Stands for hyperText Mark-up Language, used to
create World Wide Web (WWW) document.
• Hypertext is ordinary text with extra features such as
formatting, images, multimedia and links to other
documents.
• Mark-up is the process of taking ordinary text and
adding extra symbols. Each of the symbols used for mark-
up in HTML is command that tells the browser how to
display the text.
• Mark-up languages are special type of computer language.
They are concerned with only parts of documents
according to their functions.
• They indicate which part of document is title, which is
subheading, which is author’s name and so on.
• HTML is essentially a set of instructions to web browser
for formatting and layout of web pages.

FEATURES OF HTML
• HTML is a set of tags that is used to create document
and then it can be published on the World Wide Web.
• HTML lets user jump from topic rather than finding and
reading information linearly.
• Documents prepared in HTML includes reference graphics
and formatting tags.
• HTML Supports to frames including target window and
borderless frame.
• It contains powerful formatting facilities for text, pages,
images etc.

VICKY CHAUHAN (MVC) 9920644662 191


COMPUTER SCIENCE

• It defines the syntax and placement of special embedded


directions, which are not displayed by the browser, but it
tells the browser how to display the content of the
document.
• It supports .BMP and .GIF images.
• HTML supports forms, which make it possible to create
documents that collect and process uses input.
• It tells how to make a document interactive through
special hypertext links.

ADVANTAGES OF HTML
• For creating a HTML document, only text editor is
needed. No special software is needed.
• HTML document can be created on any hardware platform
using any text editor.
• HTML is easy to learn and implement.
• Contain powerful formatting facilities.
• Any HTML document can be updated easily, without
changing whole document.
• If something is not working, then finding error is easy in
HTML.
• HTML will not cost anything for its use. There are no
expensive licenses to buy or no updates to purchase.

192 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

DISADVANTAGES OF HTML
• HTML is not a programming language in true sense.
• Any simple calculation cannot be done in HTML.
• It cannot be used to display even date.
• The interactive web pages cannot be built by HTML.
• The web pages developed in HTML cannot behave like an
application.
• The web pages developed in HTML do not have their own
interface.
• Hyperlink is providing in HTML. But for that we need a
trip to server at each step.

Software required for writing


HTML codes
• Notepad in Windows.
• Simple text in Macintosh.
• Pico in Unix.

QUESTIONS FORM MODULE 1:


5. What is HTML?
6. Explain features of HTML.
7. What are advantages of HTML?
8. What are disadvantages of HTML?
9. Name any two software that are used for writing HTML.
10. What are basic and essential tags of HTML code?

VICKY CHAUHAN (MVC) 9920644662 193


COMPUTER SCIENCE

MODULE 2:
TAGS IN HTML

194 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

TAGS IN HTML
HTML tags are used to mark-up HTML elements
HTML tags are surrounded by the two characters < and >
The surrounding characters are called angle brackets
HTML tags normally come in pairs like <b> and </b>
The first tag in a pair is the start tag, the second tag is
the end tag The text between the start and end tags is
the element content
HTML tags are not case sensitive, <b> means the same as
<B>

ESSENTIAL TAGS IN HTML:


<html> </html>: The <html> tag is in fact the only tag you
need to create the simplest webpage. The <html> tag tells
the browser that this is an HTML document, so the
browser understands how to show the page. The first line
in each file will be <html> and the last line in each file will
be </html>.

<head> </head>: The "head" of an HTML document


contains information which is not displayed on the screen
when viewed in a browser, but is nevertheless important in
making the document more readable. You need both the
opening <head> and closing </head> tag.

<title> </title>: An example of a tag that would appear


in the head of an HTML document is the <title> </title> tag.
Any text within this tag is not seen directly in the browser
window, but is displayed in the title bar of the browser.

VICKY CHAUHAN (MVC) 9920644662 195


COMPUTER SCIENCE

<body> </body>: The "body" contains the part of the


document that will be viewed in the webpage. You need
both the opening <body> and closing </body> tag. You can
set options for the <body> tag that will be applied to the
entire web page. Some of these options are:
background="url" - Sets the background image to the
image found at URL. The image should be in .gif, .jpg, or
.jpeg format
• BGCOLOR = "hexvalue" or BGCOLOR = "color_name"
Sets the background color.
• LINK = "hexvalue" or LINK = "color_name"
Sets the colour for unvisited links
• VLINK = "hexvalue" or VLINK = "color_name"
Sets the colour for visited links
• TEXT = "hexvalue"
Sets the colour for text in the body of the document

<P> tag (Paragraph tag): Paragraphs are defined with the


<p> tag. Think of a paragraph as a block of text. You can
use the align attribute with a paragraph tag as well. You
must indicate paragraphs with <p> elements. A browser
ignores any indentations or blank lines in the source text.
Without <p> elements, the document becomes one large
paragraph. HTML automatically adds an extra blank line
before and after a paragraph.
The <p> tags have one optional attribute called align. This
is used to specify where the text appears on screen.

Example:
<p> your text </p>
<p align="left"> your text </p>
<p align="right"> your text </p>
<p align="center"> your text </p>

196 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Heading tags:
[<h1> </h1>, <h2> </h2>, <h3> </h3>, <h4> </h4>, <h5> </h5>,
<h6> </h6>]
Headings are useful when you want to organize text into
named sections. In all there are six headings of form <hn>,
where n is any number between 1 and 6; and closing tags
are of the form </hn> are needed to close the six
different heading tags. Applying heading tags to text
causes that text to have a predetermined size and format.
H1 is the largest, and H6 is the smallest.

Example:
This code Would display
<h1>This
<h2>This
is
is
heading</h1>
heading</h2>
This is a heading
<h3>This is heading</h3>
<h4>This is heading</h4> This is a heading
<h5>This is heading</h5>
<h6>This is heading</h6> This is a heading
This is a heading
This is a heading

This is a heading

<BR> tag (break tag): The <br> tag is used when you want
to start a new line, but don't want to start a new
paragraph. The <br> tag forces a line break wherever you
place it. It is similar to single spacing in a document. The
<br> tag has no closing tag.

Example:
This code Would display
<p> This <br> is a para <br> This
graph with line breaks </p> is a para
graph with line breaks

VICKY CHAUHAN (MVC) 9920644662 197


COMPUTER SCIENCE

<HR> tag (horizontal rulers): The <hr> tag stands for


horizontal rule. This tag will cause a horizontal line to be
drawn on the screen. Following are some attributes
associated with this tag:
• ALIGN - aligns the line horizontally, "left", "right", or
"center".
• SIZE - sets the thickness of the line to the number
of pixels.
• WIDTH - sets the width of the line to be number of
pixels or to take up the percentage of the screen's
width. (For example, if you wish to create a line that
takes up the whole width of the screen, use <hr width
="100%"> ).
• COLOR NAME - sets the colour of the line. You can
use the color name or the hex code for the color.

Example:
This code Would display
<hr width=“50%” size=“6”>

<PRE> tag: This tag is used to preformat the text. The


text appearing between start tag <PRE> and end tag </PRE>
is displayed in mono space form. This tag displays the text
in exactly same format as the character and line spacing
format define in source HTML document.

Example:
This code Would display
<PRE>
1 1
1 1 1 1
1 2 1 1 2 1
1 3 3 1 1 3 3 1
</PRE>

198 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

<B> tag: Bold tag: The text appearing between start tag
<B> and end tag </B> will be display in bold letters.

Example
This code Would display
<P> This is normal </P><BR> This is normal
<B> This is big </B>
This is big

<I> tag: Italic tag: The text appearing between start


tag <I> and end tag </I> will be display in italic letters.

Example:
This code Would display
<P> This is normal </P><BR> This is normal
<I> This is italic </I>
This is italic

<U> tag: underline tag: The text appearing between


start tag <U> and end tag </U> will be underlined. Generally
browser indicates hyperlinks in wed pages by underlining
them. So it is generally avoided.

Example:
This code Would display
<P> This is normal </P><BR> This is normal
<U> This is underlined </U>
This is underlined

<marquee> tag: It is used for scrolling the text and images


on screen from right to left. The text writing between
start tag <marquee> and end tag </marquee> will scroll on
VICKY CHAUHAN (MVC) 9920644662 199
COMPUTER SCIENCE

screen, in horizontal line. Following are some attributes


associated with this tag:
• BGCOLOR - Sets the background color.
• HEIGHT – Sets the height of image.
• WIDTH – Sets the width of image.
Example:
This code Would display
<marquee> computer </marquee> Here, the word computer
would appear scrolling on
the screen.

<SUP> tag: superscript tag: The text appearing within


start tag <SUP> and end tag </SUP> is displayed in super
script form.

Example:
This code Would display
E = MC<SUP>2</SUP> E = MC2

<SUB> tag: subscript tag: The text appearing within


start tag <SUB> and end tag </SUP> is displayed in
subscript form.

Example:
This code Would display
H <SUB> 2 </SUB> O H2O

<BIG> tag: The text appearing within start tag <BIG> and
end tag </BIG> is displayed in larger font. If size is
already larger, then tag is ignored.
<BIG> Tag has the same effect as <FONT SIZE = “+1”>

200 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Example:
This code Would display
<p>This text is normal.</p> This text is normal.
<p><big>This text is
bigger.</big></p>
This text is bigger.

<SMALL> tag: The text appearing within start tag


<SMALL> and end tag </SMALL> is displayed in smaller
font. If size is already smaller, then tag is ignored.
<SMALL> Tag has the same effect as <FONT SIZE = “-1”>

Example:
This code Would display
<p>This is normal</p><BR> This is normal
<small>This is smaller</small>
This is smaller

<EM> tag: Emphasis tag: The text appearing within start


tag <EM> and end tag </EM> is displayed in italic font.

Example:
This code Would display
<P>This is normal</P><BR> This is normal
<EM>This is emphasis </EM>
This is emphasis

<STRONG> Tag: The text appearing within start tag


<STRONG> and end tag </STRONG> is displayed in bold
font.

Example:
This code Would display
<P> This is normal </P><BR> This is normal
<STRONG> This is strong
</STRONG>
This is strong

VICKY CHAUHAN (MVC) 9920644662 201


COMPUTER SCIENCE

<FONT> Tag: This tag is used to format the size, type


face and color of enclosed text. Following are the
attributes associated with this tag.

• FACE = “any font face” - Use these tags for


specifying the font face of your page. Text that
appears between these tags will be displayed in the
font face and style identified by the attributes.
Unfortunately the font face you use will only be
displayed if the actual font is installed in the visitor’s
machine. If the font is not installed, the visitor’s
browser will replace it with one that is similar in size
and style.
• SIZE = “number(1-7)” - The size tag allows you to set
the size of the font, The size attribute can be
assigned a value between "1" being the smallest and
"7" being the largest. By putting “+” or “-” sign before
the number will change font relative to default size.
• COLOR = “hexnumber” or COLOUR = “color_name” -
The color tag lets you change the color of the text.

Example:
This code
<P> This is normal </P><BR>
<FONT FACE="Arial" SIZE="3"> This is Arial </FONT><BR>
<FONT FACE="TimesNewRoman" SIZE="6"> This is TimesNewRoman
</FONT>
Would display
This is normal

This is Arial

This is TimesNewRoman

202 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

UNORDERED LIST
In an unordered list bullets are placed before each list
item. The basic form for an unordered list uses he <UL>
tag, a collection of <LI> </LI> tags for each of the list
items, and finally a </UL> to tell the browser that the list
is complete.

Example:
This code Would display
<UL> • Coffee
<LI>Coffee</LI>
<LI>Milk</LI> • Milk
<LI>Curd</LI> • Curd
</UL>

Unordered list is associated with “TYPE” attribute.


TYPE = “CIRCLE” - Sets hollow circle bullet.
TYPE = “DISC” – Sets solid circle bullet.
TYPE = “SQUARE” - Sets hollow square bullet.
By default Disc is used.

Example:
This code Would display
<UL TYPE = “CIRCLE”> o Coffee
<LI>Coffee</LI>
<LI>Milk</LI>
o Milk
<LI>Curd</LI> o Curd
</UL>

This code Would display


<UL TYPE = “SQUARE”> § Coffee
<LI>Coffee</LI>
<LI>Milk</LI>
§ Milk
<LI>Curd</LI> § Curd
</UL>

VICKY CHAUHAN (MVC) 9920644662 203


COMPUTER SCIENCE

ORDERED LIST
The ordered list numbers each item consecutively. The
basic form for an ordered list is the <ol> tag, (which stands
for ordered list), a collection of list items identified by <li>
</li> tags, and then the </ol> tag.

Example:
This code Would display
<OL> • Coffee
<LI>Coffee</LI>
<LI>Milk</LI> • Milk
<LI>Curd</LI> • Curd
</OL>

Ordered list is associated with “TYPE” attribute.


TYPE = “1” - Sets Arabic number.
TYPE = “a” – Sets lowercase alphanumeric.
TYPE = “A” - Sets uppercase alphanumeric.
TYPE = “i” – sets lowercase Roman number.
TYPE = “I” – sets uppercase Roman number.
By default Arabic number is used.

Example:
This code Would display
<OL TYPE = “a”> a. Coffee
<LI>Coffee</LI>
<LI>Milk</LI>
b. Milk
<LI>Curd</LI> c. Curd
</OL>

This code Would display


<OL TYPE = “A”> A. Coffee
<LI>Coffee</LI>
<LI>Milk</LI>
B. Milk
<LI>Curd</LI> C. Curd
</OL>

204 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

This code Would display


<OL TYPE = “i”> i Coffee
<LI>Coffee</LI>
<LI>Milk</LI>
ii Milk
<LI>Curd</LI> iii Curd
</OL>

This code Would display


<OL TYPE = “I”> I. Coffee
<LI>Coffee</LI>
<LI>Milk</LI>
II. Milk
<LI>Curd</LI> III. Curd
</OL>

<IMG> tag: Image tag: The <img> tag, where IMG stands
for image has no </img> counterpart, but does have several
useful attributes. The SRC attribute is the only necessary
option for the <img> tag, since the browser must know
where it can find the image file. The SRC option can be set
to equal a valid filename, if the image file is located in the
same directory as the source document of an image file.
Following are the attributes used along with <IMG> tag
SRC="FILENAME" - Specifies the SOURCE of the image;
if the image file is in the same directory as the source
document, all that is needed is the filename itself. Note:
Don't link to another page for an image - copy the image to
your filespace and link to it from there (with permission of
course!)
• HEIGHT = "NUMBER" - Specifies that the height of
the image should be NUMBER pixels.
• WIDTH = "NUMBER" - Specifies that the width of
the image should be NUMBER pixels.
• ALT = "DESCRIPTION" - Specifies a description of
the image. The ALT option for the IMG tag is useful
for those whose browsers cannot support in-line
images, or have their images turned off in their
VICKY CHAUHAN (MVC) 9920644662 205
COMPUTER SCIENCE

browsers; instead of seeing the image, they'll see the


description of the image that you gave them in the
ALT tag.
• BORDER = "NUMBER" - Specifies the width of the
image's border, in pixels

Example:
This code Would display
<IMG SRC ="graphics/chef.gif"
BORDER = “2” >

<A> tag: Anchor Tag: This tag is used to create links or


hyperlinks. The text or file enclosed between starting tag
<A> and ending tag </A> is a link. This link is clickable in
graphical browser. With most browser, the text within
these tags is displayed in different color and underline.
HREF is attribute associated with this tag.

• HREF – HREF means hyperlink reference the object


to which the link has to be made is defined by HREF
attribute.
General format is:
<A HREF = “URL”> name or image which can be treated as
link </A>

TYPES OF HYPERLINK:
a. Link to page on the World Wide Web:
Example:
<A HREF = “http://www.google.com”> search </A>
The string “search” is a hyperlink to the website
www.google.com.
206 VICKY CHAUHAN (MVC) 9920644662
COMPUTER SCIENCE

b. Link to a image by imiage as a link:


Example:
<A HREF=“img.jpg”> <IMG SRC=”img2.jpg”> </A>
here image img.jpg is a hyperlink to the image file
img2.jpg
c. Link to document located in different:
Example:
<A HREF = “d:\power\ab.html”> click here </A>
here by clicking on “click here” link, destination page
i.e. ab.html will be displayed which is specified in the
path given

RGB codes:
R: RED
G: GREEN
B: BLUE

• RGB codes are always 6 numbers: first two numbers


specify amount of red, next two number specify amount
of green and last two numbers specify amount of blue.
• By mixing these three primary colors in different
amount, it is possible to derive any color.
• RGB code use hexadecimal numbering system.
• For red color, RGB code is #FF0000, for blue color RGB
code is #0000FF and for green color RGB code is
#00FF00.
• Yellow is combination of maximum red and maximum
green. Hence RGB code is #FFFF00.
• RGB code for black is #000000 and RGB code for white
is #FFFFFF.

VICKY CHAUHAN (MVC) 9920644662 207


COMPUTER SCIENCE

TABLE:
Tables are defined with the <table> tag. A table is divided
into rows (with the <TR> tag), and each row is divided into
data cells (with the <TD> tag or <TH> tag). The letters TD
stands for table data, which is the content of a data cell.
The letter TH stands for table heading. A data cell can
contain text, images, lists, paragraphs, forms, horizontal
rules, tables, etc.

Followings are the attribute associated with table tag:


• BORDER = “number” – draw an outline around table row
and cell. By default table has no border
• WIDTH = “number” – define how wide your table will
appear across the width of the screen.
• CELLPADDING = “number” - decide the amount of
spacing between each cell border and the actual
content of cell.
• CELLSPACING = “number” – create space between the
cells.
• BGCOLOR = “color name” – give the background color to
the table.
• BORDERCOLOR = “color name” – give the color to the
border.
• ALIGN = “position” – decides the alignment of the table.
By default it is left.

Following are the attributes associated with <TR>, <TD>,


<TH> tags:
• ALIGN = “position” – specify horizontal alignment of
row or column.

208 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

• VALIGN = “position” – specify vertical alignment of row


of column. Default alignment is left.
• BGCOLOR = “color name” – give the background color of
specific row or column.

Following are the attributes of table cell:


• COLSPAN = “number” – Number of columns that a cell
spans.
• ROWSPAN = “number” – Number of rows that a cell
spans.

Example:
This code Would display
<table>
<tr>
<td>Ram</td>
Ram Patel 50
<td>Patel</td> John Demelo 94
<td>50</td> Ali Khan 80
</tr>
<tr>
<td>John</td>
<td>Demelo</td>
<td>94</td>
</tr>
<tr>
<td>Ali</td>
<td>Khan</td>
<td>80</td>
</tr>
</table>

VICKY CHAUHAN (MVC) 9920644662 209


COMPUTER SCIENCE

Example: with border attribute:


This code Would display
<table border = “1”>
<tr>
<td>Ram</td> Ram Patel 50
<td>Patel</td>
<td>50</td> John Demelo 94
</tr>
<tr>
Ali Khan 80
<td>John</td>
<td>Demelo</td>
<td>94</td>
</tr>
<tr>
<td>Ali</td>
<td>Khan</td>
<td>80</td>
</tr>
</table>

Example: with cellpadding:


This code Would display
<table border=“1”
cellpdding=“20”>
<tr> Ram Patel 50
<td>Ram</td>
<td>Patel</td> John Demelo 94
<td>50</td>
</tr>
Ali Khan 80
<tr>
<td>John</td>
<td>Demelo</td>
<td>94</td>
</tr>
<tr>
<td>Ali</td>
<td>Khan</td>
<td>80</td>
</tr>
</table>

210 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Example: with border attribute:


This code Would display
<table border = “1”
cellspacing= “15”>
<tr>
<td>Ram</td>
<td>Patel</td>
<td>50</td>
</tr>
<tr>
<td>John</td>
<td>Demelo</td>
<td>94</td>
</tr>
<tr>
<td>Ali</td>
<td>Khan</td>
<td>80</td>
</tr>
</table>

QUESTIONS FORM MODULE 2:


1. Explain following tags in HTML:
a. <p> tags b. <BR> tag c. <HR> tag
2. How text is formatted by using <B>, <I> and <U> tags?
3. Explain following tags in HTML:
a. <marquee> tags b. <SUP> tag c. <SUB> tag
4. How can be unordered list be created?
5. Explain the use of <OL>tag with example.
6. What is <IMG> tag? What are the attributes that can be
used with <IMG> tag?
7. List any three types of hyperlinks with suitable example.

VICKY CHAUHAN (MVC) 9920644662 211


COMPUTER SCIENCE

MODULE 3:
IMPORTANT
PROGRAM

212 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program1: Write HTML code for the following:

CRICKET ANALYSIS
COUNTRY PLAYED WON LOSE
INDIA 30 23 07
AUS 24 19 05
PAK 18 02 16
ZIM 10 07 03
<HTML>
<BODY>
<CAPTION ALIGN = "TOP"> CRICKET ANALYSIS </CAPTION>
<TABLE BORDER="3">
<TR>
<TH>COUNTRY</TH>
<TH>PLAYED</TH>
<TH>WON</TH>
<TH>LOSE</TH>
</TR>
<TR>
<TD>INDIA</TD>
<TD>30</TD>
<TD>23</TD>
<TD>07</TD>
</TR>
<TR>
<TD>AUS</TD>
<TD>24</TD>
<TD>19</TD>
<TD>05</TD>
</TR>
<TR>
<TD>PAK</TD>
<TD>18</TD>
<TD>02</TD>
<TD>16</TD>
</TR>
<TR>
<TD>ZIM</TD>
<TD>10</TD>
<TD>07</TD>
<TD>03</TD>
</TR>
</TABLE>
</BODY>
</HTML>
VICKY CHAUHAN (MVC) 9920644662 213
COMPUTER SCIENCE

Program2: Write HTML code for the following:

Yeshwant College Nanded


Course Capicity
B.Sc(Comp) 80
B.Sc(C.A) 80
M.Sc(Comp) 30
M.C.M 40
<HTML>
<BODY>
<TABLE BORDER="3">
<TR>
<TH COLSPAN="2">Yeshwant College Nanded</TH>
</TR>
<TR>
<TH>Course</TH>
<TH>Capicity</TH>
</TR>
<TR>
<TD>B.Sc(Comp)</TD>
<TD>80</TD>
</TR>
<TR>
<TD>B.Sc(C.A)</TD>
<TD>80</TD>
</TR>
<TR>
<TD>M.Sc(Comp)</TD>
<TD>30</TD>
</TR>
<TR>
<TD>M.C.M</TD>
<TD>40</TD>
</TR>
</TABLE>
</BODY>
</HTML>

214 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program3: Write HTML code for the following:

Students Marks Obtained Total


Sr.No.
Name. Test 1 Test 2 Test 3
1 Maheshwari 150 150 150 650
2 Akanksha 129 130 131 390
3 Asma 125 115 120 360
<HTML>
<BODY>
<TABLE BORDER="3">
<TR>
<TH ROWSPAN="2">Sr.No.</TH>
<TH ROWSPAN="2">Students <BR> Name.</TH>
<TH COLSPAN="3">Marks Obtained </TH>
<TH ROWSPAN="2">Total </TH>
</TR>
<TR>
<TD>Test 1</TD>
<TD>Test 2</TD>
<TD>Test 3</TD>
</TR>
<TR>
<TD>1</TD>
<TD>Maheshwari</TD>
<TD>150</TD>
<TD>150</TD>
<TD>150</TD>
<TD>650</TD>
</TR>
<TR>
<TD>2</TD>
<TD>Akanksha</TD>
<TD>129</TD>
<TD>130</TD>
<TD>131</TD>
<TD>390</TD>
</TR>
<TR>
<TD>3</TD>
<TD>Asma</TD>
<TD>125</TD>
<TD>115</TD>
<TD>120</TD>
<TD>360</TD>
</TR>

VICKY CHAUHAN (MVC) 9920644662 215


COMPUTER SCIENCE

</TABLE>
</BODY>
</HTML>

Program4: Write HTML code for the following:

YEAR
1998 1999 2000
Units 500 400 1000
Sales
Income 1000 800 2000
<HTML>
<BODY>
<TABLE BORDER="3" CELLSPACING="15">
<TR ALIGN="CENTER">
<TD ROWSPAN="2" COLSPAN="2"></TD>
<TD COLSPAN="3">YEAR</TD>
</TR>
<TR ALIGN="CENTER">
<TD>1998</TD>
<TD>1999</TD>
<TD>2000</TD>
</TR>
<TR ALIGN="CENTER">
<TD ROWSPAN="2">Sales</TD>
<TD>Units</TD>
<TD>500</TD>
<TD>400</TD>
<TD>1000</TD>
</TR>
<TR ALIGN="CENTER">
<TD>Income</TD>
<TD>1000</TD>
<TD>800</TD>
<TD>2000</TD>
</TR>
</TABLE>
</BODY>
</HTML>

216 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program5: Write the HTML code for the following:

SCIENCE
F.Y.B.Sc S.Y.B.Sc T.Y.B.Sc
300 100 25
ARTS
F.Y.B.A S.Y.B.A T.Y.B.A
200 150 40
COMMERCE
F.Y.Bcom. S.Y.Bcom. T.Y.Bcom.
300 70 50

<HTML>
<BODY>
<TABLE BORDER="1" CELLPADDING = 20 CELLSPACING = 10 >
<TR>
<TH COLSPAN = 3 ALIGN = center > SCIENCE </TH>
</TR>

<TR>
<TH> F.Y. B.Sc. </TH>
<TH> S.Y. B.Sc. </TH>
<TH> T.Y. B.Sc. </TH>
</TR>

<TR>
<TD ALIGN = center > 300 </TD>
<TD ALIGN = center > 100 </TD>
<TD ALIGN = center > 25 </TD>
</TR>

<TR>
<TH COLSPAN = 3 ALIGN = center > ARTS </TH>
</TR>

<TR>
<TH> F.Y. B.Sc. </TH>
<TH> S.Y. B.Sc. </TH>
<TH> T.Y. B.Sc. </TH>
</TR>

VICKY CHAUHAN (MVC) 9920644662 217


COMPUTER SCIENCE

<TR>
<TD ALIGN = center > 200 </TD>
<TD ALIGN = center > 150 </TD>
<TD ALIGN = center > 40 </TD>
</TR>

<TR>
<TH COLSPAN = 3 ALIGN = center > COMMERCE </TH>
</TR>

<TR>
<TH> F.Y. B.Sc. </TH>
<TH> S.Y. B.Sc. </TH>
<TH> T.Y. B.Sc. </TH>
</TR>

<TR>
<TD ALIGN = center > 300 </TD>
<TD ALIGN = center > 70 </TD>
<TD ALIGN = center > 50 </TD>
</TR>

</TABLE>
</BODY>
</HTML>

218 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program6: Write HTML code for the following:

HSC Boards Exams

1 Paper I
Computer Science 2 Paper II
• 200 Marks

<HTML>
<BODY>
<TABLE BORDER= 5 WIDTH = 50% >

<TR>
<TD WIDTH = 100% COLSPAN = 2 >
<H1 ALIGN = center> HSC Boards Exams </H1>
</TD>
</TR>

<TR>
<TD WIDTH = 50% ROWSPAN = 3 >
<P ALIGN = center><B> computer science </B>
</TD>

<TR>
<TD WIDTH = 50% ALIGN = center>
<OL>
<LI> paper I </LI>
<LI> paper II </LI>
</OL>
</TD>
</TR>

<TR>
<TD WIDTH = 50% ALIGN = center>
<UL>
<LI> <P ALIGN = center> 200 Marks </LI>
</UL>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>

VICKY CHAUHAN (MVC) 9920644662 219


COMPUTER SCIENCE

Program7: Write the HTML code for the following:

COMPUTER PAPER-I PAPER-II TOTAL


SCIENCE 100 100 200

<HTML>
<BODY>
<TABLE BORDER= ”2” CELLSPACING = “15” >

<TR>
<TD ROWSPAN = 2 ALIGN = center > COMPUTER SCIENCE </TD>
<TD ALIGN = center > PAPER-I </TD>
<TD ALIGN = center > PAPER-II</TD>
<TD ALIGN = center > TOTAL </TD>
</TR>

<TR>
<TD ALIGN = center > 100 </TD>
<TD ALIGN = center > 100 </TD>
<TD ALIGN = center > 200 </TD>
</TR>

</TABLE>
</BODY>
</HTML>

220 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program8: Write HTML code for the following:

Government of Maharashtra (TEXT SIZE IN H2)

Education
PWD ADMIN

For details
Feel free to approach us

PWD is a link available where clicking on PWD a webpage


file “Mahapwd.html” should be invoked. On clicking ADMIN
a webpage file “admin.html” should be invoked. On clicking
for details the user can write e-mail to mail-address
“free_free@hscboard.com”. On clicking feel free to
approach us, user can invoked to website
“www.maharashtra.gov.in”

<HTML>
<BODY>
<H2> Government of Maharashtra </H2>

<TABLE BORDER = 1 CELLSPACING = 10 >


<TR>
<TH COLSPAN = 2 ALIGN = center > Education </TH>
</TR>
<TR>
<TD ALIGN = center > <A HREF = “Mahapwd.html”> PWD </A></TD>
<TD ALIGN = center > <A HREF = “admin.html”> ADMIN </A></TD>
</TR>
</TABLE>

<P> <A HREF = “free_free@hscboard.com”> for details </A> </P>


<P> <A HREF = “www.maharashtra.gov.in”> feel free to approach us </A> </P>
</BODY>
</HTML>

VICKY CHAUHAN (MVC) 9920644662 221


COMPUTER SCIENCE

Program9: Write an exact output of the following


HTML code:
<HTML>
<HEAD>
<TITLE> </TITLE>
</HEAD>

<BODY>
<TABLE BORDER= 2 WIDTH = 50%>

<TR>
<TD WIDTH = 100% COLSPAN = 2 >
<H1 ALIGN = “center”> HSC Board Exams </H1>
</TD>
</TR>

<TR>
<TD WIDTH = 50% ALIGN = center> <U> Paper I </U> </TD>
<TD WIDTH = 50% ALIGN = center> <U> Paper II </U> </TD>
</TR>

<TR>
<TD WIDTH = 50% > <P ALIGN = center ><I> 50 Marks </I > </TD>
<TD WIDTH = 50% > <P ALIGN = center ><I> 50 Marks </I > </TD>
</TR>

</TABLE>
</BODY>
</HTML>

OUTPUT:

HSC Board Exams


Paper I Paper II
50 Marks 50 Marks

222 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program10: Write the exact output of the following


HTML code with font specifications in brackets:

<html>
<title> Introduction </title>
<body>
<h1> <b> COMPUTER SCIENCE <b> </h1>
<hr>
<u> SCHAUM'S OUTLINE SERIES </u>
<hr>
<h5>SEYMOUR LIPSCHUTZ </h5>
</body>
</html>

OUTPUT:

COMPUTER SCIENCE (text size h1 in bold, default


Font is used)

SCHAUM'S OUTLINE SERIES (text size is default, regular,


Default font is used)

SEYMOUR LIPSCHUTZ (text size is h5 Regular,


Default font is used)

VICKY CHAUHAN (MVC) 9920644662 223


COMPUTER SCIENCE

Program11: Write an exact output of the following


HTML code with font specification in brackets:
<html>
<body>
<h1> <b> LIST OF BOOKS <b> </h1>
<ul type = “circle”>
<li> How to solve it by computer
<li> HTML in easy steps
<li> C++ Programming
</ul>
<ol type = “A”>
<li> Microprocessor Programming
<li> Networking Essentials
<li> Microcontroller
</ol>
</body>
</html>

OUTPUT:

LIST OF BOOKS
(Text size h1 in bold, default Font is used)
o How to solve it by computer (Text size is default,
o HTML in easy steps Regular font is used)
o C++ Programming

A. Microprocessor Programming (Text size is default,


B. Networking Essentials Regular font is used)
C. Microcontroller

224 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Program12: Write an exact output of the following


HTML code with font specification in brackets:

<html>
<body>
<h1> <center> HSC SYLLABUS </center> </h1>
<h3> PAPER I </h3>
To know more about
<p> Just click here
<address>
<b> Data structure </b>
<b> GUI </b>
<b> HTML </b>
<b> C++ </b>
<b> VB </b>
</address>
<body>
</h

OUTPUT:

HSC SYLLABUS
(Text size h1, regular font)
PAPER I (Text size h3, regular font)
To know more about (Text size regular)
Just click here
Data structure (Text size regular, bold font)
GUI
HTML
C++
VB

VICKY CHAUHAN (MVC) 9920644662 225


COMPUTER SCIENCE

Program13: Write an exact output of the following


HTML code:

<html>
<body>
<h1> <b> Languages </h1>
<ol>
<li> English </li>
<li> Second language </li>
</ol>
<ul>
<li> Marathi </li>
<ul>
<li> Hindi </li>
<ul>
<li> French </li>
</ul>
<li> Sanskrit </li>
</ul>
</body>
</html>

OUTPUT:

Languages
1 English
2 Second language
• Marathi
o Hindi
§ French
o Sanskrit

226 VICKY CHAUHAN (MVC) 9920644662


COMPUTER SCIENCE

Select the correct alternative and rewrite the


following.

1. ____ tag is used for superscript in HTML.


a)<SUPER> b) <SUP> c) <UP> d)<SUPERSCRIPT>
2. HTML stands for ____.
a) hypertext markup language
b) high text manipulation language
c) hyper text manipulation language
d) none
3. To display definition lists on your web page ___ tag is
used.
a) <DLIST> b) <OL> c) <LI> d) <DL>
4. Long forth of HREF is ____.
a) horizontal reference b) hypertext reference
c) hyperlink reference d) hypermedia reference
5. RGB code for black is ____.
a) FF0000 b) FFFFFF c) 00000F d) 000000
6. Which of the following color is not allowed to used in
HTML____.
a) OLIVE b) PURPLE c) ORANGE d) FUCHSIA
7. ____ tag is used to put a line break in HTML code.
a) <HR> b) <BR> c) <P> d) <TT>
8. To place the image into HTML file ____ attribute is
used in IMG tag.
a) URL b) ALT c) SRC d) HREF
9. VB script can be executed in ____ wed browser.
a) Netscape Navigator b) Internet Explorer
c) Both d) none of these
10. The long form of SGML is ____
a) Standard Global Machine Language
b) Special Global Markup Language
c) Symbolic Generalized Machine Language

VICKY CHAUHAN (MVC) 9920644662 227


COMPUTER SCIENCE

d) Standard Generalized Markup Language

11. ____ is the name of the wed browser


a) Embedded system b) Netscape Navigator
c) Oracle d) C++
12. ____ tag is used for scroll the text.
a) <STRIKE> b)<MARQUEE> c)<HR> d) none of
these

1 b 7 b
2 c 8 c
3 d 9 c
4 b 10 d
5 d 11 b
6 c 12 b

228 VICKY CHAUHAN (MVC) 9920644662

You might also like

pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy