0% found this document useful (0 votes)
33 views290 pages

Structures & Pointers-1

Uploaded by

gojosmijith
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)
33 views290 pages

Structures & Pointers-1

Uploaded by

gojosmijith
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/ 290

Chapter 1

STRUCTURES
& POINTERS
Part 1
Contents
Structures
Variable declaration and memory allocation
Variable initialisation
Accessing elements of structure
Nested structure
Array Vs Structure
Structures
Structures
Structure is a user-defined data type of C++ to represent a collection
of logically related data items, which may be of different types, under a
common name. Arrays allow to define type of variables that can hold
several data items of the same kind. Similarly structure is another user
defined data type available in C++ that allows to combine data items of
different kinds.

Structure is a user defined data type -

It is a collection of heterogeneous data items


It can be defined using the key word struct -

-
Defining a Structure
To define a structure, you must use the struct statement. The struct
statement defines a new data type, with more than one member. The
format of the struct statement is as follows −

struct structure tag


{
data_type variable;
data_type variable;
-
-

data_type variable;
- -

……………………………..
-
-

……………………………..
data_type variable;
-
-

} [one or more structure variables];


-
Eg:-
Struct student
{
-

int adm_no;
char name[20];
-
-

char group[20];
- -

float fee;
-

};
-
-
Struct date
{
int dd;
int mm;
int yy;
};
Struct date
{
int day;
char month[10];
int year;
};
Variable declaration and memory allocation
Structure variable can be declared by the syntax

Struct structure-name structure-variable;


or
- - -

struct structure_tag var1, var2, ..., varN;


or
-
-
-

structure_tag var1, var2, ..., varN; -


- -

-
(in
Student >;
Struct
Eg:
--

E Struct student s;
-
-
int admno Student s;
, -

float fee;
admng
.
(in >
-

int mark
y CInDS . admno

3; cinS .
fee
CkDS Mosk
Student S
;
.

-
-
date dob, today; struct date dob, today;
OR
strdate adm_date, join_date;
Memory allocation
of structure variable
A c++ compiler allocate separate memory location for each and every
structure members.
int -
3
struct student

S
{ Chri =
12
-
Int roll_no;
&

-
-

Char name[20];
-
-

fFloat mark;
-
-
=
-

I float =
Ya
}; L
- -
-

20
Total 28 bytes
Roll_no 4 byte t
Name 20*1=20 byte
Mark 4 byte &
= 28 bat
=
day month[10] year

4 Bytes 10 Bytes 4 Bytes


Variable initialisation

structure_tag variable={value1, value2,..., valueN};

Eg:

student s={3452, "Vaishakh", "Science", 270.00};


adm_no name group fee
3452 Vaishakh Science 270.00

adm_no name group fee


3452 Vaishakh Science 270.00
Accessing elements of structure

The structure member can be accessed by using the structure


variable with dot(.) operator.

structure_variable.element_name
- -

s.roll_no=5;
s.name=“abc”;
today.dd = 10;

strcpy(adm_date.month, "June");
cin >> s1.adm_no;
cout << c1.real + c2.real;
Write a c++ programme to read and print student details using structure.
Nested structure

it means structure with in a structure and inner most member in a


nested structure can be accessed by chaining all the conserved
structure. Variable [ outer most to inner most] with member using
dot operator (.)
Struct pay
{
Int basic;
Int da;
};
Struct employ
{
Int id;
Char name[10];
Struct pay p;
}
Void main()
{
Struct employ e;
e.id=101;
e.name=“abc”;
e.p.basic=10000;
e.p.da=101.5;
}
Definition A Definition B

struct date struct student


{ - {
short day; int adm_no;
=

short month; char name[20];


short year; struct date
}; {
-

struct student short day;


{
int adm_no;
Y short month;
short year;
char name [20]; } dt_adm;
date dt_adm; float fee;
-

float fee; }; -

};
student s = {4325, "Vishal", {10, 11, 1997}, 575};
cout<<s.adm_no<<s.name;

cout<<s.dt_adm.day<<"/"<<s.dt_adm.month<<"/"<<s.dt_adm.year;
outer_structure_varaiable.inner_structure_variable.element
Arrays Structures
-
It is a derived data type. It is a user-defined data type
T -

A collection of same type of data. A collection of different types of


data. -

- Elements of an array are referenced


using the corresponding subscripts.
-

Elements of structure are -


referenced using dot operator (.)
- When an element of an array -

becomes another array, multi- When an element of a structure


dimensional array is formed. becomes another structure, nested
- Array of structures is possible.
-
structure is formed.

Structure can contain arrays as


elements
Chapter 1

STRUCTURES
& POINTERS
Part 2
Contents
Pointer
Benefits of pointers
Declaring pointer variable
Methods Of Memory Allocation
Dynamic operators
Memory leak
Pointers
Pointer
A pointer is a derived data type.
It contain memory address of another variable.
It can be used to access & manipulate data stored in the memory.
Pointer
Pointers are more efficient in handling arrays.
Pointers can be used to return multiple values from a function.
Pointers support dynamic memory management.
Pointers provide an efficient tool for manipulating dynamic data
structures such as data structures linked list , queue.
Pointers reduced length and complexity of a programme.
Pointers increases the execution speed.
int num=25;

num 25
1001 1001 1001 1001
variable is associated with two values:
L-value and R-value,
where L-value is the address of the variable and Rvalue is its content.

Figure 1.5 shows that L-value of num is 1001 and R-value is 25


Declaring pointer variable
The declaration of a pointer variable take the following forms,

Data type * pointer_variable_name;

Eg:

int *p;
int *ptr1;
float *ptr2;
struct student *ptr3;
The address of a variable can be assigned to pointer variable using address
operator (&)

Eg:

int *p;
int a;
p=&a
& -address of
ptr1 = &num;
rains at
-
-

O ptr1 1001
1500
-~
num 25
1001
W
cout<< &num; 1001
-

cout<< ptr1; loo/ X



-

cout<< num; 25
ptr1 1001
-cout<< *ptr1; 25 1500
=>

cout<< &ptr1; 1500

O 25
- cout<< *num;
=
num
1001
cout<< &num; // 1001 (address of num) will be the output
cout<< ptr1; // 1001 (content of ptr1) will be the output
cout<< num; // 25 (content of num) will be the output
cout<< *ptr1;/* 25 (value in the location pointed to by
ptr1) will be the output */
cout<< &ptr1;// 1500 (address of ptr1) will be the output
cout<< *num; // Error!! num is not a pointer
The process of assigning address of a variable is known as initialization.

initialization:- int a;
int *p=&a;

A pointer can store address of similar variable only.

Eg:- int *p;


float f;
p=&f /error
It is possible to make a pointer to another pointer. Thus creating the chain
of pointers.

Int x,*p1,**p2;
X=100;
P1=&x;
P2=&p1
COUT<<**p2;
A pointer can be initialized with null or zero.
Multiplication is not possible on pointer variable.
Methods Of Memory Allocation
The memory allocation that takes place before the execution of the
program is known as static memory allocation.
-

memory is allocated during the execution of the program is called dynamic


-
memory allocation.
-

-
New : allocate
-
Dynamic operatives
- delete : de-allocate
Dynamic operators - new and delete
The operator new is a keyword in C++ and it triggers the allocation of
memory during run-time (execution).

following syntax is used for dynamic memory allocation:


pointer_variable = new data_type;
-
-

Int Aj
!
-

P =
new
;
Int
short * si_ptr;
float * fl_ptr;
struct complex * cx_ptr;
si_ptr = new short;
fl_ptr = new float;
cx_ptr = new complex;
si_ptr fl_ptr cx_ptr

1001 1010 1200

real imagenary

1000 1001 1010 1011 1012 1013 1200 1201 1202 1203
Allocated memory locations can also be initialised using the following syntax:

pointer_variable = new data_type(value);

The following examples show initialisation along with dynamic memory


allocation:

si_ptr = new short(0);


fl_ptr = new float(3.14);
delete operator is used with the following syntax: XTD
-
delete pointer_variable;
X y'
-

int
The following are valid examples:
P-
new int,
delete si_ptr;
delete fl_ptr, cx_ptr; delete :
Memory leak
Orphaned Memory Block -

If the memory allocated using new operator is not freed using delete,
that memory is said to be an orphaned memory block
-

a block of memory that is left unused, but not released for further
allocation. This memory block is allocated on each execution of the
program and the size of the orphaned block is increased. Thus a part
of the memory seems to disappear on every run of the program, and
eventually the amount of memory consumed has an unfavorable effect.
This situation is known as memory leak.
-
The following are the reasons for memory leak:
- Forgetting to delete the memory that has been allocated dynamically
(using new).
-Failing to execute the delete statement due to poor logic of the program
code.
-

-
Assigning the address returned by new operator to a pointer that was
-

already pointing to an allocated object


-
Arrays Arrays
i) Takes place before the execution of the
program.

ii) new operator is required

