Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use lecture notes to develop a plan to design and finally implement a set of fun

ID: 3816195 • Letter: U

Question

Use lecture notes to develop a plan to design and finally implement a set of functions using C++ that would implement the HAMMING CODE. Phase 1 will include the literature write up, description of the HAMMING CODE and a complete description of the functions implemented including: l. Functions type void, or any data returning function 2. Type of data passed in to the functions (function parameters or arguments) 3. Type of function parameters (value or reference). 4. Global variables if needed. 5. HAMMING CODE layout and its individual parts (data, check bits) details. 6. Work out a full example from A to Z. SUGGESTED FUNCTIONS PLAN: MENU To display the user options... RAW DATA GENERATER To generate a random data using C ++ rand() ...etc. HAMMING PACKAGER Prepare the hamming package using data collected... etc. PARITY DECIMAL COLLECTOR Function to collect the addresses of the parity bits (check bits) ... etc. PARITY BINARY CONVERTER Function to convert the parity addresses from decimal to binary ... etc. CHANNEL FUNCTION Function to create noise and flips on of the bits in the hamming package ... etc. DETECTOR FUNCTION Function that detects the bit that arrived in error ...etc. DISPLAY Display the result ... etc.

Explanation / Answer

#include <iostream.h>
#include <conio.h>
#include <dos.h>

void main()
{
int m;
int r;
int db[30];

cout<<" Enter frame size:";
cin>>m;

int i,j,k;

cout<<" Enter Frame :";
for (i=0;i<m;i++)
{
cin>>db[i];
}

cout<<" Enter redundancy bits: ";
cin>>r;

  
cout<<" Frame : ";
for(i=0;i<m;i++)
{
cout<<db[i]<<" ";
}

  
int temp[30];
for (i=m-1,j=0;i>=0;i--,j++)
{
temp[j]=db[i];
}
for (i=0;i<m;i++)
{
db[i]=temp[i];
}


int nrb=0;
int rb[8];   

  
int l=0;
int df[30];   


k=1;
for(i=1,j=0;j<m;i++)
{

if(i==k)
{
df[i]=-1;
k=k*2;
nrb++;
}

else
{
df[i]=db[j];
j++;
}
l++;
}

cout<<" ";
cout<<" Frame after introducing redundancy bits : ";
for(i=l;i>0;i--)
{
cout<<df[i]<<" ";
}

  
int i1,i2,i3,i4,i5,i6,i7;
int a1[4],a2[4];

i5=0;

  
for(i1=1;i1<=l;i1++)
{

if(df[i1]==-1)
{
  
i4 = -1;

  
i7=i1;
while (i7>0)
{
i4++;
if(i7==1)
{
break;
}
else
{
i7=i7/2;
}
}

i3=0; // Consider even parity

//Calculating redundancy bit and parity
for(i2=1;i2<=l;i2++)
{
//reset a1 frame
for(i6=0;i6<4;i6++)
{
a1[i6]=-1;
}


i7=i2;
i6=0;
while(i7>0)
{
if(i7==1)
{
a1[i6]=1;
break;
}
else if(i7==0)
{
a1[i6]=0;
}
else
{
a1[i6]=i7%2;
i7=i7/2;
}
i6++;
}

if(a1[i4]==1)
{
if(df[i2]==1)
{
i3++;
}
}

}

if(i3%2==0)
{
df[i1]=0;
rb[i5]=0;
}
else
{
df[i1]=1;
rb[i5]=1;
}
i5++;

//Print current frame
cout<<" R"<<i5<<" = "<<rb[i5-1]<<" New Frame";
for(i2=l;i2>0;i2--)
{
cout<<" "<<df[i2];
}
}

}

//Get the error bit
int eb;
cout<<" ";
cout<<" Enter bit number where error is occurred: ";
cin>>eb;

cout<<" Bit at position "<<eb<<" is "<<df[eb];

//Change bit
if(df[eb]=1)
{
df[eb]=0;
}
else
{
df[eb]=1;
}

cout<<" and now changed to "<<df[eb];

// Print new frame after changing the bit
cout<<" New Frame is";
for(i=l;i>0;i--)
{
cout<<" "<<df[i];
}

//Recalculate everything

i5=0;
k=1;
//Scan Whole frame
for(i1=1;i1<=l;i1++)
{   
  
if (i1==k)
{

i4 = -1; //Hold position of 1


i7=i1;
while (i7>0)
{
i4++;
if(i7==1)
{
break;
}
else
{
i7=i7/2;
}
}

i3=0; // Consider even parity

//Calculating redundancy bit and parity
for(i2=1;i2<=l;i2++)
{
//reset a1 frame
for(i6=0;i6<4;i6++)
{
a1[i6]=-1;
}

//find binary conversion
i7=i2;
i6=0;
while(i7>0)
{
if(i7==1)
{
a1[i6]=1;
break;
}
else if(i7==0)
{
a1[i6]=0;
}
else
{
a1[i6]=i7%2;
i7=i7/2;
}
i6++;
}

//check that the binary conversion is having bit at specific position or not
//if yes calculate parity

if(a1[i4]==1)
{
if(df[i2]==1)
{
i3++;
}
}

}

if(i3%2==0)
{
df[i1]=0;
rb[i5]=0;
}
else
{
df[i1]=1;
rb[i5]=1;
}

i5++;

k=k*2;
}

}

cout<<" Redundancy bits:";
for(i=0;i<nrb;i++)
{
cout<<" "<<rb[i];
}

//Calculate error position
int ep=0;
for(i=0,j=1;i<nrb;i++)
{
if(rb[i]==1)
{
ep=ep+j;
}
j=j*2;
}

cout<<" Error is at : "<<ep;

getch();
}