Showing posts with label payrol. Show all posts
Showing posts with label payrol. 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);
    }
on Sunday, 19 January 2014
#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();
}
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";
}