ii) Pointer is essential

iv) Data is referenced using variables

v) No statement is needed for de- allocation


Chapter 1

STRUCTURES
& POINTERS
Part 3
Contents
Operations on pointers
Arithmetic operations
on pointers
Relational operations
on pointers
Pointer and array
Dynamic array
Pointer and string
Array of strings
Pointer and structure
Self referential structure
Questions
Operations on pointers
The operators that can be used with pointers and how these
operations are performed.
Arithmetic operations on pointers
si_ptr and fl_ptr

si_ptr fl_ptr cx_ptr

1000 1010 1200

real imagenary

1000 1001 1010 1011 1012 1013 1200 1201 1202 1203
cout << si_ptr + 1;
cout << fl_ptr + 1;

What will be the output? Do you think that it will be 1001 and 1011?
When we add 1 to a short int pointer, the expression returns the address of
the next location of short int type.

si_ptr+1
(1000+(1*2))=1002 (size of short int is 2 bytes)

fl_ptr+1
(1010+(1*4))=1014 (size of float is 4 byte)

si_ptr+5=?
si_ptr+5 = (1000+5×2)=1010

fl_ptr+3 = (1010+3×4)=1022

This kind of operation is practically wrong.


Because we are trying to access locations that are not allocated for
authorised use. These locations might have been used by some other
variables. Sometimes these locations might not have been accessible due
to the violation of access rights.

No other arithmetic operations are performed on pointers


