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 the binary operator(+) overloading without creating a new object

  2. Program to solve the Towers of Hanoi Problem (using Recursive Algorithm)

  3. Program to construct and display the Divided Difference Table from the given distinct data points.

  4. Program that are completely portable across different operating systems

  5. Program to implement Add and Subtract function on Big Number Class

  6. Program that reads an expression consisting of two non-negative integer and an operator. Determine if either integer or the result of the expres......

  7. Program to illustrate the implementation of Reflection Transformation about the line y=x and y=-x

  8. Program to construct Natural Cubic Spline Interpolant from the given data

  9. Program to add two integers without using + operator

  10. Program of Line clipping by Cohen Sutherland

  11. Program that take font and background color and text input from a user and display it in center aligned

  12. PROGRAM THAT PROVIDES AN EXAMPLE OF GETLINE FUNCTION

  13. Program to illustrate object initialization and assignment by default member wise copy

  14. Program that provides facilities of calculator in c++

  15. Program to illustrate the implementation of arrays as a Stack in graphics

  16. Program of Midpoint Circle Drawing

  17. Program to draw a 3D Bezier Surface for MxN control points

  18. Program to read a Non-Linear equation in one variable, then evaluate it using Secant Method and display its kD accurate root

  19. Write a program to read value from console and perform arithmetic operation

  20. Program of singly link list with different functionalities

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