Friday, March 4, 2011

CYCLIC REDUNDANCY CHECK PROGRAM


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int main() //int avgc,char *avgv[];
{
int val1[20],val2[20],val3[20],val4[20];
int x,i,j,n,m,a,s;
clrscr();
cout<<"enter no .of generating fu.bits";
cin>>n;
cout<<"\n";
cout<<" enter gen.fu";
cout<<"\n ";
for (i=0;i<n;i++)
{
cin>>val1[i];
}
cout<<"gen.fu";
cout<<"\n";
for(i=0;i<n;i++)
{
cout<<val1[i];
}
cout<<"\n";
cout<<" enter no .of bits of polynomial";
cout<<"\n";
cin>>n;
cout<<"enter polynomial ";
cout<<"\n";
for(i=0;i<m;i++)
{
cin>>val2[i];
val4[i]=val2[i];
}
cout<<"\n";
cout<<" polynomial";
cout<<"n";
for(i=0;i<m;i++)
{
cout<<val2[i];
}
cout<<"\n";
cout<<"\n";
for(i=m;i<m+n-1;i++)
{
val2[i]=0;
}
cout<<"\n";
cout<<"appened polynomial i";
for(i=0;i<m+n-1;i++)
{
cout<<val2[i];
}
a=m+(n-1);
for(i=0;i<m;i++)
{
if(val2[i]==0)
{
for(i=1;j<n+i;++j)
val2[j]=val2[j]^0;
}
else
{
val2[i]=val2[i]^val2[0];
val2[i+1]=val2[i+1]^val1[1];
val2[i+2]=val2[i+2]^val1[2];
val2[i+3]=val2[i+3]   ^val1[3];
}
}
cout<<"\n \t the crc is !";
for(i=m;i<a;++i)
cout<<val2[i];
for(i=m,j=m;j<a,i<m+n-1;j++,i++)
{
val4[i]=val2[j];
}
cout<<"crc matrix is :";
cout<<"\n";
for(i=0;i<m;i++)
{
if(val4[i]==0)
{
for(j=i;j<n+i;++j)
val4[j]=val4[i]^val1[0];
val4[i+1]=val4[i+1]^val1[1];
val4[i+2]=val4[i+2]^val1[2];
val4[i+3]=val4[i+3]^ val1[3];
}
}
cout<<"\n\t after error check is :";
for(i=m;i<a;i++)
{
cout<< val4[i];
}
cin>>x;
return 0;
}

CHARACTER STUFFING PROGRAM


#include<stdio.h>
#include<conio.h>
#include<string.h>
void start();
void end(char);
FILE *of;
FILE *cf;
int b,i=0;
char c,a='@',z='$',d[25];
void main()
{
clrscr();
cf=fopen("andy.txt","r");
of=fopen("ani.txt","w");
do
{
c=getc(cf);
d[i++]=c;
}while(c!=EOF);
fprintf(of,"%c",a);
for(i=0;i<strlen(d);i++)
{
if(d[i]==' '||d[i]=='\t')
{
end(d[i]);
}
else if(d[i]=='\n')
{
start();
}
else if(d[i]==EOF)
{
fprintf(of,"%c",z);
}
else
{
fprintf(of,"%c",d[i]);
}
}
printf("file sucessfully stuffed");
fclose(cf);
fclose(of);
getch();
}
void start()
{
fprintf(of,"%c\n",z);
fprintf(of,"%c",a);
}
void end(char k)
{
fprintf(of,"%c",z);
fprintf(of,"%c",a);
fprintf(of,"%c",k);
fprintf(of,"%c",z);
fprintf(of,"%c",a);
}

ROUND ROBIN


#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,t=0,s=1;
int a,q,x,*b;
clrscr();
printf("enter number of processes");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("process %d",i);
scanf("%d",&b[i]);
}
printf("enter time quantum");
scanf("%d",&q);
x=0;
for(i=1;i<=n;i++)
  t=t+b[i];
printf("total time is = %d\n",t);
for(i=0;i<=n;i++)
{
for(a=1;a<=n;a++)
{
if(b[a]>0)
{
if(b[a]<q && b[a]>0)
   x=x+b[a];
else
   x=x+q;
printf("current program is p %d...%d \n",a,x);
b[a]=b[a]-q;
s++;
}
}
}
getch();
}

PRIORITY SCHEDULING PROGRAM


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,r,s,t,x,d=0,p[20],b[20],pr[20];
clrscr();
printf("enter the no. of process");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("enter burst time %d:",i);
scanf("%d",b[i]);
}
for(i=1;i<=n;i++)
{
printf("priority %d",i);
scanf("%d",pr[i]);
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(pr[i]>pr[j])
{
r=p[j];
s=b[j];
t=pr[j];
p[j]=p[i];
b[j]=b[i];
pr[j]=pr[i];
p[i]=r;
b[i]=s;
pr[i]=t;
}
}
}
for(i=1;i<=n;i++)
{
x=x+b[i];
printf("process %d interval is from %d to %d",p[i],d,x);
d=x;
}
getch();
}