Thursday, 28 April 2011

DLL for Calcutor using VC++ code & VB Interface......



/****************** PKDLL.cpp ********************/


// PKDDL.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "math.h"

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
)
{
    return TRUE;
}

double _stdcall berij(double x,double y)
{
return x+y;
}
double _stdcall vajabaki(double x,double y)
{
return x-y;
}
double _stdcall gunakar(double x,double y)
{
return x*y;
}
double _stdcall bhagakar(double x,double y)
{
return x/y;
}
double _stdcall logicaland(long x,long y)
{
return x & y;
}
double _stdcall logicalor(long x,long y)
{
return x | y;
}
double _stdcall logicalxor(long x,long y)
{
return (x & (~y)) | (y & (~x));
}
double _stdcall modd(long x,long y)
{
return x % y;
}
double _stdcall xchay(double x,double y)
{
return(pow(x,y));
}
double _stdcall xchaydon(double x)
{
return(pow(x,2));
}
double _stdcall xchayteen(double x)
{
return(pow(x,3));
}
double _stdcall xchaynimma(double x)
{
return(pow(x,0.5));
}
double _stdcall xchaytippat(double x)
{
return(pow(x,0.3333333333333333333333333333333334));
}
double _stdcall onebyx(double x)
{
return(1/x);
}
double _stdcall xfact(double x)
{
int i,j;
j=1;
for(i=1;i<=x;i++)
j=i*j;
return(j);
}
double _stdcall echax(double x)
{
return(pow(2.71828,x));
}
double _stdcall xsindeg(double x)
{
return(sin(x*0.01745555555555555555555555555556));
}
double _stdcall xcosdeg(double x)
{
return(cos(x*0.01745555555555555555555555555556));
}
double _stdcall xtandeg(double x)
{
return(tan(x*0.01745555555555555555555555555556));
}


double _stdcall xlog(double x)
{
return(log(x));
}
double _stdcall xlogten(double x)
{
return(log10(x));
}
double _stdcall xsinrad(double x)
{
return(sin(x));
}
double _stdcall xcosrad(double x)
{
return(cos(x));
}
double _stdcall xtanrad(double x)
{
return(tan(x));
}
/******************* PKDLL.def *******************/
LIBRARY PKDDL

EXPORTS
berij @1
vajabaki @2
gunakar @3
bhagakar @4
logicaland @5
logicalor @6
logicalxor @7
modd @8
xchay @9
xchaydon @10
xchayteen @11
xchaynimma @12
xchaytippat @13
onebyx @14
echax @15
xfact @16
xsindeg @17
xcosdeg @18
xtandeg @19
xsinrad @20
xcosrad @21
xtanrad @22
xlog @23
xlogten @24
/******************** calci.vbp ********************/
Dim op As Integer
Dim a As Variant
Private Declare Function berij Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double, ByVal Y As Double) As Double
Private Declare Function vajabaki Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double, ByVal Y As Double) As Double
Private Declare Function gunakar Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double, ByVal Y As Double) As Double
Private Declare Function bhagakar Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double, ByVal Y As Double) As Double
Private Declare Function logicaland Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Long, ByVal Y As Long) As Double
Private Declare Function logicalor Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Long, ByVal Y As Long) As Double
Private Declare Function logicalxor Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Long, ByVal Y As Long) As Double
Private Declare Function modd Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Long, ByVal Y As Long) As Double
Private Declare Function xchay Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double, ByVal Y As Double) As Double
Private Declare Function xchaydon Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xchayteen Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xchaynimma Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xchaytippat Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function onebyx Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function echax Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xfact Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xsindeg Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xcosdeg Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xtandeg Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xsinrad Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xcosrad Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xtanrad Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xlog Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Declare Function xlogten Lib "C:\TE-A-37\PKDDL\PKDDL\Debug\PKDDL.dll" (ByVal X As Double) As Double
Private Sub Command1_Click(Index As Integer)
    If (Index <> 10) Then
        Text1.Text = Text1.Text & Index
    Else
        Text1.Text = Text1.Text & "."
    End If
End Sub