pointers are only incremented or decremented
int *ptr1, *ptr2; // Declaration of two integer pointers
ptr1 = new int(5); /* Dynamic memory allocation (let the
address be 1000)and initialisation with 5*/
ptr2 = ptr1 + 1; /* ptr2 will point to the very next
integer location with the address 1004 */
++ptr2; // Same as ptr2 = ptr2 + 1
cout<< ptr1; // Displays 1000
cout<< *ptr1; // Displays 5
cout<< ptr2; // Displays 1004
cin>> *ptr2; /* Reads an integer (say 12) and
stores it in location 1004 */
cout<< *ptr1 + 1; // Displays 6 (5 + 1)
cout<< *(ptr1 + 2);// Displays 12, the value at 1004
ptr1--; // Same as ptr1 = ptr1 - 1
To find the average height of students
#include <iostream>
using namespace std;
int main()
{
int *ht_ptr, n, s=0;
float avg_ht;
ht_ptr = new int; //dynamic memory allocation
cout<<"Enter the number of students: ";
cin>>n;
for (int i=0; i<n; i++)
{
cout<<"Enter the height of student "<<i+1<<" - ";
cin>>* (ht_ptr+i); //to get the address of the next location
s = s* (ht_ptr+i);
}
avg_ht = (float)s/n;
cout<<"Average height of students in the class = "<<avg_ht;
return 0;
Enter the number of students: 5
Enter the height of student 1 - 170
Enter the height of student 2 - 169
Enter the height of student 3 - 175
Enter the height of student 4 - 165
Enter the height of student 5 - 177
Average height of students in the class = 171.199997
we used arrays in such a situation. But the size should be specified during
the array declaration. This may cause wastage or insufficiency of memory
space.

Pointer and its arithmetic overcome this drawback.


But there is a problem in this kind of memory usage. It is not sure that
Program 1.3 will always run with any value of n.

pointer ht_ptr is initialised with the address of only one location. The memory
locations accessed using pointer arithmetic on ht_ptr are unauthorised, since
these locations are not allocated by the OS.

We can overcome these issues by the facility of dynamic arrays,


Relational operations on pointers
Among the six relational operators, only == (equality) and !=
(non-equality) operators are used with pointers.
If p and q are two pointers, they may contain the address of the same
integer location or different memory locations.

This can be verified with the expressions

p==q or p!=q
- - -
Int -
Pointer and array -
=

-
-

Figure 1.9 shows the memory allocation of an array ar[10] of int


type with 10 numbers.
ar -

O-
Int * Per
; O
1000

1004
O
34

⑧12
-
-
OL
P = 1000
fartoj
-

Ptr = 1008 8 -
-

1012 18

Cout2PEr;
1016

1020
24
38
S Anas abdul

1000 1024 43 Nizar


i
&

1028 14
cont ** A/34 1032

1036
7

O 9
19
Write C++ statement to display all the 10 elements of this array.
If ptr is an integer pointer

ptr = &ar[0];
int

cout<<ptr; //Displays 1000, the address of ar[0]


- 4 buts
-

cout<<*ptr; //Displays 34, the value of ar[0]


-

cout<<(ptr+1); //Displays 1004, the address of ar[1]


cout<<*(ptr+1); //Displays -
-

12, the value of ar[1]


-

cout<<(ptr+9); //Displays O
1036, the address of ar[9]
-

cout<<*(ptr+9); //DisplaysO
19, the value of ar[9]
--

=
loots
1x4
1000 +
- ⑩
9X7
+

-

1000
-
=
1000 + 36 =
-
Can you predict the output of the statement:

cout<<ar;
output will be 1000

The address of the first location of the array


The following C++ statement displays all the elements of this array:

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


cout<<*(ar+i)<<'\t';
There is a difference between an ordinary pointer and an array-name.

ptr++; is valid and is equivalent to ptr=ptr+1;

The statement ar++; is invalid,

Because array-name always contains the base address of the array, and it
cannot be changed.
Dynamic array
Dynamic array is created during run time using the dynamic memory
allocation operator new. -

The syntax is:

② pointer = new data_type[size];

new in + [5] ;
inf
To find the highest percent of pass in schools
#include <iostream>
using namespace std;
int main()
{
float *pass, max;
int i, n;
cout<<"Enter the number of schools: ";
cin>>n; //To input number of schools
pass new float [n]; //dynamic array having n elements
for (i=0; i<n; i++)
{
cout<<"Percent of pass by school "<<i+1<<": ";
cin>>pass[i]; //Concept of subscripted variable
}
max=pass[0];
for (i=1; i<n; i++) if (pass[i]>max) max = (pass+i);
/* Elements are accessed using subscript and pointer arithmetic operation */
cout<<"Highest percent is '<<max;
return 0;
}
Pointer and string
String data can be referenced by character array

char str[20]; //character array declaration


char *sp; //character pointer declaration
cin>>str; //To input a string, say "Program"
cout<<str; //Displays the string "Program"
sp=str; //Content of str is copied into the pointer sp
cout<<sp; //Displays the string "Program"
cout<<&str[0]; //Displays the string "Program"
cout<<sp+1; //Displays the string "rogram"
cout<<&str+1; //Displays the string "rogram"
/* The two statements given above display the substring
starting from 2nd character onwards */
cout<<str[0]; //Displays the character 'P'
cout<<*sp; //Displays the character 'P'
cout<<&str; //Displays the base address of the array str
cout<<&sp; //Displays the address of the pointer sp
chor y Chor
:

P
SPET
*
Advantages of character pointer
~Since there is no size specification, a string of any number of characters
can be stored. There is no wastage or insufficiency of memory space. But it
-

should be done with initialization. (e.g., char *str = "Program";)


~Assignment operator (=) can be used to copy strings.
- Any character in the string can be referenced using the concept of
pointer arithmetic which makes access faster.
-Array of strings can be managed with optimal use of memory space.
-
Array of strings
A array or character pointer can be used to store only one name at a
time. Here we need to refer to a collection of strings
("Sunday", "Monday", ..., "Saturday“)

The following statement declares an array of character pointers to


handle this case:

char *name[7];
This array can contain a maximum of 7 strings, where each string can
contain any number of characters.

char *week[7]={"Sunday", "Monday", "Tuesday", "Wednesday",


"Thursday", "Friday", "Saturday"}; \
Pointer and structure
Structures are accessed by pointers. A structure is defined to represent
the details of employees as follows:

struct employee

{
int ecode;
char ename[15];
float salary;
};
employee *eptr;
It is clear that eptr is a pointer that can hold the address of employee
type data. The statement:

eptr = new employee;


eptr

ecode ename salary


structure is accessed in terms of its elements with the following format:

structure_variable.element_name

have to use the pointer eptr. The syntax for accessing the elements of a
structure is as follows:

structure_pointer->element_name
Self referential structure -

-
Self referential structure is a structure in which one of the elements is a
pointer to the same structure.
- - -

-
struct node
{
int date1;
char date2;
struct node *link;
}; xyz
Self referential structure is a powerful tool of C and C++ languages
that helps to develop dynamic data structures like linked list, tree, etc

The memory locations are scattered, but there will be a link from one
location to another
Q. Run time allocation of memory is triggered by the operator ……

Ans. new.

Q. Define a structure named ‘Time’ with elements hour, minute and second

Ans. struct Time


{
int hour;
int minute;
int second;
};
Q. Read the following C++ code
int a[5]={10,15,20,25,30};
int *p=a;
Write the output of the following statements:

a) cout<<*(p+2);
b) cout<<*p+3;

Ans.

a)20
b)13
Q. What are the different memory allocations in C++? Explain

Ans. Different memory allocations are: Static and Dynamic Memory Allocation

Arrays Arrays
i) Takes place before the execution of the
program.

ii) new operator is required

ii) Pointer is essential

iv) Data is referenced using variables

v) No statement is needed for de- allocation


Q. Identify and correct the errors in the following code fragment

struct
{
int regno ;
char name[20] ;
float mark=100 ;
};

Ans.

.
.1.struct tagname
2.float mark=100;
Q.Structure with in a structure is termed as -----------------.

Ans.
Nested structure
Q. Consider the given structure definition
{
int real;
int imag;
};

a) Write a C++ statement to create a structure variable


b) write a C++ statement to store the value 15 to the structure member real
Ans.

(a) complex c1;


or
struct complex c1;
or
struct complex
{
int real;
int imag;
}c1;

(b) c1.real=15;
Q. Write the use of * and & operators used in pointer

Ans.
The dereference operator (*) retrieves the value pointed to by the pointer
Address of operator ( & ), to get the address of a variable
Q. Distinguish between array and structure

Ans:
Arrays Arrays
Derived data type User defined data type

Same type of data Different type of data

Elements are referenced using Elements are referenced using


subscripts .(dot) operator

Multi dimensional array Nested structure

Array of structures Elements as arrays


Q. How will you free the allocated memory?

Ans:
Using delete operator
Q. What is the difference between the declaration statements given below ?

( a ) int * ptr = new int ( 10 ) ;


( b ) int * ptr = new int [10 ] ;
Ans.

( a ) int * ptr = new int ( 10 ) ; This is dynamic initialization of a pointer


variable with value 10.

( b) int * ptr = new int [10 ] ; This is creation of a dynamic array of size 10.
Q. What is a pointer in C++ ? Declare a pointer and initialize with the name
of your country.

Ans.
Pointer is a variable that can hold the address of a memory location.
It is a primitive since it contains memory address which is atomic in nature.

char *name_of_nation = “ India “ ;


