Variable, Datatype, Pointer, Operator & Conditional, etc..

   
     //general purpose programming language
     //it was designed by Bjarne Stroustrup
     //in 1979 at Bell Labs
     //initial time c++ is called as C with Class.
     
     #include <iostream>
     using namespace std;
     
     //Compiler version g++ 6.3.0
     int a=10;
     
     int main()
     {
     /******** Variable **********/
     //it is a simple name which use to store any value in memory space.
     //name="Haresh";
     
     /******** Data Type **********/
     //it specifies the type of data and size of data you want to
     // store or used there.
     /*             .
               .    .   . 
             .      .      .
     Fundamental  Derived  UserDefine
     int          Array    Class
     char         String   Structure
     float        Pointer  Union
     bool         Reference 
     double       Function
     long
     short  
     
     */  
     /* int a=1288888;
     char letter='Z';
     float score=16.8999;
     double num=145.88888888;
     long b=188888888888888888;
     short c=1;
     cout<<c;
     */
     
     /******** Type Conversion **********/
     //when we convert a variable of one  data type to 
     //an other data type that is called This.
     
     //internal
     /*float a=1;
     char b='Ha';
     bool c=-1;
     cout<<a<<" "<<b<<" "<<c;
     */
     //External
     /*
     float a=1.888;
     int sum=(int)a+5;
     cout<<sum;
     */
     
     /******** Pointers && References **********/       
     // a pointer is a variable which points another.
     //it mean pointer use to store address of any variable.
     //Reference refer address.
     /*  int a=5;
     int *ptr=&a; 
     int **ptrr=&ptr;
     cout<<ptr<<" / "<<&a<<" / "<<*ptr<<"/ "<<ptrr<<"/ "<<**ptrr; */
     
     /******** Input and Output **********/       
     //input and output functions are in STD library <iostream>
     /*cout<<"hello"<<endl;
     int a;
     cin>>a; 
     cout<<a<<endl;   */
     
     /******** Operators **********/  
     // an operator is a symble which used to perform operation 
     //between one or two operands. 
     /*               .
                .   . . .    .
          .        .  .   .       .
       .          .    .      .          .
     Arithmetic  Assig- Compa- Logical   Other
     -ment  -rsion
     +           =     ==      &&       ::
     -           +=    !=      ||       endl
     *           -=    >       !        sizeof()
     /           *=    <                ()?():();
     %           /=    >=
     ++          %=    <=
     --       
     
     T&&F=F
     F&&F=F
     !T=F
     */
     
     /*{
     int a=5;
     cout<< ::a <<endl;
     cout<<sizeof(a)<<endl;
     }
     cout<< a;   
     */   
     
     /******** Conditional **********/  
     // it use to exicute some code on the
     //base of codition satisfies or not.
     /*           .
                  .
         .        .        .
     
     if-else | else if  | Nested if 
     
     if(){}  | if(){}   |  if(){ if(){}
     else{}  | else if()|        else{} }
             |  {}      |  else{ if(){}
             | else{}   |        else{} }
     */ 
     /*  int a=8; 
     if(a>6){
     cout<<"5>6";
     }
     else{
     cout<<"5<6";
     }*/
     /*  int num1,num2;
     cout<<"Enter a and b number: ";
     cin>>num1>>num2;
     
     if(num1>num2){
     cout<<"big is: "<<num1;
     } 
     else if(num2>num1){
     cout<<"big is: "<<num2;
     }
     else{
     cout<&num1<<"="<<num2;
     } */
     /*int mark;
     cout<<"Enter your marks: ";
     cin >> mark;
     if(30<=mark){
     if(60<=mark){
     cout<<"1st";
     }
     else{
     cout<<"pass";
     }
     }
     else{
     cout<<"Fail";
     }
     */
     
     
     
     // cout<<"Haresh";  
     return 0;
     }
   
  

