22 Nov 2019

  • November 22, 2019
  • Amitraj
Class:-
-> Language supports different data type like int, float, char, long, structure etc. Similar to that C++ supports class data type.

-> A class is a user defined data type which has data members and member functions. They can be accessed through class variables (objects).

-> A class is like a Blue print for an object.

-> By default, All members in the class are Private.

For Ex:
Fruit is a class.
Then mango, orange will be objects of class.



Objects

-> Class type variable is known as object.
->  An object is an instance of a class.
-> Objects are basic runtime entities in an object oriented system.
-> In Structured programming problem is divided into function unlike this, in OOPs the problem is divided into objects.




// C++ program using class to calculate Area.

#include<iostream>
using namespace std;
class  shape
{
      private:
                      int l,b,area;
      public:
                     void input()
      {
              cout<<"Enter l and b values:";
               cin>>l>>b;
       }
void calculate()
{
         area = l*b;
}
void output()
{
        cout<<"Area is:"<<area;
}
};
int main()
{
      shape s;
      s.input();
      s.calculate();
      s.output();
      return 0;
}

OUTPUT:

Enter l and b values:6    5
Area is:30


*Abstraction using classes: An abstraction can be achieved using classes. A class is used to group all the data members and member functions into a single unit by using the access specifiers. A class has the responsibility to determine which data member is to be visible outside and which is not.



Related Posts:

  • Hierarchical - Inheritance in C++ 4.)  Hierarchical - Inheritance  Inheritance is the process of inheriting properties of objects of one class by objects of another class. The class which inherits the properties of another class is called Derived… Read More
  • Single inheritance in C++ 1.) single inheritance -> A derived class with only one base class, is known as single inheritance. -> When a single class is derived from a single parent class, it is called Single inheritance. It is the simplest o… Read More
  • multilevel Inheritance in C++ 3.)  Multilevel - Inheritance *In this type of inheritance, a derived class is created from another derived class.      *If a class is derived from another derived class then it is called multilevel inh… Read More
  • multiple inheritance in C++ 2.) multiple inheritance Multiple inheritance occurs when a class inherits from more than one base class. So the class can inherit features from multiple base classes using multiple inheritance. This is an important… Read More
  • Inheritance in C++ Inheritance in C++ 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… Read More

Translate

Popular Posts