Wednesday, July 11, 2018

Birh day wish program in C++

Source code:
#include<iostream.h>
#include<conio.h>
#include<dos.h>  //for delay();

int main()
{
 int i;
 char h=3;
 clrscr();
 cout<<"\t\t\tFrom: BIKASH SIJAPATI\n";
 delay(2000);
 cout<<"\t\t\tTo  : BALKRISHNA BHANDARI\n\n";
 delay(200);
 cout<<"\t\t";
 for(i=0;i<42;i++)
 cout<<"_";
 cout<<"\n\n";

 delay(200);
 cout<<"\t\t\t\ti i i i i\n";

 delay(200);
 cout<<"\t\t\t\t| | | | |\n";

 delay(200);
 cout<<"\t\t\t      __i_i_i_i_i__\n";

 delay(200);
 cout<<"\t\t\t     |"<<h<<"           "<<h<<"|\n";

 delay(200);
 cout<<"\t\t\t   __| "<<h<<"  03/28  "<<h<<" |__\n";

 delay(200);
 cout<<"\t\t\t  | "<<h<<"   "<<h<<"       "<<h<<"   "<<h<<" |\n";

 delay(200);
 cout<<"\t\t\t__|"<<h<<"   HAPPY     "<<h<<"   "<<h<<"|__\n";

 delay(200);
 cout<<"\t\t       | "<<h<<"   "<<h<<"     BIRTHDAY    "<<h<<" |\n";

 delay(200);
 cout<<"\t\t       |"<<h<<"  "<<h<<"     "<<h<<"    "<<h<<"     "<<h<<"   "<<h<<"|\n";


 delay(200);
 cout<<"\t\t       | "<<h<<" "<<h<<" "<<h<<" "<<h<<" B A L E "<<h<<" "<<h<<" "<<h<<" "<<h<<" |\n";

 delay(200);
 cout<<"\t\t       |_________________________|\n";
 delay(200);
 cout<<"\t\t";
 for(i=0;i<42;i++)
 cout<<"_";
 cout<<"\n\t\t Happiness begins with your smile and let your\n";
 cout<<"\t\tsmile change the world dear.Happy birthday BALE";
 cout<<"\n\n\n\n\n";
 getch();
 return 0;
}

output:

for more:

Thursday, July 5, 2018

DDA line drawing program in C++

source code:

/* Line drawing programme in c++ using DDA algorithm*/
#include<conio.h>
#include<iostream.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
void main()
{  float x,y,x1,y1,x2,y2,dx,dy,length;
   int i,gd=DETECT,gm;
   // Read two end point
   cout<<"Enter first point";
   cin>>x1>>y1;
   cout<<"Enter another point ";
   cin>>x2>>y2;
 // initializing the graphics mode
   initgraph(&gd,&gm,"c://TURBOC3//bgi");
   dx=abs(x2-x1);
   dy=abs(y2-y1);
   if(dx>=dy)
   {
   length=dx;
   }
   else {
   length=dy;
   }
    dx=(x2-x1)/length;
    dy=(y2-y1)/length;
    x=x1+0.5; //factor 0.5 is added to round the value
    y=y1+0.5;// factor 0.5 is added to round the value
    i=1;  // initialize the loop counter
    while(i<=length)
    {  putpixel(x,y,WHITE);
    x=x+dx;
    y=y+dy;
    i=i+1;
    delay(50); // to see every iteration or steps
    }
getch();

}

output:

Bresenham’s Line Drawing Algorithm in C and C++

Bresenham's line drawing algorithm in c and c++

Here you will get program for bresenham’s line drawing algorithm in C and C++.
This algorithm is used in computer graphics for drawing line.
The program will work in Turbo C or Turbo C++ compiler as it uses graphics.h header file.
Make sure to change the path of BGI folder inside initgraph() function according to your system. Otherwise the program will not work.

Program for Bresenham’s Line Drawing Algorithm in C

#include<stdio.h>
#include<graphics.h>
void drawline(int x0, int y0, int x1, int y1)
{
    int dx, dy, p, x, y;
    dx=x1-x0;
    dy=y1-y0;
    x=x0;
    y=y0;
    p=2*dy-dx;
    while(x<x1)
    {
        if(p>=0)
        {
            putpixel(x,y,7);
            y=y+1;
            p=p+2*dy-2*dx;
        }
        else
        {
            putpixel(x,y,7);
            p=p+2*dy;
        }
        x=x+1;
    }
}
int main()
{
    int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
    initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
    printf("Enter co-ordinates of first point: ");
    scanf("%d%d", &x0, &y0);
    printf("Enter co-ordinates of second point: ");
    scanf("%d%d", &x1, &y1);
    drawline(x0, y0, x1, y1);
    return 0;
}

Program for Bresenham’s Line Drawing Algorithm in C++

#include<iostream.h>
#include<graphics.h>
void drawline(int x0, int y0, int x1, int y1)
{
    int dx, dy, p, x, y;
    dx=x1-x0;
    dy=y1-y0;
    x=x0;
    y=y0;
    p=2*dy-dx;
    while(x<x1)
    {
        if(p>=0)
        {
            putpixel(x,y,7);
            y=y+1;
            p=p+2*dy-2*dx;
        }
        else
        {
            putpixel(x,y,7);
            p=p+2*dy;
        }
        x=x+1;
    }
}
int main()
{
    int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
    initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
    cout<<"Enter co-ordinates of first point: ";
    cin>>x0>>y0;
    cout<<"Enter co-ordinates of second point: ";
    cin>>x1>>y1;
    drawline(x0, y0, x1, y1);
    return 0;
}

Output: