C++ Programming Tutorial

 
 
 

Graphics Programming

Quadratic Surfaces

Draw a Sphere using Ellipses Draw a Sphere using Parametric Equations Draw an Ellipsoid using Parametric Equations

Character Generation

Urdu Alphabets using Stroke Method Urdu Alphabets using Matrix Method

Arc

Circular Arc using Trigo. Method Elliptical Arc using Trigo. Method

General Programs

C-Curve of nth order K-Curve of nth order Cubic Bezier Curve Bezier Curve of nth degree Scanfill algorithm Boundary Fill - 8 Connected Point Flood fill algorithm Rotate About Origin Rotate about reference point Scaling about origin Scaling about reference point Polyline translation Reflection in x axis Reflection in y Axis Reflection on any line Midpoint Circle Drawing Bresenhams Line Algorithm (BLA) Generate a pattern Draw a Chess Board Draw a Luddo Board Deterministic Finite Automation for identifier Kurskals algo - Minimum Cost Spanning Tree

Windows Programs

Checkbox like windows Simple windows & buttons Moving message box like windows Text box Graphical Rep. of tower of hanoi Graphical menu - operate it using arrow keys Text animation

Line

Line using Parametric equations Line-Cartesian Slope-Intercept Equation simple imp Line using Cartesian Slope-Intercept Equation Line - BLA - slopes negative and greater than 1 Line - BLA - slopes negative and less than 1 Line - BLA - slopes positive and greater than 1 Line - BLA - slopes positive and less than 1 DDA line drawing algorithm Bresenham line drawing algorithm Cohen sutherland Line clipping algo.

Line Styles

Different kinds of Dashed Lines Different kinds of Thick Lines

Polygons

Draw a Polygon Draw a Triangle Draw a Rectangle Sutherland-Hodgeman Polygon Clipping Algo

Circle

Circle using Trigo. Method Circle using Polynomial Method Circle using Bresenhams Circle algo. Circle using MidPoint Circle algo.

Ellipse

Ellipse using Polynomial Method Ellipse using Trigo. Method Ellipse using MidPoint Ellipse algo.

2D Transformations

Translation Transformation Scaling Transformation Scaling Trans along a Fixed Point Scaling Trans along Arbitrary Direction Rotation Transformation Rotation Trans along a Pivot Point Reflection tran of x-axix, y-axis and w.r.t origin Reflection tran of line y=x and y=-x X-Direction Shear Transformation Y-Direction Shear Transformation

2D Viewing - Clipping

Window-to-Viewport Coordinate Tran Point Clipping Algorithm Cohen-Sutherland Line Clipping Algo Cohen-Sutherland MidPoint Subdivision Line Nicol Lee Nicol algo. for Line Clipping Liang-Barsky Line Clipping Algo Window-to-Viewport Transformaton None-or-All String Clipping Strategy None-or-All Character Clipping Strategy

3D Object Representations

3D object using Polygon-Mesh Rep. 3D object - Translational Sweep Representatiom 3D object - Rotational Sweep Rep.

3D Transformations

3D Rotation Trans along x-axis 3D Rotation Trans along y-axis 3D Rotation Trans along z-axis 3D Reflection Trans along xy-plane 3D Reflection Trans along yz-plane 3D Reflection Trans along zx-plane 3D Shearing Trans along x-axis 3D Shearing Trans along y-axis 3D Shearing Trans along z-axis

Bezier Curves - Surfaces

3D Cubic Bezier Curve 3D Bezier Curve of nth degree 3D Piece-Wise Bezier Curve of nth degree 3D Bezier Surface for MxN control points

Projection

3D objects - Standard Perspective Projection 3D obj - Arbitrary Plane and Center of Projection 3D objects using General Perspective Projection 3D obj-Orthographics Proje Parallel onto xy-plane 3D obj-Cavalier Oblique Parallel prj-xy-plane 3D obj-Cabinet Oblique Parallel prj - xy-plane

Fill Algorithm or Area Filling

Geometric shapes using Boundary Geometric shapes - Boundary - Linked List Geometric shapes using Flood Geometric shapes - Flood - Linked-List Polygon using Scan Line Polygon Rectangle using Scan-Line Rectangle Circle using Scan-Line Circle Circle - Scan-Line Circle - Polar Coordinates
 
 
#include<iostream.h>
#include<conio.h>
#include <dos.h>
#include<graphics.h>


//Menu Global Item
#define pixTOrc(x) (8*(x-1))  //convert pixel into row and col format
#define INC 5  //Increment Distance Between Menu Items
#define ROW 15 //Row Value for Menu Item
#define COL 8 //Column Value for Menu Item
#define MAXITEM 4 //Total menu items

// To display the Inventory Main menu options
typedef char option[15];
option mainMenu[]= {
  \"NEW\",
  \"OPEN\",
 \"SAVE\",
 \"CLOSE\"
};



// Function to displays all the menu prompt messages from the pointer array of option a[]
void normalvideo(int x,int y,char *str)
{
    x=pixTOrc(x);
    y=pixTOrc(y);
    outtextxy(x,y,str);
}

// Function to move the cursor on the menu prompt with a reverse video color
void reversevideo(int x,int y,char *str)
{
    x=pixTOrc(x);
    y=pixTOrc(y);
    setcolor(YELLOW);  //Selected Item
    sound(400);
    delay(100);
    nosound();
    outtextxy(x,y,str);
    setcolor(WHITE); //Unselected Item
    sound(500);
    delay(100);
    nosound();
}


