Showing posts with label c-plus plus program. Show all posts
Showing posts with label c-plus plus program. Show all posts

Thursday 5 July 2012

Program that demostrate used of structure in c++.

#include<iostream>
using namespace std;

struct time_struct
{
int hour,minute,second;
};

int main()
{
time_struct st;
cout<<"Enter hour";
cin>>st.hour;
cout<<endl;

Program to display reverse number or string of inputed numbe or string in c++.

#include<iostream>
using namespace std;

int reverse(int );

int main()
{
int num,k;
cout<<"Enter your number:";
cin>>k;
cout<<endl;
num=reverse(k);
cout<<"Reverse number is :"<<num;
   
return 0;
}

Program to display prime factor of inputed number in c++ .

#include<iostream>
using namespace std;

void factor(int );

int main()
{
int k;
cout<<"Enter your number:";
cin>>k;
cout<<endl;
factor(k);
return 0;
}

Program to identify enter number is available or not within array of elements using c++.

#include<iostream>
using namespace std;

int main()
{
int n,flag,j,k;

    cout<<"Enter your total number here";
    cin>>n;
    int a[n];
        for(j=0;j<n;j++)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :";
        cin>>a[j];
        cout<<endl;
        }

Program to find maximum, minimum and sum of array of elememets in c++ .

#include<iostream>
using namespace std;

int main()
{
int n,i,j,k;

    cout<<"Enter your total number here";
    cin>>n;
    int a[n];
        for(j=0;j<n;j++)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :";
        cin>>a[j];
        cout<<endl;
        }

program to interchange odd and even element within array in c++.

#include<iostream>
using namespace std;

int main()
{
int n,i,j,k,temp;

    cout<<"Enter your total number here";
    cin>>n;
   
    int a[n];
    cout<<endl<<"enter element for first array"<<endl;

        for(j=0;j<n;j++)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :";
        cin>>a[j];
        cout<<endl;
        }

program to display transpose of matrix using c++ .

#include<iostream>
using namespace std;

int main()
{
int i,j,rows,cols;
   
    lable:
    cout<<"Enter your total number of rows ";
    cin>>rows;
    cout<<endl;
    cout<<"Enter your total number of cols ";
    cin>>cols;
    if (rows!=cols)
    {
    cout<<"rows and cols are not equal"<<endl;
    goto lable;
    }
    int a[rows][cols];
    cout<<endl<<"enter element for array"<<endl;

Wednesday 4 July 2012

program that sort the element of array into acending order and decending order using java.

#include<iostream>
using namespace std;

int main()
{
int n,i,j,k,temp;

    cout<<"Enter your total number here";
    cin>>n;
   
    int a[n];
    cout<<endl<<"enter element for first array"<<endl;
       
        for(j=0;j<n;j++)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :";
        cin>>a[j];
        cout<<endl;
        }

program that reverse an array of n number in c++.

#include<iostream>
using namespace std;

int main()
{
int n,j,temp;

    cout<<"Enter your total number here";
    cin>>n;
    int a[n];
//input from user
        for(j=0;j<=n;j++)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :"
        cin>>a[j];
        cout<<endl;
        }
//reverse array element
       
        for(j=n;j>0;j--)
        {
        cout<<"Enter  element at position  " <<j+1<<"  :"
        cout<<a[j];
        cout<<endl;
        }
        return 0;
}

Sunday 1 July 2012

Show movement of Ball using c++.


#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
#include <stdlib.h>


int tx=0,ty=0;

void getx(int &p)
{
    if (p==50)
    {
        tx = 0;
        p = p+1;
    }
    else if (p==getmaxx()-50)
    {
        tx = -1;
        p = p-1;
    }
    else if(tx==0)
        p = p + 1;
    else  if(tx==-1)
        p = p - 1;
}

Show movement of flying kite using c++.

#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
#include <stdlib.h>
#define ESC_KEY   0x1b

int tx=0,ty=0;
void getx(int &ox)
{
    if (ox==50)
    {
        tx=0;
        ox=ox+1;
    }
    else if (ox==590)
    {
        tx=-1;
        ox=ox-1;
    }
    else if(tx==0)
        ox=ox+1;
    else  if(tx==-1)
        ox=ox-1;
}

void gety(int &oy)
{
    if (oy==50)
    {
        ty=0;
        oy=oy+1;
    }
    else if (oy==430)
    {
        ty=-1;
        oy=oy-1;
    }
    else if(ty==0)
        oy=oy+1;
    else if(ty==-1)
        oy=oy-1;
}

void main()
{
int i,j;
int gdriver = DETECT, gmode, errorcode;
void kite(int,int);
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "..\\bgi");
int x,y;
x=400;
y=200;

a:
cleardevice();
getx(x);
gety(y);
kite(x,y);
        while(!kbhit())
        {

            delay(10);
            goto a;
        }
        if (getch()==ESC_KEY)
        {
            exit(1);
        }
        else
        goto a;
}
void kite(int i,int j)
{
line(i-50,j,i+50,j);
line(i,j-50,i,j+50);
line(i-50,j,i,j+50);
line(i,j-50,i+50,j);
line(i+50,j,i,j+50);
line(i,j-50,i-50,j);
line(i,j,getmaxx()/2,getmaxy() );
line(i,j+50,i-20,j+70);
line(i,j+50,i+20,j+70);
line(i+20,j+70,i-20,j+70);
}


To Show Movement of Ball using c++



#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
#include <stdlib.h>
#define ESC_KEY     0x1b

