Course Content
Programming Language C Plus Plus
About Lesson

Syntax of class and object with example

C
#include<iostream.h>
#include<conio.h>
class Rect
{
  private:
  int l,b;
  public:
  void input()
  {
     cout<<"\n enter l and b";
     cin>>l>>b;
  }
  void output()
  {
    cout<<"\n Rect Dimension is "<<l<<"x"<<b;
  }
  void area()
  {
    int a;
    a=l*b;
    cout<<"\n  Rect Area ="<<a;
  }
};
void main()
{
  //array of objects
  Rect r1;
  Rect r2;
  clrscr();
  r1.input();
  r1.output();
  r1.area();
  getch();
}

/*
Box - l, b, h
input output
vol area

*/
C
/*
Array of Objects
*/
#include<iostream>
using namespace std;

class Rect
{
   private:
    int l,b;
   public:
    void input()
    {
      cout<<"\nenter Len and Bre of Rect";
      cin>>l>>b;
    }
    void output()
    {
     cout<<"\n Rect dimesion is "<<l<<"x"<<b;
    }
    int Area()
    {
     return l*b;
    }
};
int main()
{
  Rect r[3]; // Array of Rect Object
  int i;
  clrscr();
  for(i=0;i<3;i++)
  {
    cout<<"\n enter Rect"<<i+1<<" object Len and Bre";
    r[i].input();
  }
  cout<<"\n Output is ";
  for(i=0;i<3;i++)
  {

    r[i].output();
  }
  
}
/*
Box  L, B, H
input()
output()
area ()
vol()

Student
rollno, name, H, E, M , SCI, SST, Total, Per

input

output

5 students data input and display

*/
C
/*
In Line Vs Non Inline
*/
#include<IOSTREAM>
using namespace std;
class Demo
{
    public:
    void msg()
    {
        cout<<"\n Welcome to Inline function";
        cout<<"\nWhen we define a function inside the class it is called inline function";
    }
    //Non Inline - declare a function inside the class and define a function outside the class
    void fun(); // declare

};
// define the function outside the class
void Demo::fun()
{
    cout<<"\n Fun function is non inline function";
}
int main()
{
    Demo d1;
    d1.msg(); // inline function calling
    // when we call the inline function then body of function inserted at calling place
    d1.fun(); // non inline function
    //when we call the non inline function the control goes to called  function and after work it come back to calling function

    // inline function expension of code not allowed 
}