Classes in C++ : An object oriented programming approach is a collection of objects and each object consists of corresponding data structures and procedures. The program is reusable and more maintainable. The important aspect in object oriented programming is a class which has similar syntax that of structure.
It is a collection of data and member functions that manipulate data. The data components of class are called data members and functions that manipulate the data are called member functions. It can also called as blue print or prototype that defines the variables and functions common to all objects of certain kind. It is also known as user defined data type or ADT(abstract data type) A class is declared by the keyword class.
Syntax for declaring a classes in c++ is:
class class_name
{
Access specifier:
variable;
statement;
}
Example :
class
{
public:
int length,breadth,height;
int calculate_area ()
{
int a = length * breadth;
return a;
}
double Calculate_Volume()
{
double b = length * breadth * height;
return b;
}
};
Here we have defined a class with name Rom. In this the variable declared are length breadth and height which are known as data member. And calculate_area and Calculate_Volume are the data function of a class.
Pingback: Unconditional control statement in C++ - AskAtul.com
Pingback: Object's in C++ - AskAtul.com