Private Sub Command2_Click(Index As Integer)
    a = Val(Text1.Text)
    Select Case Index
        Case 8: Text1.Text = xchaydon(a)
                GoTo baher
        Case 9: Text1.Text = xchayteen(a)
                GoTo baher
        Case 10: Text1.Text = xchaynimma(a)
                GoTo baher
        Case 11: Text1.Text = xchaytippat(a)
                GoTo baher
        Case 12: Text1.Text = onebyx(a)
                GoTo baher
        Case 14: Text1.Text = xfact(a)
                GoTo baher
        Case 15: Text1.Text = echax(a)
                GoTo baher
        Case 16:
                If (Option1.Value = True) Then
                    Text1.Text = xsindeg(a)
                Else
                    Text1.Text = xsinrad(a)
                End If
                GoTo baher
        Case 17:
                If (Option1.Value = True) Then
                    Text1.Text = xcosdeg(a)
                Else
                    Text1.Text = xcosrad(a)
                End If
                GoTo baher
        Case 18:
                If (Option1.Value = True) Then
                    Text1.Text = xtandeg(a)
                Else
                    Text1.Text = xtanrad(a)
                End If
                GoTo baher
        Case 19: Text1.Text = xlog(a)
                GoTo baher
        Case 20: Text1.Text = xlogten(a)
                GoTo baher
        Case 21: Text1.Text = 3.142
                GoTo baher
        Case 22: Text1.Text = (-1) * a
                GoTo baher
    End Select
    op = Index
    Text1.Text = ""
baher:
End Sub

Private Sub Command3_Click()
    Select Case op
        Case 0: Text1.Text = berij(a, Val(Text1.Text))
        Case 1: Text1.Text = vajabaki(a, Val(Text1.Text))
        Case 2: Text1.Text = gunakar(a, Val(Text1.Text))
        Case 3: Text1.Text = bhagakar(a, Val(Text1.Text))
        Case 4: Text1.Text = logicaland(a, Val(Text1.Text))
        Case 5: Text1.Text = logicalor(a, Val(Text1.Text))
        Case 6: Text1.Text = logicalxor(a, Val(Text1.Text))
        Case 7: Text1.Text = modd(a, Val(Text1.Text))
        Case 13: Text1.Text = xchay(a, Val(Text1.Text))
   End Select
End Sub

Private Sub Command4_Click()
    Text1.Text = ""
End Sub

Private Sub Command5_Click()
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Text1_Change()
    Text1.Locked = True
End Sub
/***************** Form Design *****************/

Page Replacement Algorithms..........


/****************************************
* TE-A-37 Date:-  /  /2011
* Assignment No:-
Page Replacement Algorithms:-
(1) FIFO
(2) Least Recent Unit (LRU)
(3) Optimal Page Replacement (OPT)
****************************************/
#include<stdio.h>
#include<process.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<op.h>
/****************************************/
int i,ii,j,k,q[3],l,m,gd,gm,value,mybrk,row,col;
int prio[4],temp[4],level,arr[96],optsize;
int optindex,check[3],grow[96],pos,jj,posval;
int flag1,flag2,flag3,ch,pgfault;
char *aaa,pk;
/********************/
void draw(int x,int y)
{
   row=x;
   do
   {
      col=19;
      do
      {
line(col,row,col+40,row);
col=col+80;
}while(col<=619);
      row=row+30;
   }while(row<=y);
}
/********************/
void redraw()
{
   for(i=19;i<=619;i=i+40)
line(i,79,i,169);
   for(i=19;i<=619;i=i+40)
line(i,219,i,309);
   for(i=19;i<=619;i=i+40)
line(i,359,i,449);
   draw(79,169);
   draw(219,309);
   draw(359,449);
   outtextxy(30,30,"Enter 999 to exit...");
}
void start()
{
   detectgraph(&gd,&gm);
   initgraph(&gd,&gm,"c:\\tc\\bgi");
   for(i=0;i<=2;i++)
q[i]=check[i]=999;
   level=0;
   mybrk=0;
   optindex=0;
}

