C++ Programming Tutorial

 
 
 

Object Oriented Programming

Structures

Example of structures Passing structures to function Passing structure pointers to function Pointers and an array of structure Relationship between union and structure Array of structure Nested structures Self-referential structures Linked List

Classes

Classes with inline functions Classes without using inline functions Example of constructor in classes Passing values to constructor in classes Overloading of constructors in classes Example of destructor in classes Example of static class data Example of static member functions Constant objects, constant member functions Strings as member of classes Use of arrays as data items in classes Example of array of objects in classes Use of pointer this using header file this.h Obj initialize, assign by default member wise copy

Inheritance - Containership

Example of Inheritance Over riding base class member fn in derived Diff in public, protected, private inheritance Multi-level inheritance Multiple inheritance Example of containership

Virtual Functions - Polymorphism

Example of Polymorphism Example of Pure Virtual functions

Operator Overloading - Type Casting

Increment operator ++ overloading w/o return type Increment operator ++ overloading - return type Decrement operator -- overloading w/o return type Decrement operator -- overloading - return type Operator overloading for strings Comparision operator < overloading Binary operator + overloading creating new object Binary operator + overloading w/o creating object Binary operator - overloading creating object Binary operator - overloading w/o creating object Binary operator * overloading w/o creating object Stream insertion >> , extraction << operators Data conversion b/w built-in data types Data conversion - built-in, user defined data type Conversion- built-in, user defined data type- char Data conversion user defined data type - function Conversion user defined data type - constructor

Friend Functions and Classes

Use of friend functions Use of friend classes Operator overloading using friend function All Operator overloading using friend function Addition of 2 matrix using friend function Example of friend function of a class

Template Functions and Classes

Interchange value using function template Example of template classes Template based array input Template to find minimum value in an array Template of vector class

File Processing - Command Line Arguments

Open file File operation program - diff type of mode Read from one text file, writing in new text file File read, write, update and display operations Read decimal from file - convert into hexadecimal Read words from file and remove palindrome Read device data from text file and show extension Example of binary files

General Programs

Number of days b/w two given dates Capitalize first charcter of every word in string Copy n num of characters from one to another Word is palindrome or not using classes & pointers Simulation of the Solar System Add and Subtract functions on Big Number Class
 
 
 #include<iostream.h>
 #include<conio.h>

 const int max=20;


 //------------------------------  stack  --------------------------------//


 template <class T>

 class stack
    {
       private:
        T stk[max];

        int top;

       public:
        stack()  { top=-1; }
        void push(T);
        T pop();
    };


 //---------------------------  complex  ---------------------------------//


 class complex
    {
       private:
        float real_part;
        float imaginary_part;

       public:
        complex()  { real_part=0.0;  imaginary_part=0.0; }
        complex(float r,float i)  { real_part=r; imaginary_part=i; }
        friend ostream &operator<<(ostream &o,complex &c);
    };




 //---------------------------   push(T)  --------------------------------//


 template <class T>
 void stack<T>::push(T data)
    {
       if(top==max-1)
      cout<<\"\\n Stack is full \"<<endl;

       else
      {
         top++;
         stk[top]=data;
      }
    }


 //----------------------------   pop(T)  --------------------------------//


 template <class T>
 T stack<T>::pop()
    {
       T item;


       if(top==-1)
         cout<<\"\\n Stack is empty \"<<endl;

       else
      {
         T item=stk[top];

         top--;
      }

       return item;
    }



 //---------------------------  complex  ---------------------------------//




 //----------------   &operator<<(ostream &,complex &)  ------------------//


 ostream &operator<<(ostream &o,complex &c)
    {
       o<<\"\\n\\t Real Part = \"<<c.real_part<<\"\\t Imaginary Part = \"<<
                             c.imaginary_part<<endl;
       return o;
    }

 main()
    {
       clrscr();


       cout<<\"\\n **********  Integers  ********\"<<endl;

       stack<int> s_1;

       s_1.push(10);
       s_1.push(20);
       s_1.push(30);

       cout<<s_1.pop()<<endl;
       cout<<s_1.pop()<<endl;
       cout<<s_1.pop()<<endl;

       cout<<\"\\n **********  Floats  ********\"<<endl;

       stack<float> s_2;

       s_2.push(1.1);
       s_2.push(2.2);
       s_2.push(3.3);

       cout<<s_2.pop()<<endl;
       cout<<s_2.pop()<<endl;
       cout<<s_2.pop()<<endl;

       cout<<\"\\n **********  Complex Numbers  ********\"<<endl;

       complex c_1(1.5,2.5);
       complex c_2(2.5,3.5);
       complex c_3(3.5,4.5);

       stack<complex> s_3;

       s_3.push(c_1);
       s_3.push(c_2);
       s_3.push(c_3);

       cout<<s_3.pop()<<endl;
       cout<<s_3.pop()<<endl;
       cout<<s_3.pop()<<endl;

       getch();
       return 0;
    }

    Related Post:
  1. Program to illustrate adding values to the contents of variables whose addresses are in pointers

  2. Program that provides an example of passing objects to function using call by reference method

  3. Program that reads a number and displays it with its digits in reverse order (using while loop)

  4. Program to read n integers and add them up and output the result

  5. Program that provides example of dynamic constructor

  6. Program to illustrate an example of Polymorphism ( Pure Virtual functions ).

  7. Program that displays result of students by compact if-else notation

  8. Program that takes input of students and result obtained, based on that provides rank

  9. Program to illustrate the overloading of constructors in classes

  10. Program which read device data from a text file and show each extension\’s dues

  11. Program of that provides an example of function overloading

  12. Program of Deterministic Finite Automation (DFA) for identifier, real number with optional Integer and Fractional Part

  13. Program that prints odd numbers form 0 to 50 (Using for Loop)

  14. Program to display string triangle

  15. Program to show the use of Bitwise Operator Left Shift ( &lt;&lt; )

  16. Program to estimate the Differential value of the function at the given point from the given data using Mid-Point Method

  17. Program to maintain employee information also illustrate virtual class and inheritance

  18. Program to illustrate the implementation of X-Direction Shear Transformation

  19. Program to illustrate the use of call-by-refrence method using pointers

  20. Program to addition of two polynomial

 
 
Didn't find what you were looking for? Find more on Program to illustrate template classes