CHAPTER 2

CONCEPTS OF OBJECT
ORIENTED PROGRAMMING
Part 1
Content

Programming paradigm

Procedure-Oriented Programming paradigm

Object-Oriented Programming (OOP) paradigm

Basic concepts of OOP

Objects

Classes
Data abstraction

Data Encapsulation

Modularity
PROGRAMMING
Programming paradigm

Way in which a program is organized(more need in larger programme)


Capabilities and styles of various programming languages are defined
by the programming paradigms supported by them.
The various approaches that have been tried are modular programming
top-down programming
bottom-up programming
structured programming.
C++ is a multiple paradigm language.
we can implement two of the most important programming paradigms,
the procedural paradigm and the object-oriented paradigm.
Procedure-Oriented Programming paradigm -

Procedure-Oriented Programming specifies a series of well-structured


-

steps and procedures to compose a program.


-
-
The main reasons for the increasing complexity with procedural languages are:
a. Data is undervalued.
b. Adding new data element may require modifications to
all/many functions.
c. Creating new data types is difficult.
d. Provides poor real world modelling.
Data is undervalued -

In procedural language, emphasis is on doing things. Here data is given


less importance.
-

-
The arrangement of local variables, global variables and functions in a
procedural programming paradigm
-
Adding new data element may require modifications to
all/many functions
Since many functions access global data, the way the data is stored is important.
The arrangement of data cannot be changed without modifying all the functions
that access it.
~
Creating new data types is difficult

Computer languages typically have several built-in data types like integer, float,
character and double. Certain programming language allows creation of data
types other than the built-in data type, which means they are extensible.
-
Provides poor real world modelling -

In procedural programming paradigm, functions and data are not considered


as a single unit and are independent of each other. So neither data nor functions
in procedure oriented paradigm, by themselves, cannot model real-world


objects effectively.
A
date
Object-Oriented Programming (OOP) paradigm -

Object-oriented paradigm eliminates the problems in the procedural paradigm


by clubbing data and functions that operate on that data into a single unit. In
OOP, such a unit is called an object.

⑳ -
Advantages of using OOP are:

a. OOP provides a clear modular structure for programs.


b. It is good for defining abstract data types.
c. Implementation details are hidden from other modules and have a clearly
defined interface.
d. It is easy to maintain and modify the existing code as new objects can be
created without disturbing the existing ones.
e. It can be used to implement real life scenarios.
f. It can define new data types as well as new operations for operators
Basic concepts of OOP
-
Objects
-
Classes
Data abstraction -

Data Encapsulation
-
Modularity ~

Inheritance -
Polymorphism -
Objects

Anything that we see around us can be treated as an object and all these
objects have properties (also called member/data/state) and behaviour
--
(also called methods/member functions).
-
Student
State
RegNo, Name, Age,
Weight, Height, Mark

Behavior
Register, Change mark,
Change Height Weight Stack
State
Push Pop
Top, Length, Full,
Clock Empty
State
Dial Color, Hour Behavior
Minute Push, Pop
Behavior
Set Time, Showtime
Radio
State
On Off, Current Volume,
Current Station
Behavior
Turn on off, Increase
volume, Decrease volume,
seek, scan, and tune Array
State
Length, Full, Empty,
Student 0 1 2 3 4 Current Index
State Behavior
Name, Current Gear, Insert, Delete, Sort,
Current Speed, Traverse, Merge, Print
Headlight Status
Behavior
Push accelerator,
Change gear, light on off
Dog
State
Name, Color, Breed,
Hungry

Behavior
Barking, Fetching.
Wagging tail Window
State
Top, Left, Name,
Current State

Bike
State Behavior
Speed, Acceleration, Minimise, Maximise,
Current Gear Move, Close

Behavior
Turn the accelerator,
Push the brake, Change
gear
Classes -
A class is a prototype/blue print that defines the specification common to all
-
objects of a particular type.
-
General form of a class
declaration

class class_name
Variables
{
declared inside
private: known as
variable declarations; data member

function declarations;

public:

variable declarations;"
Functions declared
inside the class are function declarations;
known as member }
functions (behavior)
Example for class
class cube class Name
{
private:
int height, color; Data Members
public:
void get_cube_info()
{
cout << "Enter Height: ";
cin >> height; Member/ Function
cout << "Enter Color: "; Method/ Behavior
cin >> color;
}
};
Class: A class in C++ is the building block, that leads to Object-Oriented
programming. It is a user-defined data type, which holds its own data members
and member functions, which can be accessed and used by creating an instance
of that class. A C++ class is like a blueprint for an object.

Object is an instance of a Class. When a class is defined, no memory is allocated


but when it is instantiated (i.e. an object is created) memory is allocated.�
Defining Class and Declaring Objects
A class is defined in C++ using keyword class followed by the name of class.
The body of class is defined inside the curly brackets and terminated by a
semicolon at the end.
Declaring Objects: When a class is defined, only the specification for the object
is defined; no memory or storage is allocated. To use the data and access
functions defined in the class, you need to create objects.
Syntax:
ClassName ObjectName;
Class class_name
{
Access specifier:
data members;
Access specifier:
member function;
};
Class abc
{
Public:
int rol;
char name[10];
Public:
void read();
void print();
};
write a programme to read and print student details using class

#include<iostream.h>
#include<conio.h>
Class student
{
Private:
char name[10];
int age;
Public:
void read()
{
cout<<“enter the name”;
cin>>name;
cout<<“enter the age “;
cin>>age;
}
void print()
{
cout<<“name =“<<name;
cout<<“age=“<<age;
}
};
Void main()
{
Clrscr();
Student s;
s.read();
s.print();
Getch();
}
Passing Message.
Objects can communicate with each other by passing message, which is
similar to people passing message with each other. This helps in building
systems that simulate real life. In OOP, calling member function of an object
from another object is called passing message. Message passing involves
specifying the name of object, the name of the member function, and the
information to be sent.
Data abstraction

Data abstraction refers to showing only the essential features of the application
and hiding the details from outside world.

C++ classes provide great level of data abstraction. They provide public methods
/functions to the outside world to use the functionality of an object and to
manipulate object data.
Data Encapsulation
Encapsulation is an OOP concept that binds together the data and functions
-
-

that manipulate the data, and keeps both data and function safe from outside
interference and misuse.

C++ implements encapsulation and data hiding through the declaration of a


class. A C++ class can contain private, protected and public members.

C++ implements encapsulation and data hiding through the declaration of a


class. A C++ class can contain private, protected and public members.
Modularity
Modularity is a concept through which a program is partitioned into modules
that can be considered and written on their own, with no consideration of any
other module.

School Software

Student Teacher
CHAPTER 2

