Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts
on Sunday, 2 February 2014
 # include <iostream.h>
 # include <graphics.h>
 # include    <conio.h>
 # include     <math.h>


 # define  f                 0.3
 # define  projection_angle   45


 void show_screen( );

 void apply_rotation_along_x_axis(constint [5][3],constint);
 void multiply_matrices(constfloat[4],constfloat[4][4],float[4]);

 void draw_pyramid(int [5][3]);
 void get_projected_point(int&,int&,int&);

 void Line(constint,constint,constint,constint);


 int main( )
    {
       int driver=VGA;
       int mode=VGAHI;

       initgraph(&driver,&mode,"..\\Bgi");

       show_screen( );

       int pyramid[5][3]={
                {280,130,50},      //  base front left
                {360,130,50},      //  base front right
                {360,130,-50},     //  base back right
                {280,130,-50},     //  base back left
                {320,20,0}        //  top
             };

      setcolor(15);
     draw_pyramid(pyramid);

       setcolor(15);
       settextstyle(0,0,1);
     outtextxy(50,415,"*** Use + & - Keys to apply Rotation along x-axis.");

       int angle=0;
       int key_code=0;

       char Key=NULL;

       do
      {
         Key=NULL;
         key_code=0;

         Key=getch( );
         key_code=int(Key);

         if(key_code==0)
        {
           Key=getch( );
           key_code=int(Key);
        }

         if(key_code==27)
        break;

         elseif(key_code==43)
        angle-=5;

         elseif(key_code==45)
        angle+=5;

         setfillstyle(1,0);
           bar(40,70,600,410);

         apply_rotation_along_x_axis(pyramid,angle);
      }
       while(1);

       return 0;
    }

 /*************************************************************************//*************************************************************************///------------------------  Funcion Definitions  ------------------------///*************************************************************************//*************************************************************************//*************************************************************************///-------------------  apply_rotation_along_x_axis( )  ------------------///*************************************************************************/void apply_rotation_along_x_axis(constint control_points[5][3],
                                constint theta)
    {
       int edge_points[5][3]={0};

       float angle=(theta*(M_PI/180));

       for(int count=0;count<5;count++)
      {
         edge_points[count][0]=control_points[count][0];
         edge_points[count][1]=control_points[count][1];
         edge_points[count][2]=control_points[count][2];

         float matrix_a[4]={edge_points[count][0],edge_points[count][1],
                            edge_points[count][2],1};
         float matrix_b[4][4]={
                    { 1,0,0,0 } ,
                    { 0,cos(angle),sin(angle),0 } ,
                    { 0,-sin(angle),cos(angle),0 } ,
                    { 0,0,0,1 }
                  };
         float matrix_c[4]={0};

         multiply_matrices(matrix_a,matrix_b,matrix_c);

         edge_points[count][0]=(int)(matrix_c[0]+0.5);
         edge_points[count][1]=(int)(matrix_c[1]+0.5);
         edge_points[count][2]=(int)(matrix_c[2]+0.5);
      }

       setcolor(10);
     draw_pyramid(edge_points);
    }

 /************************************************************************///----------------------  multiply_matrices( )  ------------------------///************************************************************************/void multiply_matrices(constfloat matrix_1[4],
                  constfloat matrix_2[4][4],float matrix_3[4])
    {
       for(int count_1=0;count_1<4;count_1++)
      {
         for(int count_2=0;count_2<4;count_2++)
        matrix_3[count_1]+=
               (matrix_1[count_2]*matrix_2[count_2][count_1]);
      }
    }

 /************************************************************************///--------------------------  draw_pyramid( )  -------------------------///************************************************************************/void draw_pyramid(int points[5][3])
    {
       int edge_points[5][3];

       for(int i=0;i<5;i++)
      {
         edge_points[i][0]=points[i][0];
         edge_points[i][1]=points[i][1];
         edge_points[i][2]=points[i][2];

         get_projected_point(edge_points[i][0],
                    edge_points[i][1],edge_points[i][2]);

         edge_points[i][1]+=240;
      }

       Line(edge_points[0][0],edge_points[0][1],
                      edge_points[1][0],edge_points[1][1]);
       Line(edge_points[1][0],edge_points[1][1],
                      edge_points[2][0],edge_points[2][1]);
       Line(edge_points[2][0],edge_points[2][1],
                      edge_points[3][0],edge_points[3][1]);
       Line(edge_points[3][0],edge_points[3][1],
                      edge_points[0][0],edge_points[0][1]);

       Line(edge_points[0][0],edge_points[0][1],
                      edge_points[4][0],edge_points[4][1]);
       Line(edge_points[1][0],edge_points[1][1],
                      edge_points[4][0],edge_points[4][1]);
       Line(edge_points[2][0],edge_points[2][1],
                      edge_points[4][0],edge_points[4][1]);
       Line(edge_points[3][0],edge_points[3][1],
                      edge_points[4][0],edge_points[4][1]);
    }

 /************************************************************************///---------------------  get_projected_point( )  -----------------------///************************************************************************/void get_projected_point(int& x,int& y,int& z)
    {
       float fcos0=(f*cos(projection_angle*(M_PI/180)));
       float fsin0=(f*sin(projection_angle*(M_PI/180)));

       float Par_v[4][4]={
                {1,0,0,0},
                {0,1,0,0},
                {fcos0,fsin0,0,0},
                {0,0,0,1}
             };

       float xy[4]={x,y,z,1};
       float new_xy[4]={0};

       multiply_matrices(xy,Par_v,new_xy);

       x=(int)(new_xy[0]+0.5);
       y=(int)(new_xy[1]+0.5);
       z=(int)(new_xy[2]+0.5);
    }

 /*************************************************************************///-------------------------------  Line( )  -----------------------------///*************************************************************************/void Line(constint x_1,constint y_1,constint x_2,constint y_2)
    {
       int color=getcolor( );

       int x1=x_1;
       int y1=y_1;

       int x2=x_2;
       int y2=y_2;

       if(x_1>x_2)
      {
         x1=x_2;
         y1=y_2;

         x2=x_1;
         y2=y_1;
      }

       int dx=abs(x2-x1);
       int dy=abs(y2-y1);
       int inc_dec=((y2>=y1)?1:-1);

       if(dx>dy)
      {
         int two_dy=(2*dy);
         int two_dy_dx=(2*(dy-dx));
         int p=((2*dy)-dx);

         int x=x1;
         int y=y1;

         putpixel(x,y,color);

         while(x<x2)
        {
           x++;

           if(p<0)
              p+=two_dy;

           else
              {
             y+=inc_dec;
             p+=two_dy_dx;
              }

           putpixel(x,y,color);
        }
      }

       else
      {
         int two_dx=(2*dx);
         int two_dx_dy=(2*(dx-dy));
         int p=((2*dx)-dy);

         int x=x1;
         int y=y1;

         putpixel(x,y,color);

         while(y!=y2)
        {
           y+=inc_dec;

           if(p<0)
              p+=two_dx;

           else
              {
             x++;
             p+=two_dx_dy;
              }

           putpixel(x,y,color);
        }
      }
    }

 /*************************************************************************///--------------------------  show_screen( )  ---------------------------///*************************************************************************/void show_screen( )
    {
       setfillstyle(1,1);
     bar(210,26,420,38);

       settextstyle(0,0,1);
     setcolor(15);
       outtextxy(5,5,"******************************************************************************");
       outtextxy(5,17,"*-**************************************************************************-*");
       outtextxy(5,29,"*-----------------------                             ------------------------*");
       outtextxy(5,41,"*-**************************************************************************-*");
       outtextxy(5,53,"*-**************************************************************************-*");

     setcolor(11);
       outtextxy(218,29,"3D Rotation along X-axis");

     setcolor(15);

       for(int count=0;count<=30;count++)
          outtextxy(5,(65+(count*12)),"*-*                                                                        *-*");

       outtextxy(5,438,"*-**************************************************************************-*");
       outtextxy(5,450,"*-------------------------                          -------------------------*");
       outtextxy(5,462,"******************************************************************************");

     setcolor(12);
       outtextxy(229,450,"Press any Key to exit.");
    }
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

