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

 constint max_size=13;

 int n=0;
 int top=-1;
 int choice=0;

 longdouble h=0;
 longdouble x0=0;

 longdouble xn[max_size]={0};
 longdouble fx[max_size]={0};

 char Fx[100]={NULL};
 char Dfx[100]={NULL};
 char Stack[30][30]={NULL};
 char Postfix_expression[2][30][30]={NULL};

 void push(constchar *);
 void convert_ie_to_pe(constchar *,constint);

 constchar* pop( );
 constlongdouble evaluate_postfix_expression(constlongdouble,constint);

 void show_screen( );
 void clear_screen( );
 void get_input( );
 void estimate_dfx( );

 constint get_index(constlongdouble);

 int main( )
    {
       clrscr( );
       textmode(C4350);

       show_screen( );
       get_input( );
       estimate_dfx( );

       return 0;
     }


 /*************************************************************************///--------------------------  show_screen( )  ---------------------------///*************************************************************************/void show_screen( )
    {
       cprintf("\n********************************************************************************");
       cprintf("*************************-                             -************************");
       cprintf("*------------------------- ");

       textbackground(1);
       cprintf(" Numerical Differentiation ");
       textbackground(8);

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

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

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

       gotoxy(1,2);
    }

 /*************************************************************************///-------------------------  clear_screen( )  ---------------------------///*************************************************************************/void clear_screen( )
    {
       for(int count=0;count<37;count++)
      {
         gotoxy(5,8+count);
         cout<<"                                                                        ";
      }

       gotoxy(1,2);
    }

 /*************************************************************************///--------------------------  push(const char*)  ------------------------///*************************************************************************/void push(constchar* Operand)
    {
       if(top==(max_size-1))
      {
         cout<<"Error : Stack is full."<<endl;
         cout<<"\n        Press any key to exit.";

         getch( );
         exit(0);
      }

       else
      {
         top++;
         strcpy(Stack[top],Operand);
      }
    }

 /*************************************************************************///------------------------------  pop( )  -------------------------------///*************************************************************************/constchar* pop( )
    {
       char Operand[40]={NULL};

       if(top==-1)
      {
         cout<<"Error : Stack is empty."<<endl;
         cout<<"\n        Press any key to exit.";

         getch( );
         exit(0);
      }

       else
      {
         strcpy(Operand,Stack[top]);
         strset(Stack[top],NULL);
         top--;
      }

       return Operand;
    }

 /*************************************************************************///----------------  convert_ie_to_pe(const char*,const int)  ------------///*************************************************************************/void convert_ie_to_pe(constchar* Expression,constint index)
    {
       char Infix_expression[100]={NULL};
       char Symbol_scanned[30]={NULL};

       push("(");
       strcpy(Infix_expression,Expression);
       strcat(Infix_expression,"+0)");

       int flag=0;
       int count_1=0;
       int count_2=0;
       int equation_length=strlen(Infix_expression);

       if(Infix_expression[0]=='(')
      flag=1;

       do
      {
         strset(Symbol_scanned,NULL);

         if(flag==0)
        {
           int count_3=0;

           do
              {
             Symbol_scanned[count_3]=Infix_expression[count_1];

             count_1++;
             count_3++;
              }
           while(count_1<=equation_length &&
               Infix_expression[count_1]!='(' &&
                  Infix_expression[count_1]!='+' &&
                 Infix_expression[count_1]!='-' &&
                    Infix_expression[count_1]!='*' &&
                       Infix_expression[count_1]!='/' &&
                      Infix_expression[count_1]!='^' &&
                         Infix_expression[count_1]!=')');


           flag=1;
        }

         elseif(flag==1)
        {
           Symbol_scanned[0]=Infix_expression[count_1];

           count_1++;

           if(Infix_expression[count_1]!='(' &&
             Infix_expression[count_1]!='^' &&
                Infix_expression[count_1]!='*' &&
                   Infix_expression[count_1]!='/' &&
                  Infix_expression[count_1]!='+' &&
                     Infix_expression[count_1]!='-' &&
                    Infix_expression[count_1]!=')')
              flag=0;

           if(Infix_expression[count_1-1]=='(' &&
               (Infix_expression[count_1]=='-' ||
                 Infix_expression[count_1]=='+'))
              flag=0;
        }

         if(strcmp(Symbol_scanned,"(")==0)
        push("(");

         elseif(strcmp(Symbol_scanned,")")==0)
        {
           while(strcmp(Stack[top],"(")!=0)
              {
             strcpy(Postfix_expression[index][count_2],pop( ));

             count_2++;
              }

           pop( );
        }

         elseif(strcmp(Symbol_scanned,"^")==0 ||
               strcmp(Symbol_scanned,"+")==0 ||
                 strcmp(Symbol_scanned,"-")==0 ||
                       strcmp(Symbol_scanned,"*")==0 ||
                         strcmp(Symbol_scanned,"/")==0)
        {
           if(strcmp(Symbol_scanned,"^")==0)
              {  }

           elseif(strcmp(Symbol_scanned,"*")==0 ||
                          strcmp(Symbol_scanned,"/")==0)
              {
             while(strcmp(Stack[top],"^")==0 ||
                     strcmp(Stack[top],"*")==0 ||
                       strcmp(Stack[top],"/")==0)
                {
                   strcpy(Postfix_expression[index][count_2],pop( ));

                   count_2++;
                }
              }

           elseif(strcmp(Symbol_scanned,"+")==0 ||
                    strcmp(Symbol_scanned,"-")==0)
              {
             while(strcmp(Stack[top],"(")!=0)
                {
                   strcpy(Postfix_expression[index][count_2],pop( ));

                   count_2++;
                }
              }

           push(Symbol_scanned);
        }

         else
        {
           strcat(Postfix_expression[index][count_2],Symbol_scanned);

           count_2++;
        }
      }
       while(strcmp(Stack[top],NULL)!=0);

       strcat(Postfix_expression[index][count_2],"=");
       count_2++;
    }

 /*************************************************************************///-----  evaluate_postfix_expression(const long double,const int)  ------///*************************************************************************/constlongdouble evaluate_postfix_expression(
                    constlongdouble x,constint index)
    {
       longdouble function_value=0;

       int count_1=-1;

       char Symbol_scanned[30]={NULL};

       do
      {
         count_1++;

         strcpy(Symbol_scanned,Postfix_expression[index][count_1]);

         if(strcmp(Symbol_scanned,"^")==0 ||
              strcmp(Symbol_scanned,"*")==0 ||
                strcmp(Symbol_scanned,"/")==0 ||
                  strcmp(Symbol_scanned,"+")==0 ||
                    strcmp(Symbol_scanned,"-")==0)

        {
           char Result[30]={NULL};
           char Operand[2][30]={NULL};

           strcpy(Operand[0],pop( ));
           strcpy(Operand[1],pop( ));

           longdouble operand[2]={0};
           longdouble result=0;

           char *endptr;

           for(int count_2=0;count_2<2;count_2++)
              {
             int flag=0;

             if(Operand[count_2][0]=='-')
                {
                   int length=strlen(Operand[count_2]);

                   for(int count_3=0;count_3<(length-1);count_3++)
                  Operand[count_2][count_3]=Operand[count_2][(count_3+1)];

                   Operand[count_2][count_3]=NULL;

                   flag=1;
                }

             if(strcmp(Operand[count_2],"x")==0)
                operand[count_2]=x;

             elseif(strcmp(Operand[count_2],"e")==0)
                operand[count_2]=2.718282;

             elseif(strcmp(Operand[count_2],"sinx")==0)
                operand[count_2]=sinl(x);

             elseif(strcmp(Operand[count_2],"cosx")==0)
                operand[count_2]=cosl(x);

             elseif(strcmp(Operand[count_2],"tanx")==0)
                operand[count_2]=tanl(x);

             elseif(strcmp(Operand[count_2],"lnx")==0)
                operand[count_2]=logl(x);

             elseif(strcmp(Operand[count_2],"logx")==0)
                operand[count_2]=log10l(x);

             else
                operand[count_2]=strtod(Operand[count_2],&endptr);

             if(flag)
                operand[count_2]*=-1;
              }

           switch(Symbol_scanned[0])
              {
             case'^' : result=powl(operand[1],operand[0]);
                    break;

             case'*' : result=operand[1]*operand[0];
                    break;

             case'/' : result=operand[1]/operand[0];
                    break;

             case'+' : result=operand[1]+operand[0];
                    break;

             case'-' : result=operand[1]-operand[0];
                    break;
              }

           gcvt(result,25,Result);

           push(Result);
        }

         elseif(strcmp(Symbol_scanned,"=")!=0)
        push(Symbol_scanned);
      }
       while(strcmp(Symbol_scanned,"=")!=0);

       char Function_value[30]={NULL};
       char *endptr;

       strcpy(Function_value,pop( ));
       function_value=strtod(Function_value,&endptr);

       return function_value;
    }

 /*************************************************************************///-----------------------------  get_input( )  --------------------------///*************************************************************************/void get_input( )
    {
       do
      {
         clear_screen( );

         gotoxy(6,9);
         cout<<"Number of Distinct Data Points :";

         gotoxy(6,10);
         cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

         gotoxy(27,13);
         cout<<"[ min. n = 3  |  max. n = 12 ]";

         gotoxy(6,12);
         cout<<"Enter the max. number of distinct data points = n = ";

         cin>>n;

         if(n<3 || n>12)
        {
           gotoxy(12,25);
           cout<<"Error : Wrong Input. Press <Esc> to exit or any other key";

           gotoxy(12,26);
           cout<<"        to try again.";

           n=int(getche( ));

           if(n==27)
              exit(0);
        }
      }
       while(n<3 || n>12);

       gotoxy(6,16);
       cout<<"Enter the value of x0 = ";

       cin>>x0;

       gotoxy(6,18);
       cout<<"Enter the value of h = ";

       cin>>h;

       gotoxy(6,24);
       cout<<"Input Mode :";

       gotoxy(6,25);
       cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍ";

       gotoxy(8,28);
       cout<<"Press : ";

       gotoxy(10,30);
       cout<<"- 'Y' or <Enter> to enter function";

       gotoxy(10,32);
       cout<<"- 'N' or <Any other key> to enter values of the function";

       gotoxy(8,35);
       cout<<"Enter your choice : ";

       char Choice=NULL;

       Choice=getch( );

       if(Choice=='y' || Choice=='Y' || int(Choice)==13)
      {
         choice=1;

         gotoxy(28,35);
         cout<<"Y";
      }

       else
      {
         gotoxy(28,35);
         cout<<"N";
      }

       gotoxy(25,43);
       cout<<"Press any key to continue...";

       getch( );

       if(choice)
      {
         clear_screen( );

         gotoxy(6,11);
         cout<<"Non-Linear Function :";

         gotoxy(6,12);
         cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

         gotoxy(6,37);
         cout<<"Note : Write the function with proper Braces ( ) e.g; 2x+3 as (2*x)+3";

         gotoxy(6,40);
         cout<<"Available Operators  :  ^ (raised to power) , * , / , + , -";

         gotoxy(6,42);
         cout<<"Available Operands   :  x , e , sinx , cosx , tanx , lnx , logx ,";

         gotoxy(6,44);
         cout<<"                        n = any number";

         gotoxy(6,14);
         cout<<"Enter the Function : f(x) = ";

         cin>>Fx;

         gotoxy(6,17);
         cout<<"Enter the Differential Function : f'(x) = ";

         cin>>Dfx;

         convert_ie_to_pe(Fx,0);
         convert_ie_to_pe(Dfx,1);
      }

       clear_screen( );

       gotoxy(6,9);
       cout<<"Data Points & Values of Function :";

       gotoxy(6,10);
       cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

       gotoxy(25,12);
       cout<<"ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿";

       gotoxy(25,13);
       cout<<"³       x       ³     f(x)      ³";

       gotoxy(25,14);
       cout<<"ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´";

       gotoxy(25,15);
       cout<<"³               ³               ³";

       for(int count_1=0;count_1<n;count_1++)
      {
         gotoxy(25,(wherey( )+1));
         cout<<"³               ³               ³";

         gotoxy(25,(wherey( )+1));
         cout<<"³               ³               ³";
      }

       gotoxy(25,(wherey( )+1));
       cout<<"ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ";

       xn[0]=x0;

       for(int count_2=0;count_2<(n-1);count_2++)
      xn[(count_2+1)]=(xn[count_2]+h);

       gotoxy(25,16);

       for(int count_3=0;count_3<n;count_3++)
      {
         gotoxy(27,wherey( ));
         cout<<xn[count_3];

         if(choice)
        {
           fx[count_3]=evaluate_postfix_expression(xn[count_3],0);

           gotoxy(43,wherey( ));
           cout<<fx[count_3];
        }

         else
        {
           gotoxy(43,wherey( ));
           cin>>fx[count_3];
        }

         if(choice)
        gotoxy(25,(wherey( )+2));

         else
        gotoxy(25,(wherey( )+1));
      }

       gotoxy(25,43);
       cout<<"Press any key to continue...";

       getch( );
    }

 /*************************************************************************///-------------------  get_index(const long double)  --------------------///*************************************************************************/constint get_index(constlongdouble x)
    {
       for(int count=0;count<n;count++)
      {
         if(xn[count]==x)
        break;
      }

       return count;
    }

 /*************************************************************************///----------------------------  estimate_dfx( )  ------------------------///*************************************************************************/void estimate_dfx( )
    {
       clear_screen( );

       gotoxy(6,9);
       cout<<"Centeral Difference Formula of Order 2 :";

       gotoxy(6,10);
       cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

       gotoxy(8,13);
       cout<<"f'(x) ÷ [f(x+h)-f(x-h)]/2h";

       gotoxy(6,17);
       cout<<"Estimation of f'(x) :";

       gotoxy(6,18);
       cout<<"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ";

       char Choice=NULL;

       longdouble x=0;
       longdouble dfx=0;
       longdouble actual_dfx=0;

       int error_flag=0;

       do
      {
         Choice=NULL;

         x=0;
         dfx=0;
         actual_dfx=0;
         error_flag=0;

         gotoxy(10,20);
         cout<<"Enter the value of x = ";

         cin>>x;

         if(x<=xn[0] || x>=xn[(n-1)])
        {
           error_flag=1;

           gotoxy(10,23);
           cout<<"Error: Please enter x greater than x(0) and less than x(n).";
        }

         else
        {
           int index=0;

           index=get_index(x);

           longdouble fxph=fx[(index+1)];
           longdouble fxmh=fx[(index-1)];

           dfx=((fxph-fxmh)/(2*h));

           gotoxy(10,23);
           cout<<"The estimated value of f'("<<x<<")  ÷  "<<dfx;
        }

         if(choice && !error_flag)
        {
           actual_dfx=evaluate_postfix_expression(x,1);

           gotoxy(10,25);
           cout<<"The Actual value of f'("<<x<<")  =  "<<actual_dfx;

           gotoxy(10,28);
           cout<<"Absolute Error = E(abs) =  "<<fabs((actual_dfx-dfx));
        }

         gotoxy(15,42);
         cout<<"Press <Esc> to exit or any other key to continue...";

         Choice=getch( );

         if(int(Choice)!=27)
        {
           gotoxy(10,20);
           cout<<"                                                    ";

           gotoxy(10,23);
           cout<<"                                                              ";

           gotoxy(10,25);
           cout<<"                                                    ";

           gotoxy(10,28);
           cout<<"                                                    ";

           gotoxy(15,42);
           cout<<"                                                    ";
        }

         elseif(int(Choice)==27)
        exit(0);
      }
       while(1);
    }
 # 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 <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <process.h>

