Simple program to create various types of constructor in one class

Saturday, December 12, 2015 Unknown 0 Comments


Simple Program To Create Various Types Of Constructor In One Class

#include<iostream.h>
#include<conio.h>
class ABC
{
        int a,b;
        char *str;
        public:
        ABC()                      //Default Constructor...
       {
               a=0;
               b=0;
               cout<<"A = "<<a<<"\tB = "<<b<<endl;
        }
        ABC(int x,int y)               //Parameterized Constructor
        {
               a=x;
               b=y;
               cout<<"A = "<<a<<"\tB = "<<b<<endl;
         }
         ABC(ABC &i)               //Copy Constructor
         {
                a=i.a;
                b=i.b;
               cout<<"A = "<<a<<"\tB = "<<b<<endl;
          }
         ABC(char s[])                  //Dynamic Constructor
         {
                 int n=strlen(s);
                 char *str=new char[n];
                 strcpy(str,s);
                 cout<<"your string is "<<str;
          }
};
void main()
{
      ABC A1;
      ABC A2(10,20);
      ABC A3(&A2);
      ABC A4("CPP");
      clrscr();
      getch();
}

OUTPUT:-
A = 0     B = 0
A = 10    B = 20
A = 10    B = 20
your string is CPP



To know about god and godly university pllease click here  www.pbks.info

0 comments:

Swap value of data member of class using friend function

Thursday, November 05, 2015 Unknown 2 Comments


Swap two value of two classes using friend function

  • Description :
                Friend function access private data of class so we can use friend function as bridge between two classes.

#include<iostream.h>
#include<conio.h>
class B;
class A
{
        int a;
        public:
        void getA()
        {
             cout<<"enter value of A : ";
             cin>>a;
        }
        friend void swap(A &,B &);
};
class B
{
         int b;
         public:
         void getB()
         {
                 cout<<"enter value of B : ";
                 cin>>b;
         }
         friend void swap(A &,B &);
};
void swap(A &a1,B &b1)
{
          int temp;
          temp=a1.a;
          a1.a=b1.b;
          b1.b=temp;
          cout<<"A = "<<a1.a;
          cout<<"B = "<<b1.b;
}

void main()
{
         A a1;
         B b1;
         a1.getA();
         b1.getB();
         swap(&a1,b1);
         getch();
}


OUTPUT:-
enter value of A : 10
enter value of B : 20
A = 20
B = 10
To know about God and Godly University please click here : www.pbks.info

2 comments:

Create friend function in class

Friday, October 23, 2015 Unknown 0 Comments


To create freind function of class

  • Definition:-
            Friend function is non-member function of class but still that access the private data of that class.

Friend function is declared in class but it not necessary object of class to call it call without object like simple functions.


#include<iostream.h>
#include<conio.h>
class ABC
{
        int a;
        Public:
        void get()
        {
               cout<<"enter value of A : ";
               cin>>a;
        }
        friend void show(ABC &);
};
void show(ABC &i)
{
      cout<<"A = "<<i.a;
}
void main()
{
       ABC A1;
       A1.get();
       show(&A1);
       getch();
}


OUTPUT:-
enter value of A : 10
A = 10

         

To know about God and Godly University please click here : www.pbks.info

0 comments:

Simple hybrid inheritance

Thursday, October 22, 2015 Unknown 0 Comments

To create simple hybrid inheritance...

  • Definition:-
          Combination of more than one inheritance is called hybrid inheritance.

  • Multiple and hybrid inheritance are also hybrid inheritance.

  • Here,in this program we combine hierarchical inheritance and multilevel inheritance...

#include<iostream.h>
#include<conio.h>
Class A
{
        public:
        void showA()
        {
                cout<<"It is class A";
        }
};
class B:public A
{
       public:
       void showB()
       {
              cout<<"It is class B";
       }
};
class C:public A
{
      public:
      void showC()
      {
              cout<<"It is class C";
      }
};
class D:public B
{
       public:
       void showD()
       {
               cout<<"It is class D";
       }
};
void main()
{
         D D1;
         C C1;
         C1.showA();
         C1.showB();
         D1.showA();
         D1.showB();
         D1.showD();
         getch();
}

OUTPUT:-
It is class A
It is class C
It is class A
It is class B
It is class D


To know about God and Godly University please click here : www.pbks.info        

0 comments:

simplest hierarchical inheritance

Monday, October 19, 2015 Unknown 2 Comments


To create Simple hierarchical inheritance...




  • Definition:-
                    More than one class derived from single base class called hierarchical inheritance.