void end()
{
ii=0;
level=level+1;
if(level==3)
{
  level=0;
  cleardevice();
}
}
void print()
{
for(m=0;m<=2;m++)
{
  k=q[m];
  if(k!=999)
  {
     sprintf(aaa,"%d",k);
     outtextxy((ii*80)+10+19,(m*30)+10+79+(140*level),aaa);
  }
}
ii=ii+1;
}
void opt()
{
   cout<<"\n Enter Size of OPT Tape :- ";cin>>optsize;
   cout<<"\n Enter Elements :- ";
   pos=0;
   for(i=0;i<optsize;i++)
cin>>arr[i];
   clrscr();
   getch();
   start();
   for(;;)
   {
      ii=0;
      redraw();
      do
      {
jj=0;pos=0;
k=value=arr[optindex];
sprintf(aaa,"%d",arr[optindex]);
outtextxy(20+(ii*80)+10,60+(139*level),aaa);
for(i=0;i<=2;i++)
  if(q[i]==value)
  {
     outtextxy((ii*80)+10+19,90+10+79+(140*level),"N.F");
     goto A;
  }
outtextxy((ii*80)+10+19,90+10+79+(140*level),"F");
pgfault=pgfault+1;
for(j=0;j<=2;j++)
check[j]=q[j];
for(j=optindex+1;j<optsize;j++)
{
grow[jj]=arr[j];
jj=jj+1;
}
flag1=flag2=flag3=0;
for(j=0;j<jj;j++)
{
if(flag1!=1)
if(check[0]==grow[j])
{
if(j>pos)
{
pos=j;
posval=check[0];
}
flag1=1;
}
if(flag2!=1)
if(check[1]==grow[j])
{
if(j>pos)
{
pos=j;
posval=check[1];
}
flag2=1;
}
if(flag3!=1)
if(check[2]==grow[j])
{
if(j>pos)
{
pos=j;
posval=check[2];
}
flag3=1;
}
}
if(flag1!=1)
{
posval=check[0];
goto Exit;
}
if(flag2!=1)
{
posval=check[1];
goto Exit;
}
if(flag3!=1)
{
posval=check[2];
goto Exit;
}
Exit:
for(j=0;j<3;j++)
if(q[j]==posval)
{
q[j]=value;
goto A;
}
A:
print();
optindex=optindex+1;
if(optindex>optsize)
goto Samapt;
getch();
}while(ii<8);
end();
}
   Samapt:
   sprintf(aaa,"%d",pgfault);
   outtextxy(100,470,"NO. Of Page Faults :- ");
   outtextxy(500,470,"...OPT...");
   outtextxy(300,470,aaa);
   SaveBMP16("c:\\op33.bmp");
   closegraph();
}
/********************/
void fifo()
{
   start();
   for(;;)
   {
      ii=0;
      redraw();
      do
      {
outtextxy(0,0,"   <== Enter Value...");
scanf("%d",&value);
k=value;
if(k==999)
  goto Samapt;
sprintf(aaa,"%d",k);
outtextxy(20+(ii*80)+10,60+(139*level),aaa);
for(i=0;i<=2;i++)
  if(q[i]==value)
  {
     outtextxy((ii*80)+10+19,90+10+79+(140*level),"N.F");
     goto A;
  }
l=mybrk%3;
mybrk=mybrk+1;
q[l]=value;
outtextxy((ii*80)+10+19,90+10+79+(140*level),"F");
pgfault=pgfault+1;
A:
print();
}while(ii<8);
end();
}
   Samapt: getch();
   sprintf(aaa,"%d",pgfault);
   outtextxy(100,470,"NO. Of Page Faults :- ");
   outtextxy(500,470,"...FIFO...");
   outtextxy(300,470,aaa);
   SaveBMP16("c:\\op1.bmp");
   closegraph();
}
/********************/
void lru()
{
   start();
   for(row=0;row<=3;row++)
prio[row]=999;
   for(;;)
   {
      mybrk=0;ii=0;
      redraw();
      do
      {
outtextxy(0,0,"   <== Enter Value...");
scanf("%d",&value);
k=value;
if(k==999)
  goto Samapt;
for(col=0;col<=3;col++)
  temp[col]=prio[col];
prio[0]=value;
j=1;
for(i=0;i<=2;i++)
{
  if(value!=temp[i])
  {
     prio[j]=temp[i];
     j=j+1;
  }
}
sprintf(aaa,"%d",k);
outtextxy(20+(ii*80)+10,60+(139*level),aaa);
for(i=0;i<=2;i++)
  if(q[i]==value)
  {
     outtextxy((ii*80)+10+19,90+10+79+(140*level),"N.F");
     goto A;
  }
for(i=0;i<=3;i++)
{
  if(prio[3]==q[i])
  {
     q[i]=value;
     goto BAHER;
  }
}
BAHER:
outtextxy((ii*80)+10+19,90+10+79+(140*level),"F");
pgfault=pgfault+1;
A:
print();
}while(ii<8);
end();
}
   Samapt: getch();
   sprintf(aaa,"%d",pgfault);
   outtextxy(100,470,"NO. Of Page Faults :- ");
   outtextxy(500,470,"...LRU...");
   outtextxy(300,470,aaa);
   SaveBMP16("c:\\op22.bmp");
   closegraph();
}
/********************/
void main()
{
   clrscr();
   do
   {
   pgfault=0;
   cout<<"\n ********** Menu **********";
   cout<<"\n (1) FIFO (2) LRU (3) OPT (4) Exit";
   cout<<"\n Enter Choice ==> ";
   cin>>ch;
   switch(ch)
   {
case 1: fifo();break;
case 2: lru();SaveBMP16("c:\\op2.bmp");break;
case 3: opt();SaveBMP16("c:\\op3.bmp");break;
case 4: exit(0);break;
   }
   clrscr();
   }while(ch!=4);
}
/********************** Output ************************/