Loop, Function, Array, Recursion & String..

   
     #include <iostream>
     using namespace std;
     
     //Compiler version g++ 6.3.0
     void pow(int a, int b){
     int res=1;
     for(int i=1; i<=b; i++){
     res=res*a;
     }
     cout<<res;
     }
     
     //find the factorial of any number let number 4
     /* 4*3*2*1
     ==> 4*factorial of 3 */
     int fact(int f){
     if(f==1||f==0){
     return 1;
     }
     return f*fact(f-1);
     }
     
     int main()
     {
     // loop -> a block of code which repete again again 
     /*for(int i=0; i<5; i=i+1){
     cout<<i<<endl;
     }*/
     
     /* int i=0;
     while(i<5){
     cout<<"Haresh"<<endl;
     i++;
     }*/
     /* int i=1;
     do{
     cout<<i<<" ";
     i+=1;
     }while(i<5);
     */
     
     //GAME
     //
     /*int org=4;
     int key;
     int count=0;
     cout<<"Enter any number between 1 to 10";
     while(cin>>key){
     count++;
     if(key==org){
     cout<<"Congratulations."<<endl;
     cout<<count;
     }
     } */
     
     //Function
     //pow(6,2);
     
     //Recursion
     //if any func call it self in side it body.
     //cout<<fact(5);
     
     //Array
     /*int n=5;
     int *arr= new int(5);
     arr[0]=2;
     arr[1]=3;
     arr[2]=5;
     //cout<<length;
     for(int i=0; i<5; i++){
     cout<<arr[i];
     }*/
     
     //String Data type 
     /*string UN;
     cout<<"Enter userid"<<endl;
     cin>>UN;
     cout<<"Your user Id: "<<UN;*/
     /*   string str;
     getline(cin, str);
     cout<<str.empty();
     cout<<str.size();
     cout<<str;*/
     /*string str1="Haresh";
     string str2="zee";
     str1= str1+str2;
     cout<<str1;*/
     
     }
   
  

Class, Object, Constructor & Destructor..

  
   #include <iostream>
   using namespace std;
   
   //Compiler version g++ 6.3.0
   class val{
   public:
   int a,b;
   val(){ //default constructor 
   a=15;
   b=18;
   }
   val(int a, int b){ //parameterised constructor 
   this->a=a;
   this->b=b;
   }
   val(val &r){//copy constructor 
   a=r.a;
   b=r.b;
   }
   ~val(){
   cout<<"destructor called"<<endl;
   }
   }
   int main()
   {
   val v1,*v2=new val();
   v1.a=5;
   v1.b=8;
   cout<<v1.a<<" & "<<v1.b<<endl;
   //cout<<v2->a<<" & "<<v2->b<<endl; 
   //delete v2;
   val v3(35,38);
   cout<<v3.a<<" & "<<v3.b<<endl;
   val *v4=new val(25,28);
   cout<<v4->a<<" & "<<v4->b<<endl;
   val v5=v3;
   cout<<v5.a<<" & "<<v5.b<<endl;
   }
  
 

Encapsulation

  
   #include <iostream>
   using namespace std;
   
   //Compiler version g++ 6.3.0
   class pas{
   int pw;
   public:
   void set(int n){
   pw=n;
   }
   void get(){
   cout<<"Password 🔑 is "<<pw<<endl;
   }
   };
   int main()
   {
   pas p1, p2;
   p1.set(738187);
   p1.get();
   p2.set(787314);
   p2.get();
   }
  
 