class    bank
{
char name[20];
int acno;
char actype[20];
int bal;
public :
void opbal(void);
void deposit(void);
void withdraw(void);
void display(void);
};

void bank :: opbal(void)
{
cout<<endl<<endl;
cout<<"Enter Name :-";
cin>>name;
cout<<"Enter A/c no. :-";
cin>>acno;
cout<<"Enter A/c Type :-";
cin>>actype;
cout<<"Enter Opening Balance:-";
cin>>bal;
}

void bank :: deposit(void)
{
cout<<"Enter Deposit amount :-";
int deposit=0;
cin>>deposit;
deposit=deposit+bal;
cout<<"\nDeposit Balance = "<<deposit;
bal=deposit;
}

void bank :: withdraw(void)
{
int withdraw;
cout<<"\nBalance Amount = "<<bal;
cout<<"\nEnter Withdraw Amount :-";
cin>>withdraw;
bal=bal-withdraw;
cout<<"After Withdraw Balance is "<<bal;
}

void  bank :: display(void)
{
cout<<endl<<endl<<endl;
cout<<setw(50)<<"DETAILS"<<endl;
cout<<setw(50)<<"name      "<<name<<endl;
cout<<setw(50)<<"A/c. No.     "<<acno<<endl;
cout<<setw(50)<<"A/c Type      "<<actype<<endl;
cout<<setw(50)<<"Balance     "<<bal<<endl;
}

void main()
{
clrscr();
bank o1;
int choice;
    do
    {
           cout<<"\n\nChoice List\n\n";
           cout<<"1)  To assign Initial Value\n";
         cout<<"2)  To Deposit\n";
         cout<<"3)  To Withdraw\n";
         cout<<"4)  To Display All Details\n";
         cout<<"5)  EXIT\n";
         cout<<"Enter your choice :-";
         cin>>choice;
         switch(choice)
         {
         case 1: o1.opbal();
                     break;
         case 2: o1.deposit();
                     break;
           case 3: o1.withdraw();
                     break;
         case 4: o1.display();
                     break;
            case 5: goto end;
         }
   }while(1);
end:
}
on Monday, 20 January 2014
# include <iostream.h>
 # include <graphics.h>
 # include    <conio.h>
 # include     <math.h>

 # define  f                 0.3
 # define  projection_angle   45

 void show_screen( );

 void Bezier_curve(constint,constint [4][3]);
 void Piece_wise_bezier_curve(constint,constint [25][3]);

 double nCr(int,int);
 double factorial(int);

 void get_projected_point(double&,double&,double&);
 void multiply_matrices(constfloat[4],constfloat[4][4],float[4]);

 void Dashed_line(constint,constint,constint,constint,constint=0);


 int main( )
    {
       int driver=VGA;
       int mode=VGAHI;

       int n;

       do
      {
         show_screen( );

         gotoxy(8,10);
         cout<<"Number of Control Points : n :";

         gotoxy(8,11);
         cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

         gotoxy(12,13);
         cout<<"Enter the value of n (1<n<=25) = ";
         cin>>n;

         if(n>=10)
        n=10;

         int control_points[25][3]={0};

         for(int count=0;count<n;count++)
        {
           gotoxy(8,16);
           cout<<"Coordinates of Point-"<<count<<" (x"<<count<<",y"<<count<<",z"<<count<<") :";

           gotoxy(8,17);
           cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

           gotoxy(12,19);
           cout<<"Enter the value of x"<<count<<" = ";
           cin>>control_points[count][0];

           gotoxy(12,21);
           cout<<"Enter the value of y"<<count<<" = ";
           cin>>control_points[count][1];

           gotoxy(12,23);
           cout<<"Enter the value of z"<<count<<" = ";
           cin>>control_points[count][2];

           gotoxy(8,16);
           cout<<"                                            ";

           gotoxy(12,19);
           cout<<"                                            ";

           gotoxy(12,21);
           cout<<"                                            ";

           gotoxy(12,23);
           cout<<"                                            ";
        }

         initgraph(&driver,&mode,"..\\Bgi");

         setcolor(15);
           Piece_wise_bezier_curve(n,control_points);

         setcolor(15);
           outtextxy(110,460,"Press <Enter> to continue or any other key to exit.");

         int key=int(getch( ));

         if(key!=13)
        break;
      }
       while(1);

       return 0;
    }

void Piece_wise_bezier_curve(constint n,constint cpts[25][3])
    {
       int pieces=(n/4);
       int extra_points=(n%4);

       int point=1;

       int cp[4][3]={0};

       for(int count_1=0;count_1<pieces;count_1++)
      {
         point--;

         for(int count_2=0;count_2<4;count_2++)
        {
           cp[count_2][0]=cpts[point][0];
           cp[count_2][1]=cpts[point][1];
           cp[count_2][2]=cpts[point][2];

           point++;
        }

         Bezier_curve(3,cp);
      }

       if(extra_points)
      {
         for(int count_3=(point-1),count_4=0;count_3<n;
                            count_3++,count_4++)
        {
           cp[count_4][0]=cpts[count_3][0];
           cp[count_4][1]=cpts[count_3][1];
           cp[count_4][2]=cpts[count_3][2];
        }

         Bezier_curve(extra_points,cp);
      }
    }

void Bezier_curve(constint n,constint cp[4][3])
    {
       setcolor(7);

       double x_1;
       double y_1;
       double z_1;
       double x_2;
       double y_2;
       double z_2;

       for(int count=0;count<n;count++)
      {
         x_1=cp[count][0];
         y_1=cp[count][1];
         z_1=cp[count][2];
         x_2=cp[(count+1)][0];
         y_2=cp[(count+1)][1];
         z_2=cp[(count+1)][2];

         get_projected_point(x_1,y_1,z_1);
         get_projected_point(x_2,y_2,z_2);

         Dashed_line((int)(x_1+0.5),(int)(y_1+0.5),
                         (int)(x_2+0.5),(int)(y_2+0.5));
      }

       double x;
       double y;
       double z;

       for(float u=0.0005;u<=1;u+=0.0005)
      {
         x=0;
         y=0;
         z=0;

         for(int k=0;k<=n;k++)
        {
           x+=(cp[k][0]*nCr(n,k)*pow(u,k)*powl((1-u),(n-k)));
           y+=(cp[k][1]*nCr(n,k)*pow(u,k)*powl((1-u),(n-k)));
           z+=(cp[k][2]*nCr(n,k)*pow(u,k)*powl((1-u),(n-k)));
        }

         get_projected_point(x,y,z);

         putpixel((int)(x+0.5),(int)(y+0.5),15);
      }
    }

double nCr(int n,int r)
    {
       double nf;
       double rf;
       double nrf;
       double ncr;

       nf=factorial(n);
       rf=factorial(r);
       nrf=factorial((n-r));

       ncr=(nf/(rf*nrf));

       return ncr;
    }

double factorial(int number)
    {
       double factorial=1;

       if(number==0 || number==1);

       else
      {
         for(int count=1;count<=number;count++)
        factorial=factorial*count;
      }

       return factorial;
    }

void get_projected_point(double& x,double& y,double& z)
    {
       float fcos0=(f*cos(projection_angle*(M_PI/180)));
       float fsin0=(f*sin(projection_angle*(M_PI/180)));

       float Par_v[4][4]={
                {1,0,0,0},
                {0,1,0,0},
                {fcos0,fsin0,0,0},
                {0,0,0,1}
             };

       float xy[4]={x,y,z,1};
       float new_xy[4]={0};

       multiply_matrices(xy,Par_v,new_xy);

       x=new_xy[0];
       y=new_xy[1];
       z=new_xy[2];
    }

void multiply_matrices(constfloat matrix_1[4],
                  constfloat matrix_2[4][4],float matrix_3[4])
    {
       for(int count_1=0;count_1<4;count_1++)
      {
         for(int count_2=0;count_2<4;count_2++)
        matrix_3[count_1]+=
               (matrix_1[count_2]*matrix_2[count_2][count_1]);
      }
    }

void Dashed_line(constint x_1,constint y_1,constint x_2,
                      constint y_2,constint line_type)
    {
       int count=0;
       int color=getcolor( );

       int x1=x_1;
       int y1=y_1;

       int x2=x_2;
       int y2=y_2;

       if(x_1>x_2)
      {
         x1=x_2;
         y1=y_2;

         x2=x_1;
         y2=y_1;
      }

       int dx=abs(x2-x1);
       int dy=abs(y2-y1);
       int inc_dec=((y2>=y1)?1:-1);

       if(dx>dy)
      {
         int two_dy=(2*dy);
         int two_dy_dx=(2*(dy-dx));
         int p=((2*dy)-dx);

         int x=x1;
         int y=y1;

         putpixel(x,y,color);

         while(x<x2)
        {
           x++;

           if(p<0)
              p+=two_dy;

           else
              {
             y+=inc_dec;
             p+=two_dy_dx;
              }

           if((count%2)!=0 && line_type==0)
              putpixel(x,y,color);

           elseif((count%5)!=4 && line_type==1)
              putpixel(x,y,color);

           elseif((count%10)!=8 && (count%10)!=9 && line_type==2)
              putpixel(x,y,color);

           elseif((count%20)!=18 && (count%20)!=19 && line_type==3)
              putpixel(x,y,color);

           elseif((count%12)!=7 && (count%12)!=8 &&
                (count%12)!=10 && (count%12)!=11 && line_type==4)
              putpixel(x,y,color);

           count++;
        }
      }

       else
      {
         int two_dx=(2*dx);
         int two_dx_dy=(2*(dx-dy));
         int p=((2*dx)-dy);

         int x=x1;
         int y=y1;

         putpixel(x,y,color);

         while(y!=y2)
        {
           y+=inc_dec;

           if(p<0)
              p+=two_dx;

           else
              {
             x++;
             p+=two_dx_dy;
              }

           if((count%2)!=0 && line_type==0)
              putpixel(x,y,color);

           elseif((count%5)!=4 && line_type==1)
              putpixel(x,y,color);

           elseif((count%10)!=8 && (count%10)!=9 && line_type==2)
              putpixel(x,y,color);

           elseif((count%20)!=18 && (count%20)!=19 && line_type==3)
              putpixel(x,y,color);

           elseif((count%12)!=7 && (count%12)!=8 &&
                (count%12)!=10 && (count%12)!=11 && line_type==4)
              putpixel(x,y,color);

           count++;
        }
      }
    }