#include<iostream.h>
#include<conio.h>
class A
{
        public:
        void showA()
        {
                cout<<"It is class A";
        }
};
class B:public A        //class B derived from class A....
{
        public:
        void showB()
        {
                cout<<"It is class B";
        }
};
class C:public A       //class C Also derived from class A...
{
        public:
        void show C()
        {
                cout<<"It is class C";
        }
};
void main()
{
          C C1;
          C1.showA();
          C1.showB();
          C1.showC();
          getch();
}


OUTPUT:-
It is class A
It is class B
It is class C

To know about God and Godly University please click here : www.pbks.info

2 comments:

simple multiple inheritance

Sunday, October 18, 2015 Unknown 0 Comments

To create simple multiple inheritance....

  • Definition:-
                     A derived class derived from more than one base class is called multiple inheritance.
                   Here, in example A and B are base class and C is derived from both classes.

#include<iostream.h>
#include<conio.h>
class A
{
         public:
         void showA()
         {
                 cout<<"It is class A";
         }
};
class B
{
          public:
          void showB()
          {
                   cout<<"It is class B";
          }
};
class C:public A,public B       //class c derived from class A and class B....
{
          public:
          void showC()
          {
                   cout<<"It is class C";
          }
};
void main()
{
          C C1;
          clrscr();
          C1.showA();
          C1.showB();
          C1.showC();
          getch();
}


OUTPUT :-It is class A
It is class B
It is class C

To know about God and Godly University please click here : www.pbks.info

0 comments:

simple multilevel inheritance

Sunday, October 18, 2015 Unknown 0 Comments


To create simple multilevel inheritance...


  • Definition:-
                 A class derived from already derived class is called multilevel inheritance.

#include<iostream.h>
#include<conio.h>
class A
{
      Public:
      void showA()
      {
            cout<<"It is class A";
      }  
};
class B:public A    //class b derived from class A....
{
         Public:
         void showB()
         {
                  cout<<"It is class B";
         }
};
class C:public B       //class C derived from derived class, class B....
{
          public:
          void showC()
          {
                  cout<<"It is class C";
          }
};
void main()
{
        C c1;
        c1.showA();
        c1.showB();
        c1.showC();
        getch();
}



OUTPUT:-It is class A
It is class B
It is class C

To know about God and Godly University please click here : www.pbks.info

0 comments:

Add two data member of class

Thursday, October 08, 2015 Unknown 0 Comments

Addition of two data member of class...

#include<iostream.h>
#include<conio.h>

class test    // class class_name
{
      Private:     //visibility mode that data only access by mathod of this class.......

         int a,b;

       public:    //it is another visibility mode that data also access by outside of class.....

             void getdata()         //method of class
             {
                       cout<<"enter value of A &B : ";
                       cin>>a>>b;
             }

             void sum()       //it is another mathod of class that sum two number......
             {
                      cout<<"Sum = "<<a+b;
             }
};

void main()
{
            test t1;        //create object of that class.....
             t1.getdata();      //call public mathod of class.....
             t1.sum();    
             getch();
}


OUTPUT:-enter value of A & B : 10 20
Sum = 30


To know about God and Godly University please click here : www.pbks.info

other programs.....
1.simple cpp program
2.simple class
3.add two numbers of class

show this all programs

0 comments:

Create simple class

Wednesday, October 07, 2015 Unknown 0 Comments


Make simple Class ...

#include<iostream.h>
#include<conio.h>

Class test
{
     int a,b;    //member variable of class. .
    public:     //public section of class
          void getdata()
          {
                  cout<<"enter value of A and B : ";
                  cin>>a>>b;
           }
          void showdata()
           {
                 cout<<"A = "<<a;
                 cout<<"B = "<<b;
            }
};
Void main()
{
       test t1; //t1 object of class test...
       Clrscr();
       t1.getdata();    //call mathod of class using object of that class.....
      t1.showdata();
       Getch();
}

OUTPUT:-enter value of A and B : 10 20
A : 10 B : 20



To know about God and Godly University please click here : www.pbks.info

other programs.....
1.simple cpp program
2.simple class
3.add two numbers of class
show this all programs

0 comments:

simple CPP program

Wednesday, October 07, 2015 Unknown 0 Comments


Simple CPP program to print hello world.

#include<iostream.h>
#include<conio.h>
Void main()
{
       Clrscr();
       cout<<"hello world";
       getch();
}

OUTPUT:-hello world


To know about God and Godly University please click here : www.pbks.info

other programs.....
1.simple cpp program
2.simple class
3.add two numbers of class
show this all programs

0 comments: