Let us Learn Computer Science
Dear Viewer, The blog contains notes and programmes based on Computer concepts and programming.
Search This Blog
Pages
'this' Pointer
'THIS' POINTER
In a class, when the objects are decalred, all the data mebers are allcoated separate memory to store their respective values while the member functions are allocated space for once only as shown illustrated by the fgure given below:
That is, multiple instances of the class member function do not exist. The functions work upon differnt set of values depending on the object through which the function is being invoked.
If member function 1 has to work with data memebr object 1 then how the function will identify that it has to process the value of object1 and not object2 or object3.
The situatio is being sorted with the use of 'this' pointer. when the object1 of class invokes fmember function1 or memberfunction2 then it automatically passes this pointer to the meber function.
'this ' is the variable that is avaailable in all the member functions of the class and it holds the address of the object that is invoking the non-static member function.
'this' pointer is not available in static member functions.
The use of this ponter may be understood with the following example:
#include<iostream.h>
class stud
{
int rno;
char sname[20];
float marks;
public:
void inp( int marks)
{ cout<<"\n enter roll number and name : ";
cin>>rno>>sname;
this->marks=marks; // marks is local parameter whereas
//this->marks is the marks of object calling the function.
}
void disp( )
{ cout<<"\n name : "<<sname;
cout<<"\n marks : "<<marks;
}
};
void main( )
{
int marks;
stud s;
cout<<"\n enter marks of the student ";
cin>>marks;
s.inp(marks);
s.disp( );
}
The use of this ponter may be understood with the following example:
#include<iostream.h>
class stud
{
int rno;
char sname[20];
float marks;
public:
void inp( int marks)
{ cout<<"\n enter roll number and name : ";
cin>>rno>>sname;
this->marks=marks; // marks is local parameter whereas
//this->marks is the marks of object calling the function.
}
void disp( )
{ cout<<"\n name : "<<sname;
cout<<"\n marks : "<<marks;
}
};
void main( )
{
int marks;
stud s;
cout<<"\n enter marks of the student ";
cin>>marks;
s.inp(marks);
s.disp( );
}
COMPUTER SCIENCE CLASS XII
COMPUTER SCIENCE
- INTRODUCTION TO C++
- ARRAYS
- SORTING : Sorting tecSorting is arranging the data elements in a particular order. The values in an array or list can either be arranged in ascending or descending order.Consider following list of integers as the marks obtained by 7 students in a test:3, 12, 6, 8, 5, 9, 15After sorting the list elements appear as :3, 5, 6, 8, 9, 12, 15we may easily find the highest marks and the range of marks in the above list. There are a number of ways to sort a given list of elements. Various algorithms have been devised to sort list of elements . Each sorting technique has its own effective approach depending on situation.
- SELECTION SORT
- INSERTION SORT
- STACKS
- QUEUES
Introduction to C++
Introduction to C++
C++ is an object oriented programming language developed by Bjarne Stroustrup at Bell laboratories.
An object oriented programming language focuses mainly on classes and objects.
Class : It is a group of objects with similar properties and behaviour.
The term ' class' is used to define the class in C++. Basically, class is a template which defines the structure of the class. For example : car is a class that has a state( Model, colour, engine, gear etc.)and behaviour (changing gear, speed, applying brakes etc.)
Let us have a look at the first program in C++
#include<iostream.h>
void main()
{
cout<<"\n HELLO";
}
Classes in programming :
Keyword 'class ' is used to define a class.
It is used like a template of Abstract Data Type.
It binds the data with the functions associated with it.
It is like a blueprint of the data type.
Networking notes
A computer network allows one computer to share/ exchange data with another computer.
or when a computer is able to share and exchange data with another computer they are said to be in a network.
Internet: Network of networks is called internet.
Intranet : It a network of networks among computers of same organization.
Extranet : Network of networks of some organisations.
Types of Network
PAN : Personal Area Network
This type of network if confnied within a metre or two.
LAN : Local Area Network
Area of network confined within 1-2 kilometers is called an LAN
MAN : Meropolitan Area Network
WAN : Wide Area Network
Topology : The pattern of arrangement of computers/ nodes in a network is called the topology.
A computer network allows one computer to share/ exchange data with another computer.
or when a computer is able to share and exchange data with another computer they are said to be in a network.
Internet: Network of networks is called internet.
Intranet : It a network of networks among computers of same organization.
Extranet : Network of networks of some organisations.
Types of Network
PAN : Personal Area Network
This type of network if confnied within a metre or two.
LAN : Local Area Network
Area of network confined within 1-2 kilometers is called an LAN
MAN : Meropolitan Area Network
WAN : Wide Area Network
Topology : The pattern of arrangement of computers/ nodes in a network is called the topology.
Subscribe to:
Posts (Atom)