C++ Programming Tutorial


Object Oriented Programming


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 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



 //----------------------------  distance  -------------------------------//

 class distance
        int feet;
        float inches;

        distance()  { feet=0,inches=0.0; }
        distance(int ft,float inch)  { feet=ft,inches=inch; }
        distance operator -(distance);
        void get_distance();
        void show_distance()
            { cout<<feet<<\"f - \"<<inches<<\"\'\"<<endl; }

 //---------------------------  get_distance( )  -------------------------//

 void distance::get_distance()
       cout<<\"\\t Enter the feet = \";

       cout<<\"\\t Enter the inches = \";

 //------------------------  operator-(distance)  ------------------------//

 distance distance::operator-(distance d1)
       distance r;

       r.feet = feet-d1.feet;
       r.inches =inches-d1.inches;

       if(r.inches <=0)

       return r;

 main( )

       distance d_1;
       distance d_2(2,2.2);
       distance d_3;
       distance d_4;

       cout<<\"\\n Enter the value of d_1 : \"<<endl;


       cout<<\"\\n Value of d_1 = \";

       cout<<\"\\n Value of d_2 = \";

       cout<<\"\\n Value of d_3 = \";

       cout<<\"\\n Value of d_4 = \";

       return 0;

    Related Post:
  1. Program to compute and print out the decimal notation for the reciprocal of each input integer

  2. Program to add two integers without using + operator

  3. Program to draw a line using Cartesian Slope-Intercept Equation [ Simple Implementation ]

  4. Program of declaration of default arguments during creation of function

  5. Program to illustrate the binary operator(*) overloading without creating a new object

  6. Program of traversing a binary tree in inorder iteratively

  7. Program that computes the n_th term of the fibonacci series and also print the series upto the n_th term using recursion

  8. Program to create heap

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

  10. Program to read 2D array and display it row by row and its sum

  11. Program to draw an ellipse using MidPoint Ellipse Algorithm

  12. Program of traversing a binary tree in inorder, preorder and postorder fashion

  13. Program to illustrate adding values to the contents of variables whose addresses are in pointers

  14. Program that provides an example of class

  15. Problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs

  16. Program to display bill receipt based on customer information and create telephone directory

  17. Program to estimate the value of First Derivative of the function at the given points from the given data using Central Difference Formula

  18. Program to illustrate operator overloading for strings

  19. Program to illustrate an array of structure

  20. Program that reads two integers and an operator , evaluates and displays the result using switch-case statement