CONCEPTS OF OBJECT
ORIENTED PROGRAMMING
Part 2
Content
Basic concepts of OOP
Inheritance
Polymorphism
Basic concepts of OOP
Inheritance
Inheritance is the process by which objects of one class acquire
the properties and functionalities of another class. Inheritance
supports the concept of hierarchical classification and reusability.

Class E
S'B
i S
Vehicle

Land Vehicle Water Vehicle

Car Truck Hovercraft Boat

Inheritance in real world


The capability of a class to derive properties and characteristics
from another class is called Inheritance.
Inheritance is one of the most important feature of Object Oriented
Programming.
-
Sub Class: The class that inherits properties from another class is

E called Sub class or Derived Class.


Super Class:The class whose properties are inherited by sub class
is called Base Class or Super class.
Types of Inheritance in C++

1. Single Inheritance -
-
2. Multiple Inheritance
-
3. Multilevel Inheritance
-
4. Hierarchical Inheritance
5. Hybrid (Virtual) Inheritance -
1. Single Inheritance: In single inheritance, a class is allowed to
inherit from only one class. i.e. one sub class is inherited by one
base class only.

E
Class A (Base Class)

Class B (Derived Class)


Syntax:

class subclass_name : access_mode base_class


{
//body of subclass
};
Class A
{
…………
……..
};
Class B: public A
{
………..
…….
};
2. Multiple Inheritance: Multiple Inheritance is a feature of C++
where a class can inherit from more than one classes. i.e one sub
class is inherited from more than one base classes.
- 1

Class B Class c

(Base Class 1) (Base Class 2)

Class A L

(Derived Class)
class subclass_name : access_mode base_class1,
access_mode base_class2, ....
{
//body of subclass
};
Class A
{
…………
……..
};
Class B
{
………..
…….
};
Class C: public A, public B
{
……
……
}
3. Multilevel Inheritance:
In this type of inheritance, a derived class is created from another
derived class.

-
Class c (Base Class 2)

(Base Class 1) Class B

Class A (Derived Class)


Class A
{
…………
……..
};
Class B : public A
{
………..
…….
};
Class C: public B
{
……
……
}
4. Hierarchical Inheritance:
In this type of inheritance, more than one sub class is inherited
from a single base class. i.e. more than one derived class is created
from a single base class.
O Class G

Class B Class E

Class A Class c Class D Class F


5. Hybrid (Virtual) Inheritance:
Hybrid Inheritance is implemented by combining more than
one type of inheritance. For example: Combining Hierarchical
inheritance and Multiple Inheritance. �Below image shows the
combination of hierarchical and multiple inheritance:
Class F Class G

Class E
Class B

Class A Class c
Polymorphism -
The word polymorphism means having many forms. In simple
words, we can define polymorphism as the ability of a message
to be displayed in more than one form.
In C++ polymorphism is mainly divided into two types:
Compile time Polymorphism -
Runtime Polymorphism -
polymorphism

Compile Time Run Time

Functions Operator Virtual


Overloding Overloding Functions
Compile time polymorphism:
This type of polymorphism is achieved by function overloading
or operator overloading
- Sumcint int ,

Function Overloading in C++ ~ float)


