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<graphics.h>
 #include<stdlib.h>
 #include<conio.h>
 #include<dos.h>


 //------------------------------  rect  ---------------------------------//


 class rect
    {
       public:
        void draw_rect(int,int,int,int,int);
    };


 //----------------------------  fill_rect  ------------------------------//


 class fill_rect:public rect
    {
       public:
        void draw_rect(int,int,int,int,int,int,int);
    };


 //---------------------------  animate_rect  ----------------------------//


 class animate_rect:public fill_rect
    {
       public:
        void draw_rect(int,int,int,int,int,int,int);
    };


 //----------------  draw_rect(int,int,int,int,int)  ---------------------//


 void rect::draw_rect(int x1,int y1,int x2,int y2,int boundry_color)
    {
       setcolor(boundry_color);
       rectangle(x1,y1,x2,y2);
    }



 //------------  draw_rect(int,int,int,int,int,int,int)  -----------------//


 void fill_rect::draw_rect(int x1,int y1,int x2,int y2,int boundry_color,
                        int pattern,int pattern_color)
    {
       rect::draw_rect(x1,y1,x2,y2,boundry_color);

       struct fillsettingstype t;

       getfillsettings(&t);

       setfillstyle(pattern,pattern_color);
       floodfill(x1+1,y1+1,boundry_color);
       setfillstyle(t.pattern,t.color);
    }



 //-------------  draw_rect(int,int,int,int,int,int,int)  ----------------//


 void animate_rect::draw_rect(int x1,int y1,int x2,int y2,int boundry_color,
                        int pattern,int pattern_color)
    {
       fill_rect::draw_rect(x1,y1,x2,y2,boundry_color,pattern,pattern_color);

       int size=imagesize(x1,y1,x2,y2);

       char *p;

       p=new char[size];

       getimage(x1,y1,x2,y2,p);
       putimage(x1+100,y1+100,p,XOR_PUT);

       int x;
       int y;

       while(!kbhit())
      {
         x=random(getmaxx());
         y=y2+random(getmaxy());

         putimage(x,y,p,OR_PUT);
         delay(100);
         putimage(x,y,p,XOR_PUT);
      }
    }


 main()
    {
       clrscr();

       int graphic_driver=DETECT;
       int graphic_mode;
       int errorcode;

       initgraph(&graphic_driver,&graphic_mode,\"..\\\\bgi\");

       errorcode=graphresult();

       if(errorcode!=grOk)
      {
         restorecrtmode();
         cout<<\"Graphic Error\";
         exit(1);
      }

       rect x;

       x.draw_rect(20,20,150,150,4);

       fill_rect y;

       y.draw_rect(210,20,350,100,14,1,13);

       animate_rect z;

       z.draw_rect(400,20,530,100,14,7,10);

       getch();
       closegraph();
       return 0;
    }

    Related Post:
  1. Program to draw an Elliptical Arc using Trigonometric Method

  2. PROGRAM TO IMPLEMENT RECURSIVE DESCENT PARSER

  3. Program to illusrate data conversion b/w built-in data types and user defined data types(in char)

  4. Program for Operator Overloading and Friend Function concept

  5. Program to illustrate the implementation of 3D Rotation Transformation along y-axis

  6. Program to implement a Translator that reads an Infix Expression translates it into a Postfix Expression and evaluate the Postfix Expression

  7. Program to print a diamond

  8. Program for electricity board charges calculation

  9. Program to draw a line using Bresenhams Line Algorithm (BLA) for lines with slopes negative and less than 1

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

  11. Program to show the projection of 3D objects using Cabinet Oblique Parallel Projection onto xy-plane (i.e. angle=30 deg)

  12. Program that takes input of 2 matrix rows and columns data and displays addition of it using + operator overloading

  13. Program to computes the product of two matrices of size 4x4 using Divide and Conquer Strategy

  14. PROGRAM OF BASIC TO CLASS CONVERSION

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

  16. Program to display string triangle

  17. Program to illustrate the Quick Sort

  18. Program to estimate the Integral value of the function at the given points from the given data using Trapezoidal Rule

  19. Program that provides an example of return by reference from functions

  20. Program of bubble sort

 
 
Didn't find what you were looking for? Find more on Program to illustrate the multi-level inheritance