Wednesday, 27 April 2011

Banker's Algorithm............


/******************************************************
Program :- Banker's Algorithm......
******************************************************/
#include<iostream.h>
#include<conio.h>
/******************************************************/
int procno,res,cnt,i,j,k,n,index;
int allocation[20][20],need[20][20],available[20],max[20][20],flag[20];
/******************************************************/
void input()
{
cout<<"\n Enter No. of Resources => ";cin>>res;
cout<<"\n Enter No. of Processes => ";cin>>procno;
cout<<"\n Enter Resources => ";
for(i=0;i<20;i++)
flag[i]=0;
for(i=0;i<res;i++)
{
cout<<"\n Resource R"<<i<<"=> ";
cin>>available[i];
}
cout<<"\n Enter Allocation Matrix => ";
for(i=0;i<procno;i++)
{
cout<<"\n Enter Instances for Process P"<<i<<" => ";
for(j=0;j<res;j++)
cin>>allocation[i][j];
}
cout<<"\n Enter Max Matrix => ";
for(i=0;i<procno;i++)
{
cout<<"\n Enter Instances for Process P"<<i<<" => ";
for(j=0;j<res;j++)
cin>>max[i][j];
}
}
/******************************************************/
void display()
{
clrscr();
cout<<"\n Allocation Matrix ==>  \n";
for(i=0;i<procno;i++)
{
cout<<"\n ";
for(j=0;j<res;j++)
cout<<"   "<<allocation[i][j];
}
cout<<"\n Max Matrix ==>  \n";
for(i=0;i<procno;i++)
{
cout<<"\n ";
for(j=0;j<res;j++)
cout<<"   "<<max[i][j];
}
for(i=0;i<procno;i++)
for(j=0;j<res;j++)
need[i][j]=max[i][j]-allocation[i][j];
cout<<"\n Need Matrix ==>  \n";
for(i=0;i<procno;i++)
{
cout<<"\n ";
for(j=0;j<res;j++)
cout<<"   "<<need[i][j];
}
cout<<"\n Available Matrix ==>  \n";
for(j=0;j<res;j++)
cout<<"   "<<available[j];
getch();
clrscr();
}
/******************************************************/
void calculate_available()
{
for(i=0;i<res;i++)
{
for(j=0;j<procno;j++)
available[i]=available[i]-allocation[j][i];
}
}
/******************************************************/
void bank()
{
cout<<"\n Sequence Of Program Execution => ";
k=0;
while(k<procno)
{
for(i=0;i<procno;i++)
{
cnt=0;
for(j=0;j<res;j++)
{
if(need[i][j]<=available[j])
cnt++;
index=i;
}
if(flag[i]==0 && cnt==3)
{
    cout<<"   "<<index;
    flag[i]=1;
    k++;
    for(j=0;j<procno;j++)
    available[j]=available[j]+allocation[i][j];
        goto A;
}
}
A:
}
}
/******************************************************/
void main()
{
clrscr();
input();
calculate_available();
display();
bank();
getch();
}