Sum (first,
Function overloading is a feature of object oriented programming where two or more
functions can have the same name but different parameters.

When a function name is overloaded with different jobs it is called Function Overloading.

In Function Overloading “Function” name should be the same and the arguments should
be different.

Function overloading can be considered as an example of polymorphism feature in C++.


#include <iostream>
using namespace std;

void print(int i)
{
cout << " Here is int " << i << endl;
}
void print(double f)
{
cout << " Here is float " << f << endl;
}
void print(char const *c)
{
cout << " Here is char* " << c << endl;
}
int main()
{ Out put
print(10); Here is int 10 Here is
float 10.1 Here is
print(10.10); char* ten

print("ten");
return 0;
}
Operator Overloading in C++

In C++, we can make operators to work for user defined classes.


This means C++ has the ability to provide the operators with a
special meaning for a data type, this ability is known as operator
-
overloading. For example, we can overload an operator ‘+’ in a
-

class like String so that we can concatenate two strings by just


using +. 32
①2
-
0
1
-

2
.
.

103 ↓
-
-
S
Runtime polymorphism

Runtime polymorphism: This type of polymorphism is achieved


by Function Overriding.

Function overriding on the other hand occurs when a derived


class has a definition for one of the member functions of the
base class. That base function is said to be overridden.
function overriding allows us to override a function of base/
parent class in derived a child class,

#include<iostream.h>
Class A
{
Public :
void show()
{
cout<<“show base class”;
}
};
Class B: public A Obj.show();
{ Return 0;
public: }
void show()
{ Out put
Show child class
cout<<“show child class”;
};
Int main()
{
B obj;
Function overloading:
same name
with different arguments
Function overriding:
same name
with same arguments
inheritance should be the there if you are function override.
DATA
STRUCTURE
-
Part 1
Definition
Data structure is a particular way of organising
similar or dissimilar logically related data items
-
which can be processed as a single unit.

Data Stuctures
-
-Simple Data Stuctures Compound Data Stuctures -

-
-
Array Structure Linear Non-Linear

-
-

-
Linked List
Tree
Queue

Stack Graph

-
Operations on Data structure
-
1. Traversing : Traversing is an operation in which each
element of a data structure is visited. The travel proceeds
from the first element to the last one in the data structure.
-
2. Searching : Searching, in the literal sense, is the process
of finding the location of a particular element in a data
structure. In other words, searching implies accessing the
values stored in the data structure.
-
3. Inserting :
Insertion is the operation in which a new data is added at a
particular place in a data structure. In some situation, where
the elements in the data structure are in a particular order, the
position may need to be identified first and then the insertion
is to be done.
-
4. Deleting : Deletion is the operation in which a particular
element is removed from the data structure. The deletion is
performed either by mentioning the element itself or by
specifying its position.
-
5. Sorting :
We are familiar with the sorting of an array using two
methods named bubble sort and selection sort. It is
the technique of arranging the elements in a
specified order, i.e., either in ascending or
descending order. Sorting of elements in a data
structure makes searching faster.
-
6. Merging : Merging usually refers to the process of
combining elements of two sorted data structures to
form a new one.
Stack -

-
In Data structure Last element is removed first . This
organising principle is known as Last-In-First-Out
(LIFO).
-
-

The data structure that follows LIFO principle is known


as stack.

It is an ordered list of items in which all insertions and


deletions are made at one end, usually called -- Top.
o
Since it follows the LIFO principle, the element added at
last will be the first to be removed from the stack.
Operations on stack
1. PUSH
2. POP
~
Overflow - ⑳
Attempt to insert an item in a Filled stack or queue.

Underflow ~
Attempt to remove an item from an empty stack or queue .
1.Push OPERATION STACK
Push operation is the process
of inserting a new data item
into the stack .
OP
; -

=T
T TOP=-

Start - I
1: If (TOS<N) Then
2: 𝑇𝑂𝑆 = 𝑇𝑂𝑆 + 1 \\ Space avallability checking (Overflow)

TOS = -I
3:
4: Else
STACK[TOS] = VAL
STACKIOS=T
5: Print "Stack Underflow"

Go Of
=
6: End of If STACk[l]
End -I
-
124 Tos = -It -

ocS = 5-1
New New New New New
Item Item Item Item Item
9 9 9 9 9
25 34 18 56
8 8 8 8 8

7 7 7 7 7
New New New New New
Item 6 Item 6 Item 6 Item 6 Item 6
3 0 1 2 3
5 5 5 5 5

4 4 4 4 4

3 3 3 3 TOS 3 56

2 2 2 TOS 2 18 2 18

1 1 TOS 1 34 1 34 1 34

0 TOS 0 25 0 25 0 25 0 25
Stack Stack Stack Stack Stack
TOS

Empty Stack Added 1st Stack Added 2nd Stack Added 3rd Stack Added 4th Stack
s
2
1.POP OPERATION
The process of deleting an
element from the top of a
stack is called Pop operation

= / TOC = 1 1
ros= -
-

Start
1: If (TOS ⟩ − 1) Then P -
2: VAL = STACK [TOS] \\ Empty status checking (Underflow) -

3: TOS = TOS -1 -

4: Else jus = -


5: Print "Stack Underflow"
6: End of If

End

07-1 STACK [1]


STACK(0]
New New New
Item Item Item
9 9 9
56 18 34
8 8 8

7 7 7
New New New
Item 6 Item 6 Item 6
2 1 0
5 5 5

4 4 4

3 56 3 3

TOS 2 18 2 18 2

1 34 TOS 1 34 1 34

0 25 0 25 TOS 0 25
Stack Stack STK[10]
After the retrievel of After the retrievel of After the retrievel of
Item TOS becomes 2 Item TOS becomes 1 Item TOS becomes 0
C++ Functions for Stack Operations
The Variables tos and n are assumed as global variables

PUSH Operation POP Operation


void push(int stack[],int val) int pop(int stack[])
{ {
i f (t o s < n) int val;
{ i f (t o s > - 1)
tos++; {
s t a c k[t o s]= v a l ; v a l =s t a c k [t o s];
q[r e a r]= v a l ; tos--;
} }
else else
c o u t << ” O v e r f l o w ” ; c o u t << ” U n d e r f l o w ” ;
} return val;
}
DATA
STRUCTURE
Part 2
Queue
In a data structure , First element is removed first is called FIFO.
-
A data structure that follow FIFO principle is known as QUEUE .
--
QUEUE has two end points - front and rear .
-
Inserting a new data item in a queue will be at the rear position
and deleting will be at the front position .

Front Rear
0 4

QUEQUE 16 38 9 65
0 1 2 3 4 5 6 7 8 9
Operations on queue
1. Insertion -
2. Deletion -
1. Insertion
Insertion is the process of adding a new item into a queue at the
rear end. The value of Rear is incremented first to point to the
next location and the element is inserted at that position.
Algorithm: To perform INSERTION operation in a queue

Consider an array QUEUE[N] that implements a queue, where N is the maximum size of
the array. The variables FRONT and REAR keep track of the front and rear positions of the
queue. A data item available in the variable VAL is to be inserted into the stack. The steps
required for insertion operation are given between the Start and Stop instructions.

Start
1:
2:
If ( REAR = −1) Then itikil
FRONT = REAR = 0 //Empty status checking
,
3: Q [REAR] =VAL
~ 4: Else If ( REAR < N) Then //Space availability checking

5: -
REAR = REAR -
+1

P(0] = 25 6: 𝑄Q [REAR] =VAL


7:
8:
9:
Else
Print "Queue Overflow"
End of If
t
Front Rear
-1 -1
QUEQUE EMTY QUEQUE

0 1 2 3 4 5 6 7 8 9

New Item
Front 25 Rear
0 0
QUEQUE 25 1st term is
inserted
0 1 2 3 4 5 6 7 8 9

New Item
Front 16 Rear
0 1
QUEQUE 25 16 2st term is
inserted
0 1 2 3 4 5 6 7 8 9

New Item
Front 38 Rear
0 2
QUEQUE 25 16 38 3st term is
0 1 2 3 4 5 6 7 8 9 inserted
2. Deletion
Deletion operation is the removal of the item at the front end. After
the deletion the value of Front is incremented by 1.
Algorithm: To perform DELETION operation in a queue

Consider an array QUEUE[N] that implements a queue with a maximum of N elements.


The variables FRONT and REAR keep track of the front and rear positions of the queue. The
data item removed from the queue will be stored in the variable VAL. The steps required
for deletion operation are given between the Start and Stop instructions.

Start =
1: If (FRONT >-1 AND FRONT < REAR) Then
2: 𝑉𝐴𝐿 = 𝑄[𝐹𝑅𝑂𝑁𝑇] //Empty status checking

3: FRONT = FRONT +1
4: Else // Checking the deletion of last element

5: Print "Queue Underflow"


6: End of If
7: If (FRONT > REAR) Then
8: 8: FRONT = REAR = −1
9: 9: End of If
Retrieved Item
Front 25 Rear
1 2
QUEQUE 25 16 38 2st term is
retrieved
0 1 2 3 4 5 6 7 8 9

Retrieved Item
Front 38 Rear
2 2
QUEQUE 16 38 3st term is
0 1 2 3 4 5 6 7 8 9 retrieved
C++ Functions for Queue Operations
The Variables n, front and rear are assumed as global variables

INSERTION Operation DELETION Operation


void ins_q(int queue[],int val) int del_q(int queue[])
{ {
i f (r e a r == - 1) int val
{ i f (r e a r == - 1)
front=0; {
rear=0; v a l = q[f r o n t];
q[r e a r]= v a l ; fro nt++;
{ }
e l s e (i f r e a r < n) else
{ c o u t << ” O v e r f l o w ” ;
re ar++; i f (f r o n t > r e a r)
q[r e a r]= v a l ; {
} fro nt=-1;
else re a r=-1
c o u t << ” O v e r f l o w ” ; }
} return val;
}
Circular QUEUE
Consider a Linear Queue,

Front Rear
0 4
-

QUEQUE 87 42 64 71s E
0 1 2 3 4 5 6 7 8 9

which six deletion operations are done. At present, there are only
three elements. Obviously, the value of Front is 6 and that of
Rear is 8.
Even though the first six locations are free, we can insert only one
element according to the insertion algorithm. Imagine the worst
situation that there is only one element at the last position of the
queue (say at 9). If we try an insertion operation in this queue, there
will be overflow situation. This limitation of linear queue can be
overcome by circular queue.
In Circular Queue , it follows FIFO principle and last position is
connected back to the first position to make a circle .

56 29 56 29
3 4 3 4

47 35 47 35
2 5 2 5

1 6 1 6
13

**
0 7 0 7
25

Rear gets the lower


Rear gets its highest value
bound value
56 29 56 29
3 4 3 4

47 35 47 35
2 5 2 5

1 6 1 6
87 87

O0 7
-
0 ↓ 7
64 18 64
-

⑫o
Rear gets its highest value
Rear gets the lower
bound value
Assume that two deletions are performed at this stage.

So the value of Front will be 2 and now we have four free


locations.

The subscripts of these position are 6, 7 and then 0, 1.

If we insert two elements one by one, the value of Rear becomes


7, but still we have two free locations with subscripts 0 and 1.

So insertion operation can be performed again. This time the


value of Rear should be set with 0 first and then insertion is to
be carried out.
Linked List
Linked list is a collection of nodes, where each node consists of
a data and a link - a pointer to the next node in the list.
-

That is, the first node in the list contains the first data item and
the address of the second node

The second node contains the second data and the address of
the third node; and so on.

The last node at a particular stage contains the last data in the
list and a null pointer

First node address contains in start or head node .


25 34 17 48 64
Node 1 Node 2 Node 3 Node 4 Node 5

Implementation of linked list START


1000

-
struct Node SONU 1200 I -

{
-
1000

2 -

int data;
NIVED 1300
1200

Node *link;
-

SNEHA 1500 3-
}; O 1300

---
S
NIKETH
1500
NULL
-
Eg :
struct Node
{
char data[10];
Node *link;
}
Operations of Linked List
1. Creation of linked list
2. Traversing a linked list
3. Inserting in a linked list
4. Deleting from Linked list
1. Creation of linked list

Step 1: Create a node and obtain its address.

Step 2: Store data and NULL in the node.

Step 3: If it is the first node, store its address in Start.

Step 4: If it is not the first node, store its address in the link part
of the previous node.

Step 5: Repeat the steps 1 to 4 as long as the user wants.


2. Traversing a linked list

Step 1: Get the address of the first node from Start and store it in
Temp.

Step 2: Using the address in Temp, get the data of the first node
and store in Val.

Step 3: Also get the content of the link part of this node (i.e., the
address of the next node) and store it in Temp.

Step 4: If the content of Temp is not NULL, go to step 2; otherwise


stop.
3. Insertion in a linked list
Step 1: Create a node and store its address in Temp.

Step 2: Store the data and link part of this node using Temp.

Step 3: Obtain the addresses of the nodes at positions (POS-1) and


(POS+1) in the pointers PreNode and PostNode respectively, with the
help of a traversal operation.

Step 4: Copy the content of Temp (address of the new node) into the link
part of node at position (POS-1), which can be accessed using PreNode.

Step 5: Copy the content of PostNode (address of the node at


position POS+1) into the link part of the new node that is pointed to
by Temp.
4. Deleting from linked list

Step 1: Obtain the addresses of the nodes at positions (POS-1) and


(POS+1) in the pointers PreNode and PostNode respectively, with the
help of a traversal operation.

Step 2: Copy the content of PostNode (address of the node at


position POS+1) into the link part of the node at position (POS-1),
which can be accessed using PreNode.

Step 3: Free the node at position POS.


web technology
Chapter 4
1.Web server
web server computer and a web server software.
A web server consists of a server computer that runs a
server operating system and a web server software installed on it for
- -
providing services like www, e-mail, etc. over the Internet.
-
2 Software ports
A software port is used to connect a client computer to a server
to access its services like HTTP, FTP, SMTP, etc.
-

software ports are given unique numbers.


Port number is a 16-bit number which when added to a
computer's IP address/ URL.

http://google.co.in:80
-
-

- -

-
-

-
-

- -
- -

- -
~
-

- - -
-

- & -
-

- -
-

- -
-

-
-
- -

-
-
-

- -

- -

-
Cascading Style Sheet

Cascading Style Sheets (CSS) is a style sheet language used for


describing the formatting of a document written in HTML.
Using CSS, we can control the colour of the text, the style of
fonts, the spacing between paragraphs..etc

CSS can be implemented in three different ways –


inline, embedded and linked.
-/
-
In inline style, the CSS style is applied to each tag separately using the
style attribute in the body part of the web page. -

-
 Embedded CSS codes are placed within the <head>part of the web
page. -
-

-Linked CSS implementation is done using an external file with the file
extension .css that contains only CSS code and is linked with the web
-

page.
Basic concepts of HTML documents
HTML is the most widely used language to write web pages.
HTML tags
attributes

“HTML document is made up of tags and attributes which work


together to decide how the contents of the web page have to be
displayed on the browser”
Basic structure of an HTML document

~
-
- -
--
-

W -
We can use either the upper or lower case or even a mix of the two.
Tags in HTML document
Tags are the commands used in the HTML document that tell
web browsers how to format and organize our web pages to show the
contents.
Every tag consists of a tag name enclosed between the angle
brackets '<' and '>’.

<html> </html>
Container tags and empty tags -

Tags that require opening tag as well as closing tag are known as
-
container tags.
Eg:- <body>………</body>
--

Tags do not require closing tag. Such tags are known as empty tags.
-

Eg:-<BR>,<HR>,<IMG>
-
Attributes of tags
Certain parameters are frequently included within the opening
tag to provide additional information such as colour, measurement,
location, alignment or other appearances to the web browser. These
parameters are called attributes.

“In HTML, the value can be given in single quotes or double quotes
(i.e., attribute='value' or attribute="value").”

Eg:-<BODY Bgcolor=“Yellow’’>………..</BODY>
HTML Elements
A pair of tags and the content enclosed between these tags are
known as an element.
Creating an HTML document

Text editors like Geany, Gedit, TextPad, Notepad, Notepad++, etc. can
be used to create HTML documents.
Extension .html or .htm (for example, sample.html).
-

Viewing an HTML document in a Browser


Browsers like Mozilla Firefox, Google Chrome, Internet Explorer,
Netscape navigator, etc.
Essential HTML tags

1.<HTML> Starting an HTML page -


2.<HEAD> Creating head -
-
3.<TITLE> Creating a title
-
4.<BODY> Creating a body
1.<HTML> Starting an HTML page
In general <HTML> is always the first tag in an HTML page and
the </HTML> is the last tag. Everything else in the web page is in
between these two tags.

The main attributes of the <HTML> tag are Dir and Lang.
-
Dir
specifies the direction of the text to be displayed on the web
page. -

This attribute can have values either ltr (left-to-right) or rtl


-
(right-to-left). -

Eg:- <HTML Dir=“rtl”>


Lang
Specifies the language we have generally used within the
document.
Eg:- <html Lang=“ar”>
-
2.<HEAD> Creating head
It contains the head of an HTML document, which holds
information about the document such as its title, scripts used, style
definitions, etc.

<HEAD> and </HEAD>


3.<TITLE> Creating a title
Contains the title of the HTML document, which will appear in
the web browser's title bar.

<TITLE> and </TITLE>

“used inside the tag pair <HEAD> & </HEAD> tag”


4.<BODY> Creating a body
The body tag pair <body> and </body> specifies the document
body section.

various attributes of <body> tag:-


Background -
-
Bgcolor
-
Text
Link, Alink and Vlink -
Leftmargin and Topmargin -
Background
This attribute sets an image as background for the documents
body. -
-
Bgcolor -
This attribute specifies a colour for the background of the
-
document body.

--
The value of Bgcolor attribute can be given in two ways.
Color_name - specifies the background colour with a colour name
(like "red", "grey" etc.)

Hex_number - specifies the background colour with a hexadecimal


code (like "#ff6080", "#303030" etc.). Each hexadecimal code will be
preceded with a hash sign #.
Text
This attribute specifies the colour of the text content in the page.

-
Link, Alink and Vlink
-
Link: This attribute specifies the colour of the hyperlinks that are not
visited by the viewer. The default colour for Link attribute is blue.
~
Alink: It specifies the colour of the active hyperlink. The link remains
active only for the moment the mouse is clicked on it. Hence at the
time of selection the colour of the link will be changed to Alink value.
The default Alink colour is green.
-
Vlink: It specifies the colour of the hyperlink which is already visited by
the viewer. The default colour for Vlink is purple.
Leftmargin and Topmargin
The margin refers to the blank area left from the edge of the
page.
Some common tags
Heading tags
<H1></H1>, <H2></H2>, <H3></H3>, <H4></H4>, <H5></H5>,
<H6></H6>.

“ Here <H1>creates the biggest text and <H2> the smallest.”


attribute of this tag is Align and the possible values are,

Left : Text is aligned to the left margin.


Right : Text is aligned to the right margin.
Center : Text is aligned to the center of the page.
Creating paragraphs
use opening tag <p> and closing tag </p>

“The Align attribute sets the alignment of the text in the paragraph
with the values left, right, center or justify.”
- Inserting line break
 using tag <br>
creating horizontal line
use tag <HR>
Attributes Size and Width.
<HR>is an empty tag.
 Other attributes Align , Noshade and Color
Centering the content
Use the tag <center> and </center>
Text formatting tags
• <B> -Making text bold -
-
• <i>- Italicising the text
• <u>- Underlining the text L-

• <s> and <STRIKE> - Striking through the text -


-
(“tags are used for the same effect.”)
• <BIG>- Making the text bigsized. -
• <SMALL>- Making the text smallsized -
• <STRONG>- Making bold text -
(It defines an important text. same as <B> tag )
-
-
--

-
- -
He Suy So <sub > 2
It <subsa < /sub)
/sub>

• <EM>- Emphasising the text -


(same as that of <i> tag>
Creating subscripts and superscripts
using tags <sub> </sub> and <sup> </sup>
- -

2
(𝑎 + 𝑏) = a + 2ab+ 𝑏
- -

-
---
- ----
• <BLOCKQUOTE> and <Q>tags - Indenting a quotation
<PRE>- Displaying preformatted text
Suppose we want to display the content as we entered in the
text editor.
Normally the browser delimited the white spaces, new line
characters, the tab spaces, etc.
<ADDRESS>- Displaying the address
<ADDRESS> tag defines the contact information for the
author/owner of a document or an article. The content of this tag can
include name, phone numbers, PIN numbers, e-mail addresses, etc.
Most of the browsers display the texts in italics.
<MARQUEE>- Displaying text in a scrolling Marquee
<MARQUEE> displays a piece of text or image scrolling horizontally
or vertically in the web page.

list of important attributes that are used with <MARQUEE> tag:-

Height: Sets the height of the marquee in pixels or in percentage of


browser window height.
 Width: This specifies the width of the marquee in pixels or in
percentage of browser window's width value.
Direction: This specifies the direction in which marquee should scroll.
This can have a value like up, down, left or right.
 Behaviour: This specifies the type of scrolling of the marquee. This can
have a value like scroll, slide and alternate.
Scrolldelay: This specifies time delay between each jump. This will
have value in seconds like 10, 15, etc.
 Scrollamount: This specifies the speed of the marquee text.
Loop: This specifies how many times the marquee element should
scroll on the screen. The default value is Infinte, which means that the
marquee scrolls endlessly.
 Bgcolor: This specifies background colour in terms of colour name or
colour hex value.
 Hspace: This specifies horizontal space around the marquee. This can
be a value in pixels or percentage value.
Vspace: This specifies vertical space around the marquee. This can be
a value in pixels or percentage value.
<DIV>- Formatting a block of text
Tag is used for defining a section or a block in the document.
This section may contain paragraphs, tables, etc

The attributes of tag are:


-Align : sets the horizontal alignment with values left, right, center, and
justify.
-Id : assigns a unique identifier for the tag.
~Style : indicates how to render the content in terms of colour, font, etc.
- Specifying font characteristics
Tag <FONT>
 tag allows us to change the size, style and colour of the text
enclosed within <FONT> and </FONT> tags

The attributes of tag are:


Color : This attribute sets the text colour using either a ColorName or a
colour in the Hexadecimal format.
Face : This attribute specifies the font face. If no face attribute is
mentioned, the document text in the default style is used in the
first font face that the browser supports.
Size : This attribute specifies the font size whose value ranges from 1 to
7, with default value 3.
HTML entities for reserved characters
In HTML, the symbols like , &, etc. have special meaning and
cannot be used in the HTML documents as part of the text content.
In order to display the text A < B & A > C in a web document, we have
to specify it in the HTML document as:
Adding comments in HTML document
Comments are not displayed in the browser window. HTML
comments are placed within <!-- --> tag.
Inserting images
 Tag <img>
-

--
Setting space for the image
attributes are:-
Width and Height
Vspace and Hspace
Align
Setting border around an image
Use Border attributes
Alt attribute
It specify an alternate text for an image.

You might also like