int main()
{
    char state = '0';
    char ch = NULL;
    char token[20]={NULL};
    char stt[3][2]= {NULL, '2',
             '0', '1',
             '1', '1'};
    cout<<"Input integer value : ";
    cin>>token;

    for(int i=0; token[i] != NULL; i++)
    {
        if(isdigit(token[i]))
        {
            ch='2';
        }
        else
        {
            printf("Invalide value");
            getchar();
            exit(0);
        }
        for(int j=1; j<3 && ch != stt[0][j]; j++);
        for(int k=1; k<2 && state != stt[k][0]; k++);
        state=stt[k][j];

    }
    printf("Valide value");  
    getchar();
    return 0;
}
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);
    }

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();
}
on Friday, 10 January 2014
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
struct employee
{
char name[20],sex[7],id[10];
float income,tax,penstion,netincome,allowance;
};
employee *accept(employee a[],int n);
employee *tax(employee a[],int n);
inline employee *penstion(employee a[],int n);
inline employee *netincome(employee a[],int n);
void putdata(employee a[],int n,ofstream &of);
void getdata(ifstream &in);
void main ()
{
clrscr ();
ofstream of;
ifstream in;
employee *s;
int n;
int choice;
char ch;
do
{
clrscr ();
cout<<endl;
cout<<endl;
cout<<"Please choose from the following: \n";
cout<<"\t1. write Data. \n";
cout<<"\t2. read Data. \n";
cout<<"\t3. Quit. \n";
cout<<endl;
cout<<"Your choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"how many Employees' detail data";
cout<<"do you want yo feed:\n";
cin>>n;
s=new employee[n];
s=accept(s,n);
s=tax(s,n);
s=penstion(s,n);
s=netincome(s,n);
putdata(s,n,of);
break;
case 2:
getdata(in);
break;
case 3:
break;
default:
cout<<"\tInvalid entry!"<<endl;
}
cout<<"\nWould you like to try again (y/n): ";
cin>>ch;

}
while(ch == 'y' || ch == 'Y');
delete []s;
getch ();
}
employee *accept(employee a[],int n)
{
cout<<"please enter the employee detail:name,sex,id,income,allowance: \n";
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<"feed employee"<<" "<<(i+1)<<" "<<"detail data:\n";
cin>>a[i].name>>a[i].sex>>a[i].id>>a[i].income>>a[i].allowance;
}
return a;
}
employee *tax(employee a[],int n)
{
for(int i=0;i<n;i++)
{
if(a[i].income<=150)
a[i].tax=0;
else if (a[i].income<=650)
a[i].tax=(a[i].income*10/100)-15;
else if (a[i].income<=1400)
a[i].tax=((a[i].income*15/100)-47.5);
else if (a[i].income<=2350)
a[i].tax=((a[i].income*20/100)-117.5);
else if(a[i].income<=3550)
a[i].tax=((a[i].income*25/100)-235);
else if (a[i].income<=5000)
a[i].tax=((a[i].income*30/100)-412.5);
else
a[i].tax=((a[i].income*35/100)-662);
}
return a;
}
employee *penstion(employee a[],int n)
{
for (int i=0;i<n;i++)
a[i].penstion=(a[i].income*6/100);
return a;
}
employee *netincome(employee a[],int n)
{
for(int i=0;i<n;i++)
a[i].netincome=(a[i].income+a[i].allowance-a[i].tax-a[i].penstion);
return a;
}
void putdata(employee a[],int n,ofstream &of)
{
of.open("xyz.txt",ios::out|ios::app);
if(of.fail())
{
cerr<<"unable to open /n";
return;
}
for(int i=0;i<n;i++)
{
of<<a[i].name<<"\t"<<a[i].sex<<"\t"<<a[i].id<<"\t"<<a[i].income<<"\t";
of<<a[i].tax<<"\t"<<a[i].penstion<<"\t"<<a[i].allowance<<"\t"<<a[i].netincome;
}
of.close();
}
void getdata(ifstream &in)
{
cout<<"....................................................................\n";
cout<<"E_Name \tSex\tID\tIncome\tTax\tPenst.\tAllow.\tNetI.\n";
cout<<"....................................................................\n";
in.open("xyz.txt");
employee p;
if(in)
{
while(!in.eof())
{
in>>p.name>>p.sex>>p.id>>p.income;
in>>p.tax>>p.penstion>>p.allowance>>p.netincome;
if(in.eof())
break;
cout<<p.name<<"\t"<<p.sex<<"\t"<<p.id<<"\t"<<p.income<<"\t"<<p.tax;
cout<<"\t"<<p.penstion<<"\t"<<p.allowance<<"\t"<<p.netincome;
cout<<endl;
}
in.close();
}
else
cerr<<"unable to open /n";
}