Members of a Class:
A class contains data items and functions. These are called members of the class. The data items are called data members and the functions arc called member functions.
Data Members:
The data items of a class are called data members of the class. For example, a class that has four integer type and two float type data items is declared as:
class abc
{
int w, x, y, z;
float a, b;
};
In the above class a, b, w, x. y and z are data members of the class “abc”.
Member Function:
The functions of a class that are defined to work on its data members are called member functions of the class. The member functions may be defined within the class or outside it.
For example:
class xyz
{
private:
int a, b, c;
public:
void get (void)
{
cout<< “Enter Value of a, b & c “;
cin >> a >> b >> c;
}
void pout (void)
{
cout << “a = “ << a << endl;
cout << “b =” << b << endl;
cout << “c =” << c << endl;
}
};
In the above class, there are three data members and two member functions. The member functions are “get” and “pout’. The “get” function is used to input values into data members a, b & c. The “pout” function is used to print values of the data members on the computer screen.
comment closed