void show_screen( )
    {
       restorecrtmode( );
       clrscr( );
       textmode(C4350);

       cprintf("\n********************************************************************************");
       cprintf("*-***********************-                           -************************-*");
       cprintf("*------------------------- ");

       textbackground(1);
       cprintf(" Piece-Wise Bezier Curve ");
       textbackground(8);

       cprintf(" --------------------------*");
       cprintf("*-***********************-                           -************************-*");
       cprintf("*-****************************************************************************-*");

       for(int count=0;count<42;count++)
      cprintf("*-*                                                                          *-*");

       gotoxy(1,46);
       cprintf("*-****************************************************************************-*");
       cprintf("*------------------------------------------------------------------------------*");
       cprintf("********************************************************************************");

       gotoxy(1,2);
    }

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>

class phoneBook{
    char name[20],phno[15];
    public:
    void getdata();
    void showdata();
    char *getname(){ return name; }
    char *getphno(){ return phno; }
    void update(char *nm,char *telno){
        strcpy(name,nm);
        strcpy(phno,telno);
    }
};

void phoneBook :: getdata(){
    cout<<"\nEnter Name : ";
    cin>>name;
    cout<<"Enter Phone No. : ";
    cin>>phno;
}

void phoneBook :: showdata(){
    cout<<"\n";
    cout<<setw(20)<<name;
    cout<<setw(15)<<phno;
}