int tx=0,ty=0;
void getx(int &ox)
{
    if (ox==50)
    {
        tx=0;
        ox=ox+1;
    }
    else if (ox==getmaxx()-50)
    {
        tx=-1;
        ox=ox-1;
    }
    else if(tx==0)
        ox=ox+1;
    else  if(tx==-1)
        ox=ox-1;
}

void gety(int &oy)
{
    if (oy==50)
    {
        ty=0;
        oy=oy+1;
    }
    else if (oy==getmaxy()-50)
    {
        ty=-1;
        oy=oy-1;
    }
    else if(ty==0)
        oy=oy+1;
    else if(ty==-1)
        oy=oy-1;
}

void main()
{
int i,j;
int gdriver = DETECT, gmode, errorcode;

/* initialize graphics mode */
initgraph(&gdriver, &gmode, "..\\bgi");
int x,y;
x=100;
y=100;

a:
cleardevice();
settextstyle(0, HORIZ_DIR, 1);
outtextxy((getmaxx()/2)-20,getmaxy()-10,"PRESS ESC FOR EXIT");
getx(x);
gety(y);
settextstyle(0, HORIZ_DIR, 1);
circle(x,y,50);
outtextxy(x-20,y,"");
while(!kbhit())
{

delay(15);
goto a;
}
if (getch()==ESC_KEY)
{
exit(1);
}
else
goto a;

}




program to draw a wheels using c++.

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#define round(a) ((int)(0.5+a))
#define radian(x) (3.14*x/180.0)

void rotate(double r,int xc,int yc,int *crl)
{
    int temp,i;
    for(i=0;i<16;i++)
    {
        if(i%2==0)
        {
            temp=crl[i];
            crl[i]=round(xc+(crl[i]-xc)*cos(radian(30))-(crl[i+1]-yc)*sin(radian(30)));
        }
        else
            crl[i]=round(yc+(temp-xc)*sin(radian(30))+(crl[i]-yc)*cos(radian(30)));
    }
        return;
}

void main(void)
{
    int gd,gm,i,xc,yc,crl[16];
    double theta,r;
    clrscr();
    detectgraph(&gd,&gm);
    initgraph(&gd,&gm,"c:\\tc\\bgi");
    printf("Enter the Center of the wheel:");
    scanf("%d %d",&xc,&yc);
    printf("Enter the Radius of the wheel:");
    scanf("%lf",&r);
    setbkcolor(WHITE);
    setcolor(RED);
    circle(xc,yc,round(r));
    crl[0]=xc;
    crl[1]=yc+round(r);
    crl[2]=xc;
    crl[3]=yc-round(r);
    for(i=4;i<16;i++)
    {
        if(i%2==0)
            crl[i]=xc+(crl[i-4]-xc)*cos(radian(45))-(crl[i-3]-yc)*sin(radian(45));
        else
            crl[i]=yc+(crl[i-4]-xc)*sin(radian(45))+(crl[i-5]-yc)*cos(radian(45));
    }
    line(crl[0],crl[1],crl[2],crl[3]);
    line(crl[4],crl[5],crl[6],crl[7]);
    line(crl[8],crl[9],crl[10],crl[11]);
    line(crl[12],crl[13],crl[14],crl[15]);
    i=0;

program to draw a waves in c++.

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void main()
{
int gd,gm,mx,my,i,m,n,k,p;
m=50;
n=10;
p=0;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");
mx=getmaxx()/2;
my=getmaxy()/2;
setcolor(BLACK);
for(k=0;k<49;k++)
{
setfillstyle(SOLID_FILL,BLACK);
pieslice(mx,p,0,360,5);
p=p+5;
delay(50);
clrscr();
}

program to draw a circle in c++.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void circlepoints(int,int,int,int);
void main()
{
int xc,yc,r;
int x,y,p;
int gd,gm;
detectgraph(&gd,&gm);
initgraph(&gd,&gm," ");
x=0;
printf("enter the value of xcenter:");
scanf("%d",&xc);
printf("enter thye value of ycenter:");
scanf("%d",&yc);
printf("enter value of radiius:");
scanf("%d",&r);
y=r;    p=1-r;
circlepoints(xc,yc,x,y);

Saturday 30 June 2012

program that performed various operation on 2D (two dimensional ) object (polygon) like scaling,rotation,transformation in c++ .


    #include<graphics.h>
    #include<conio.h>
    #include<stdio.h>
    #include<math.h>
    #include<process.h>
    void main()
    {
        int gd,gm,r,tx,ty,xr,yr,g;
        float a[3][3],yref,xref;
        float b[3][3];
        float sx,sy,x1,y1,x2,y2,x3,y3,x4,y4,x11,y11,x22,y22,x33,y33,x44,y44,
        a1,xc,yc,shx,shy;
        detectgraph(&gd,&gm);
        initgraph(&gd,&gm,"  ");
//    printf("ENTER THE CO-ORDINATES OF TRIANGLE :");
//    scanf("%f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3);

Friday 29 June 2012

c++ program which will to display circle with animation

#include<dos.h>
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
do

c++ program to draw ellipse.

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
class myellipse
{
 public:
 int x,y,xcenter,ycenter;
 float rx,ry,p;
 void input()
  { 

c++ program to draw circle using MID POINT Algorithm.

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

class mid_circle
{
 public:
  int xc,yc,r;

c++ program to draw line using BRESHNHEM'S LINE Algorithm.

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

struct co_ordinate
{
 int x,y;
};

class bresline
{
 public:
  co_ordinate point[2];
  void input_parameter()
   {