//Keep Track of which arrow key is pressed
char menu()
{
    settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
    setcolor(WHITE);  //Initial Menu Item Color
    int i,done;
    for(i = 1; i < MAXITEM; i++)
      normalvideo(COL, (i*INC)+ROW, mainMenu[i]);

    reversevideo(COL,ROW, mainMenu[0]);
    i = done = 0;
    do
    {
            /**Status Bar Logic**/
            //Message will be displayed as status bar guide-line
            setfillstyle(SOLID_FILL,BLUE);
            settextstyle(SMALL_FONT,HORIZ_DIR,5);
            bar(pixTOrc(2),pixTOrc(52.5),pixTOrc(75),pixTOrc(55));
            setcolor(LIGHTCYAN);
            switch(i){
                case 0 : outtextxy(pixTOrc(5),pixTOrc(52.75),\"New --> Create New file\");
                     break;
                case 1 : outtextxy(pixTOrc(5),pixTOrc(52.75),\"Open --> Open Existing file\");
                     break;
                case 2 : outtextxy(pixTOrc(5),pixTOrc(52.75),\"Save --> Save file\");
                     break;
                case 4 : outtextxy(pixTOrc(5),pixTOrc(52.75),\"Close the Program\");
                     break;
            }
            /**status Bar ends**/

             //Restore Orignal Color and Font Setting
             setcolor(WHITE);
            settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);

        int key = getch();
        switch (key)
        {

            case 00:
                key = getch();
                switch (key)
                {
                    case 72:
                        normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
                        i--;
                        if (i == -1)
                            i = MAXITEM-1;
                        reversevideo(COL,(i*INC)+ROW,mainMenu[i]);
                        break;
                    case 80:
                        normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
                        i++;
                        if (i == MAXITEM)
                            i = 0;
                        reversevideo(COL, (i*INC)+ROW, mainMenu[i]);
                        break;
                }
                break;
            case 13:
                done = 1;
        }
    }
    while (!done);
    return(i+49);
}


//Advertise Screen will displayed to utilize empty screen area
//It can be utilize for some effective...work
void advertise(){
    setcolor(BLUE);
    outtextxy(pixTOrc(30),pixTOrc(20),\"Syntax-Example.com\");
    setcolor(YELLOW);
}


/* The function is used to display the main menu*/
//Actual code for all the menu utility resides in this
//Function...
void control_menu()
{
     char choice;
    do
    {
        choice = menu();
        switch (choice)
        {
           case \'1\':    //New
                setcolor(BLUE);
                outtextxy(pixTOrc(40),pixTOrc(15),\"New\");
                advertise();
                getch();
                setfillstyle(SOLID_FILL,LIGHTGRAY);
                bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                advertise();
                break;

           case \'2\':    //Open
                setcolor(BLUE);
                outtextxy(pixTOrc(40),pixTOrc(15),\"Open\");
                advertise();
                getch();
                setfillstyle(SOLID_FILL,LIGHTGRAY);
                bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                advertise();
                break;

           case \'3\':    //Save
                setcolor(BLUE);
                outtextxy(pixTOrc(40),pixTOrc(15),\"Save\");
                advertise();
                getch();
                setfillstyle(SOLID_FILL,LIGHTGRAY);
                bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                advertise();
                break;

           case \'4\':    //Modify the status of item in inventory
                setcolor(BLUE);
                outtextxy(pixTOrc(40),pixTOrc(15),\"About Me\");
                advertise();
                getch();
                setfillstyle(SOLID_FILL,LIGHTGRAY);
                bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                advertise();
                break;

           case \'5\':    //Close the program
                setcolor(BLUE);
                outtextxy(pixTOrc(40),pixTOrc(15),\"CLOSE\");
                advertise();
                delay(1000);
                setfillstyle(SOLID_FILL,LIGHTGRAY);
                bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                advertise();
                goto out;
       }
      } while (choice != MAXITEM);
        out:
}



void main()
{
    int i,j;

    int gd=DETECT,gm=0;
    initgraph(&gd,&gm,\"\");

///code as space holder\\\\\\\\        setfillstyle(SOLID_FILL,LIGHTGRAY);
    bar(0,0,640,480);

    setcolor(DARKGRAY);
    rectangle(0,0,639,480);
    rectangle(1,1,638,479);
    setcolor(BLACK);
    rectangle(2,1,637,478);
    rectangle(3,1,636,477);

    settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
    setcolor(BLUE);
    outtextxy(pixTOrc(8),pixTOrc(2),\"  MENU  -->>  (Simple Style) \");

    setfillstyle(HATCH_FILL,DARKGRAY);
    for(i=15,j=70;i<40||j>40;i++,j--){
        bar(pixTOrc(8),pixTOrc(7),pixTOrc(i),pixTOrc(7.5));
        delay(10);
        bar(pixTOrc(j),pixTOrc(7),pixTOrc(70),pixTOrc(7.5));
        delay(20);
    }

    bar(pixTOrc(7),pixTOrc(14),pixTOrc(25),pixTOrc(50));

///code as space holder\\\\\\\\    
    //Calling Menu
    control_menu();

    closegraph();
}

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

  2. Program to print an array before and after adding 5 to its contents using pointers

  3. Program to implement Add and Subtract functions on Big Number Class

  4. Program that creats a 3D solid object using Translational Sweep Representatiom Method

  5. Program to tokenized a given string

  6. Program to coumputes and displays the factorial of the given number ( using Recursive Algorithm )

  7. Program to estimate the Differential value of the function using Euler Method

  8. Implement a Matrix class representing 2-dimensional matrix with the following functionalities i.e. operators + , - , * , == , += &lt;&lt; , &gt;&gt; etc

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

  10. Program of disk editor

  11. Program to illustrate the implementation of array as a Circular Queue

  12. Program that performs file read, write, update and display operations

  13. Program to illustrate the implementation of Arithmetic Expression Evaluater accepting {} & [] also

  14. Program to illusrate data conversion b/w built-in data types and user defined data types (int & float)

  15. Program to implement the Binary search Algorithm

  16. Program of Deapth First Search Traversal ( DFS )

  17. Program to illustrate the difference between the use of strcomp, strcmpi and stricmp

  18. Program to perform stack operations using array

  19. Program to show the use of Bitwise operator OR ( | )

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

 
 
Didn't find what you were looking for? Find more on Program of displaying graphical menu and operate it using arrow keys