void main(){
    phoneBook rec;
    fstream file;
    file.open("d:\\phone.dat", ios::ate | ios::in | ios::out | ios::binary);
    char ch,nm[20],telno[6];
    int choice,found=0;
    while(1){
        clrscr();
        cout<<"\n*****Phone Book*****\n";
        cout<<"1) Add New Record\n";
        cout<<"2) Display All Records\n";
        cout<<"3) Search Telephone No.\n";
        cout<<"4) Search Person Name\n";
        cout<<"5) Update Telephone No.\n";
        cout<<"6) Exit\n";
        cout<<"Choose your choice : ";
        cin>>choice;
        switch(choice){
            case 1 : //New Record
                 rec.getdata();
                 cin.get(ch);
                 file.write((char *) &rec, sizeof(rec));
                 break;

            case 2 : //Display All Records
                 file.seekg(0,ios::beg);
                 cout<<"\n\nRecords in Phone Book\n";
                 while(file){
                    file.read((char *) &rec, sizeof(rec));
                    if(!file.eof())
                        rec.showdata();
                 }
                 file.clear();
                 getch();
                 break;

            case 3 : //Search Tel. no. when person name is known.
                 cout<<"\n\nEnter Name : ";
                 cin>>nm;
                 file.seekg(0,ios::beg);
                 found=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    if(strcmp(nm,rec.getname())==0)
                    {
                        found=1;
                        rec.showdata();
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 getch();
                 break;

            case 4 : //Search name on basis of tel. no
                 cout<<"\n\nEnter Telephone No : ";
                 cin>>telno;
                 file.seekg(0,ios::beg);
                 found=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    if(strcmp(telno,rec.getphno())==0)
                    {
                        found=1;
                        rec.showdata();
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 getch();
                 break;

            case 5 : //Update Telephone No.
                 cout<<"\n\nEnter Name : ";
                 cin>>nm;
                 file.seekg(0,ios::beg);
                 found=0;
                 int cnt=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    cnt++;
                    if(strcmp(nm,rec.getname())==0)
                    {
                        found=1;
                        break;
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 else
                 {
                    int location = (cnt-1) * sizeof(rec);
                    cin.get(ch);
                    if(file.eof())
                        file.clear();

                    cout<<"Enter New Telephone No : ";
                    cin>>telno;
                    file.seekp(location);
                    rec.update(nm,telno);
                    file.write((char *) &rec, sizeof(rec));
                    file.flush();
                 }
                 break;
            case 6 : gotoout;
        }
    }
out:
file.close();
}[/Code]
on Sunday, 19 January 2014
 #include<iostream.h>
 #include<conio.h>


 int year_code(int,int);

 main()
    {
       clrscr();

       int date;
       int year;
       int month;
       int birth_week;
       int century;
       int birth_year;
       int century_remainder;
       int century_code;
       int birth_year_code;
       int day;

       cout<<"\n Enter the date in the following pattern :"<<endl;
       gotoxy(34,3);
       cout<<"Date - Month - Year"<<endl;

       gotoxy(39,4);
       cout<<"-       -       "<<endl;

       gotoxy(35,4);
       cin>>date;

       gotoxy(43,4);
       cin>>month;

       gotoxy(50,4);
       cin>>year;

       century=year/100;
       birth_year=year%100;

       century_remainder=century%4;

       if(century_remainder==0)
      century_code=date-1;

       elseif(century_remainder==1)
      century_code=date-3;

       elseif(century_remainder==2)
      century_code=date-5;

       else
      century_code=date;

       birth_year_code=year_code(birth_year,month);
       birth_week=century_code+birth_year_code;

       cout<<"\n The day on the given date is : ";

       day=birth_week%7;

       switch(day)
      {
         case 0: cout<<"Friday";
             break;

         case 1: cout<<"Saturday";
             break;

         case 2: cout<<"Sunday";
             break;

         case 3: cout<<"Monday";
             break;

         case 4: cout<<"Tuesday";
             break;

         case 5: cout<<"Wednesday";
             break;

         case 6: cout<<"Thursday";
             break;
      }

       getch();
       return 0;
    }

int year_code(int year,int month)
    {
       int code;

       int array_1[12]={3,6,6,2,4,7,2,5,1,3,6,1};
       int array_2[12]={4,7,7,3,5,1,3,6,2,4,7,2};
       int array_3[12]={5,1,1,4,6,2,4,7,3,5,1,3};
       int array_4[12]={6,2,3,6,1,4,6,2,5,7,3,5};
       int array_5[12]={1,4,4,7,2,5,7,3,6,1,4,6};
       int array_6[12]={2,5,5,1,3,6,1,4,7,2,5,7};
       int array_7[12]={3,6,6,2,4,7,2,5,1,3,6,1};
       int array_8[12]={4,7,1,4,6,2,4,7,3,5,1,3};
       int array_9[12]={6,2,2,5,7,3,5,1,4,6,2,4};
       int array_10[12]={7,3,3,6,1,4,6,2,5,7,3,5};
       int array_11[12]={2,3,1,2,4,7,2,5,1,3,6,1};
       int array_12[12]={7,3,4,7,2,5,7,3,6,1,4,6};
       int array_13[12]={5,1,2,5,7,3,5,1,4,6,2,4};
       int array_14[12]={3,6,7,3,5,1,3,6,2,4,7,2};
       int array_15[12]={1,4,5,1,3,6,1,4,7,2,5,7};

       if(year==1 || year==29 || year== 57 || year==85 || year==7 ||
     year==35 || year==63 || year==91 || year==18 || year==46 || year==74)
      code=array_1[month-1];

       elseif(year==2 || year==30 || year== 58 || year==86 || year==13 ||
     year==41 || year==69 || year==97 || year==19 || year==47 || year==75)
      code=array_2[month-1];

       elseif(year==3 || year==31 || year== 59 || year==87 || year==14 ||
     year==42 || year==70 || year==98 || year==25 || year==53 || year==81)
      code=array_3[month-1];

       elseif(year==4 || year==32 || year== 60 || year==88)
      code=array_4[month-12];

       elseif(year==5 || year==33 || year== 61 || year==89 || year==11 ||
     year==39 || year==67 || year==95 || year==22 || year==50 || year==78)
      code=array_5[month-1];

       elseif(year==6 || year==34 || year== 62 || year==90 || year==17 ||
             year==45 || year==73 || year==23 || year==51 || year==79)
      code=array_6[month-1];

       elseif(year==7 || year==35 || year== 63 || year==91)
      code=array_7[month-1];

       elseif(year==8 || year==36 || year==64 || year==92)
      code=array_8[month-1];

       elseif(year==9 || year==37 || year== 65 || year==93 || year==15 ||
     year==43 || year==71 || year==99 || year==26 || year==54 || year==82)
      code=array_9[month-1];

       elseif(year==10 || year==38 || year==66 || year==94 || year==21 ||
             year==49 || year==77 || year==27 || year==55 || year==83)
      code=array_10[month-1];

       elseif(year==12 || year==40 || year==68 || year==96)
      code=array_11[month-1];

       elseif(year==16 || year==44 || year==72 || year==100)
      code=array_12[month-1];

       elseif(year==20 || year==48 || year==76)
      code=array_13[month-1];

       elseif(year==24 || year==52 || year==80)
      code=array_14[month-1];

       elseif(year==28 || year==56 || year==84)
      code=array_15[month-1];

       return code;
    }
#include<iostream.h>
#include<iomanip.h>
template<class s>                                ///templats classclass stack
{
      private:
          int top;
          s item;
          s array[5];
      public:
          stack()
          {
              top=-1;
          }
          void getdata()
          {
                  cout<<"enter item to push in stack"<<endl;
                cin>>item;
             
          }
          void push()
          {
              if(top==5)
                  cout<<"overflow"<<endl;
              else
              {
                  top++;
                  array[top]=item;
              }
          }
          void pop()
          {
              if(top==-1)
                  cout<<"underflow"<<endl;
              else
              {
                  array[top]=NULL;
                 
                  top--;
              }
          }
          void disp()
          {
               for(int i=0;i<=top;i++)
               {
                     cout<<array[i]<<'\t';
               }
                cout<<endl;
          }
};
int main()
{
    stack<int>stacki;
    stack<char>stackc;
    int r;
    char ch;
    do
    {
        cout<<"integer array"<<endl;
        cout<<"press 1 to push element in stack & 2 to pop it"<<endl;
        cout<<"    3 to display stack"<<endl;
        cin>>r;
        switch (r)
        {
          case 1:
               stacki.getdata();
               stacki.push();
               break;
          case 2:
                stacki.pop();
                break;
          case 3:
                stacki.disp();
                break;
          default:
            cout<<"bad input"<<endl;
            break;
        }
        cout<<"do you want to process more y/n"<<endl;
        cin>>ch;
    }
    while(ch!='n');
do
{  
    cout<<"character array"<<endl;
        cout<<"press 1 to push element in stack & 2 to pop it"<<endl;
        cout<<"    3 to display stack"<<endl;
        cin>>r;
        switch (r)
        {
          case 1:
               stackc.getdata();
               stackc.push();
               break;
          case 2:
                stackc.pop();
                break;
          case 3:
                stackc.disp();
                break;
          default:
            cout<<"bad input"<<endl;
            break;
        }
        cout<<"do you want to process more y/n"<<endl;
        cin>>ch;
    }
    while(ch!='n');

    return 0;
}

on Tuesday, 14 January 2014

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip.h>
#include<ctype.h>

void main()

{
clrscr();
int i,l;
char st[50];

ofstream t1("lower.txt");
ofstream t2("upper.txt");

if(t1&&t2)
{
cout<<"ENTER "<<endl;
gets(st);
l=strlen(st);
for(i=0;i<l;i++)
{
if(islower(st[i]))
t1<<st[i];
if(isupper(st[i]))
t2<<st[i];
}
}

getch();
}


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


struct employee
{
int eno;
char name[25];
float salary;
}e[10];

void main()
{
clrscr();
int n;
void bubb(employee,int);
cout<<"Enter No of Employees"<<endl;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter Employee Name   :";
gets(e[i].name);
cout<<endl<<"Enter Employee  Code  :";
cin>>e[i].eno;
cout<<endl<<"Enter Employee Salary   :";
cin>>e[i].salary;
}
bubb(e[10],n);
getch();
}
void bubb(employee e,int n)
{
employee x;
for(int j=0;j<n;j++)
{
if(e[j].salary<e[j+1].salary)
{
for(int i=j;i<n-1;i++)
{
x=e[i];
e[i]=e[i+1];
e[i+1]=x;
}
}
}
for(int i=0;i<n;i++)
{
cout<<endl;
cout<<e[i].name<<endl<<e[i].salary<<endl<<e[i].eno;
}
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void main()
{
clrscr();
int aa,g,h,s=0,ii=0,dd,b,ch;
men :
cout<<endl<<"Enter the choice - "<<endl<<endl<<"1:Binary to Decimal"<<endl<<endl<<"2:Decimal to Binary"<<endl;
cout<<endl<<
"3:Binary to Octal"<<endl<<endl<<"4:Octal to Binary"<<endl<<endl<<"5:exit"<<endl<<endl;;
cin>>ch;
switch(ch)
{
case 1:
s=0;
ii=0;
cout<<"Enter the Binary Digit"<<endl;
cin>>b;

while(b>0)
{
aa=b%10;
s=s+aa*(pow(2,ii));
ii=ii+1;
b=b/10;
}
cout<<"Answer ="<<s<<endl;
goto men;

case 2:
s=0;
ii=0;
cout<<"Enter the Decimal"<<endl;
cin>>dd;
while(dd>0)
{
aa=dd%2;
aa=aa*pow(10,ii);
s=s+aa;
ii=ii+1;
dd=dd/2;
}
cout<<"Answer ="<<s<<endl;
goto men;


case 3:
int oc,sum,p,r,n,a,i=0,x=0,d=0,j,o;
cout<<"ENTER THE BINARY DIGIT  :"<<endl;
cin>>b;
while(b>0)
{
a=b%1000;
j=0;
d=0;
while(a>0)
{
n=(a%10);
d=d+(n*pow(2,j));
j=j+1;
a=a/10;
}
x=x+(d*pow(10,i));
i=i+1;
b=b/1000;
}
cout<<"Answer ="<<x;
goto men;


case 4:
cout<<"Enter the Octel"<<endl;
cin>>oc;
i=0;
j=0;
sum=0;
s=0;

while(oc>0)
{
p=oc%1000;
while(p>0)
{
r=p%2;
s=s+r*pow(10,j);
j++;
p=p/2;
}
sum=sum+(s*pow(1000,i));
i++;
oc=oc/10;
j=0;
}
cout<<"Binary ="<<sum;
goto men;

case 5:
exit(0);

default:
cout<<"Wrong choice"<<endl;

}
getch();

}


on Friday, 10 January 2014
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void dda( float xa, float ya, float xb, float yb);


void main()
{
clrscr();

int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");
for(int i=16;i>=14; i--)
{

delay(900);
setcolor(i);
line(216,110,410,110);

}
for(int i1=16;i1>=14; i1--)
{

delay(900);
setcolor(i1);
line(216,110,216,250);

}

for(int i2=16;i2>=14; i2--)
{

delay(900);
setcolor(i2);
line(216,250,410,250);
}
for(int i3=16;i3>=14; i3--)
{

delay(900);
setcolor(i3);
line(410,110,410,250);
}
for(int i4=16;i4>=14; i4--)
{

delay(900);
setcolor(i4);
line(216,120,410,120);
               }for(int i5=16;i5>=14; i5--)
{

delay(900);
setcolor(i5);
line(216,110,313,10);   }
for(int i6=16;i6>=14; i6--)
{

delay(900);
setcolor(i6);
line(410,110,313,10);
}for(int i7=16;i7>=14; i7--)
{

delay(900);
setcolor(i7);
line(250,250,250,150);   }
for(int i8=16;i8>=14; i8--)
{

delay(900);
setcolor(i8);
line(300,250,300,150);
}for(int i9=16;i9>=14; i9--)
{

delay(900);
setcolor(i9);
line(250,150,300,150);
 }for(int i10=16;i10>=14; i10--)
{

delay(900);
setcolor(i10);

line(320,150,320,200);   }
for(int i11=16;i11>=14; i11--)
{

delay(900);
setcolor(i11);
line(390,150,390,200);  }for(int i111=16;i111>=14; i111--)
{

delay(900);
setcolor(i111);
line(320,150,390,200);   }
for(int i12=16;i12>=14; i12--)
{

delay(900);
setcolor(i12);
line(320,200,390,150);
}for(int i13=16;i13>=14; i13--)
{

delay(900);
setcolor(i13);
line(320,150,390,150);
}for(int i14=16;i14>=14; i14--)
{

delay(900);
setcolor(i14);
line(320,200,390,200);  }
for(int i15=16;i15>=14; i15--)
{

delay(900);
setcolor(i15);
circle(313,60,10);       }
for(int i16=16;i16>=14; i16--)
{

delay(900);
setcolor(i16);

line(410,120,480,90);
}
for(int i17=16;i17>=14; i17--)
{

delay(900);
setcolor(i17);
line(313,10,480,90);
}
for(int i18=16;i18>=14; i18--)
{
delay(900);
setcolor(i18);
line(410,250,480,220);
}
for(int i19=16;i19>=14; i19--)
{

delay(900);
setcolor(i19);
line(480,90,480,220);     }for(int i20=16;i20>=14; i20--)
{

delay(900);
setcolor(i20);

line(410,110,468,87);      }for(int i21=16;i21>=14; i21--)
{

delay(900);
setcolor(i21);

line(436,150,460,140);      }for(int i22=16;i22>=14; i22--)
{

delay(900);
setcolor(i22);
line(437,200,461,190);       }for(int i23=16;i23>=14; i23--)
{

delay(900);
setcolor(i23);
line(437,150,437,200);    }for(int i24=16;i24>=14; i24--)
{

delay(900);
setcolor(i24);
line(460,140,460,190);     }for(int i25=16;i25>=14; i25--)
{

delay(900);
setcolor(i25);

line(436,160,460,150);
}for(int i26=16;i26>=14; i26--)
{

delay(900);
setcolor(i26);
line(436,190,460,180);
}for(int i27=16;i27>=14; i27--)
{

delay(900);
setcolor(i27);
circle(448,170,12);
}for(int i28=16;i28>=14; i28--)
{

delay(900);
setcolor(i28);

arc(185,275,300,20,70);
}for(int i29=16;i29>=14; i29--)
{

delay(900);
setcolor(i29);
arc(235,275,300,20,70);
 }


getch();
}