Friend Class & Function..

   
    #include <iostream>
    using namespace std;
    
    //Compiler version g++ 6.3.0
    class A{
    int x;
    public:
    A(int x){
    this->x=x;
    }
    //void lala();
    friend void print(A &obj);
    };
    void print(A &obj){
    cout<<obj.x<<endl;
    }
    /*void A::lala(){
    cout<<x;
    }*/
    int main()
    {
    A o(10);
    print(o);
    //o.lala();
    
    }
     // next
     
    class A{
    private:
    int pvt;
    protected:
    int ptc;
    public:
    friend class F;
    };
    
    class F{
    public:
    void put(A &obj){
    cout<<"Enter two values.";
    cin>>obj.pvt;
    cin>>obj.ptc;
    }
    void get(A &obj){
    cout<<"private value: "<<obj.pvt<<endl;
    cout<<"protected value: "<<obj.ptc;
    }
    };
    
    int main()
    {
    A o;
    F o2;
    o2.put(o);
    o2.get(o);
    
    }
   
  

Inheritance..

   
    #include <iostream>
    using namespace std;
    
    //Compiler version g++ 6.3.0
    
    /*********** Single Inheritance 😉 ***********/
    class perent{
    public:
    perent(){
    cout<<"Now in perent class."<<endl;
    }
    };
    class child: public perent{
    public:
    child(){
    cout<<"Now in child class"<<endl;
    }
    }; 
    
    /*********** Multiple Inheritance 😉 ***********/
    class perent1{
    public:
    perent1(){
    cout<<"Class Perent1."<<endl;
    }
    };
    class perent2{
    public:
    perent2(){
    cout<<"Class Perent2."<<endl;
    }
    };
    class children: public perent1, public perent2{
    public:
    children(){
    cout<<"Class Children."<<endl;
    }
    };
    
    
    /*********** Multilevel Inheritance 😉 ***********/
    class grandfather{
    public :
    grandfather(){
    cout << "Grandpa class."<<endl;
    }
    };
    class father:public grandfather {
    public:
    father(){
    cout<< "Father class."<<endl;
    }
    };
    class son:public father{
    public:
    son(){
    cout<<"Son class."<<endl;
    }
    };
    
    /*********** Hierarchical Inheritance 😉 ***********/
    class mother{
    public:
    mother(){
    cout<<"mother class."<<endl;
    }
    };
    class son1:public mother{
    public:
    son1(){
    cout<<"Son 1 class."<<endl;
    }
    };
    class son2:public mother{
    public:
    son2(){
    cout<<"Son 2 class."<<endl;
    }
    };
    
    
    /*********** Hybrid Inheritance 😉 ***********/
    class grandpa{
    public:
    grandpa(){
    cout<<"grandpa class"<<endl;
    }
    };
    class bigpapa: public grandpa{
    public:
    bigpapa(){
    cout<<"bigpapa class "<<endl;
    }
    };
    class papa:public grandpa{
    public:
    papa(){
    cout<<"papa class "<<endl;
    }
    };
    class putra:public papa{
    public:
    putra(){
    cout<<"putra class "<<endl;
    }
    };
    
    int main()
    {
    
    child o1;
    
    children o2;
    
    son o3;
    
    son1 o4;
    son2 o5;
    
    putra o6;
    }
   
  

Polymerphism..

   
    #include<iostream>
    using namespace std;
    
    //Operator Overloading
    /*class a{
    public:
    int x;
    a(int x){
    this->x=x;
    }
    void operator++(){
    x=x-1;
    } 
    };
    
    int main()
    {
    int x=8;
    a obj(x);
    cout <<obj.x<<endl;
    ++obj;
    cout <<obj.x<<endl;
    ++obj;
    cout <<obj.x<<endl;
    }*/
    class a{
    public:
    int x;
    int operator/(a &obj){
    return (this->x)-(obj.x);
    }
    };
    int main(){
    a o;
    o.x=10;
    a o1;
    o1.x=5;
    int r= o/o1;
    cout<<r;
    }
    
    // Function Overloading
    void add(int a, int b)
    {
    cout << "sum = " << (a + b);
    }
    
    void add(int a, int b, int c)
    {
    cout << endl << "sum = " << (a + b + c);
    }
    
    // Driver code
    int main()
    {
    add(10, 2);
    add(5, 6, 4);
    
    return 0;
    }