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
 
 

Image

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

template <class T>
class vector
{
    T *arr;
    int size;

    public:

    vector() {
       arr=NULL;
       size=0;
    }

    vector(int m);
    vector(T *a,int n);
    void modify(T value,int index);
    void multiply(int scalarvalue);
    void display();
};

template <class T>
vector<T> :: vector(int m)
{
   size=m;
   arr = new T[size];
   for(int i=0;i<size;i++)
       arr[i]=0;
}

template <class T>
vector<T> :: vector(T *a,int n)
{
   size=n;
   arr = new T[size];
   for(int i=0;i<size;i++)
       arr[i]=a[i];
}


template <class T>
void vector<T> :: modify(T value,int index)
{
    arr[index]=value;
}


template <class T>
void vector<T> :: multiply(int scalarvalue)
{
    for(int i=0;i<size;i++)
       arr[i] = arr[i] * scalarvalue;
}

template <class T>
void vector<T> :: display()
{
    cout<<\"(\";
    for(int i=0;i<size;i++)
    {
        cout<<arr[i];
        if(i!=size-1)
           cout<<\", \";
    }
    cout<<\")\";
}


void main()
{
    clrscr();


    //Creating Integer Vector.
    int iarr[]={1,2,3,4,5};
    cout << \"Integer Values \\n\";
    for(int i=0; i < 5; i++)
    {
        cout << \"Enter integer value \"  << i+1 << \" : \";
        cin >> iarr[i];
    }
    vector <int> v1(iarr,5); //Integer array with 5 elements.
    cout<<\"\\nInteger Vector : \";
    v1.display();
    cout<<\"\\n\\nModify index 3 with value 15\\n\";
    v1.modify(15,3); //modifying index 3 with value 15.
    cout<<\"After Modification : \";
    v1.display();
    cout<<\"\\n\\nMultiply with scalar value : 10\\n\";
    v1.multiply(10); //Multiply with scalar value 10.
    cout<<\"After Multiplying : \";
    v1.display();
    cout<<\"\\n\\n\";


    //Creating double Vector.
    double darr[]={1.1,2.2,3.3,4.4,5.5};
    vector <double> v2(darr,5); //Double array with 5 elements.
    cout<<\"\\nDouble Vector : \";
    v2.display();
    cout<<\"\\n\\nModify index 0 with value 9.9 \\n\";
    v2.modify(9.9,0); //modifying index 0 with value 9.9.
    cout<<\"After Modification : \";
    v2.display();
    cout<<\"\\n\\nMultiply with scalar value : 10\\n\";
    v2.multiply(10); //Multiply with scalar value 10.
    cout<<\"After Multiplying : \";
    v2.display();
    cout<<\"\\n\\n\";

    getch();



}

    Related Post:
  1. Program to illustrate the Quick Sort

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

  3. Program to construct Newtons Divided Difference Interpolation Formula from the given distinct data points and estimate the value of the function

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

  5. Comment line in c

  6. Program to read a Linear System of Equations,then evaluate it by using Jacobis Itrative Method and show the result

  7. Program to get possible prime numbers like number 6158 contains the substrings 6, 1, 5, 8, 61, 15, 58, 615, 158, and 6158.Find the largest substring..

  8. Program for converting string to class object

  9. Program simulate the working of Pre-Processor

  10. Program that takes input of counter and displays output of incremented counter using overloading operator++

  11. Program to illustrate the use of default argument function

  12. Program that provides an example of scope resolution operator

  13. CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS

  14. Program to search an element in an array using Linear search

  15. Program to draw a spiral rotating clockwise at the center of the screen

  16. Program to perform operator overloading converting one class object to another

  17. Program that reads a number and displays it with its digits in reverse order using do-while loop

  18. Program for displaying data in tabular format

  19. Program that creats a 3D solid object using Rotational Sweep Representatiom Method

  20. Program to fill different types of geometric shapes using Boundary Fill Algorithm (Using Linked-List)