Hi,
Here is the updated C++ code for Checksum.
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
cout<<” — CHECKSUM — \n”;
int n,i,ro,in,j,ro1;
cout<<“\nEnter the number of bits in the multiple of 4: “;
cin>>n;
if(n%4==0)
{
int data[n];
cout<<“Enter the data bits: \n”;
for(i=0;i<n;i++)
cin>>data[i];
ro=n/4;
int sum[ro][4]; //Creating a 2D array
in=0;
for(i=0;i<ro;i++)
{
for(j=0;j<4;j++)
{
sum[i][j]=data[in]; //Storing the data bits into the array
in++;
}
}
cout<<“\n\nThe information bits are: \n”;
for(i=0;i<n;i++)
{
cout<<data[i]<<“\t”;
}
cout<<“\n\nThe bits in a seqence is: \n”;
for(i=0;i<ro;i++)
{
for(j=0;j<4;j++)
{
cout<<sum[i][j]<<“\t”;
}
cout<<endl;
}
int par[4]; //Bits to be added
for(i=0;i<4;i++)
{
int ss=0;
for(j=0;j<ro;j++)
{
ss=ss+sum[j][i];
}
if(ss%2==0)
{ par[i]=0; }
else
{ par[i]=1; }
}
cout<<“—————————–\n”;
for(i=0;i<4;i++)
{
cout<<par[i]<<“\t”;
}
cout<<“\t(Checking through even parity)\n”;
int com1[4];
int send[n+4];
int x=n;
for(i=0;i<4;i++)
{
if(par[i]%2==0)
{
com1[i]=1; }
else
{ com1[i]=0; }
}
cout<<“—————————–\n”;
for(i=0;i<4;i++)
{
cout<<com1[i]<<“\t”;
}
cout<<“\t(Taking 1’s Complement)\n”;
cout<<“\nData to be sent\n”;
for(i=0;i<4;i++)
cout<<com1[i];
for(i=0;i<n;i++)
cout<<data[i];
int z=n+4;
int rec[z];
cout<<“\n\nEnter the received data: \n”;
for(i=0;i<z;i++)
cin>>rec[i];
ro1=z/4;
int sum1[ro1][4];
in=0;
for(i=0;i<ro1;i++)
{
for(j=0;j<4;j++)
{
sum1[i][j]=rec[in];
in++;
}
}
cout<<“\n\nThe bits in a seqence is: \n”;
for(i=0;i<ro1;i++)
{
for(j=0;j<4;j++)
{
cout<<sum1[i][j]<<“\t”;
}
cout<<endl;
}
int par1[4];
for(i=0;i<4;i++)
{
int ss=0;
for(j=0;j<ro1;j++)
{
ss=ss+sum[j][i];
}
if(ss%2==0)
{ par1[i]=0; }
else
{ par1[i]=1; }
}
cout<<“—————————–\n”;
for(i=0;i<4;i++)
{
cout<<par1[i]<<“\t”;
}
cout<<“\t(Checking through even parity)\n”;
if(par1[0]==1 && par1[1]==1 && par1[2]==1 && par1[3]==1)
cout<<“\nNo Error”;
else
cout<<“\nError”;
cout<<“\n\n\n @ KIDS Labs\n”;
}
else
cout<<“\n\nMessage:\nYou are not entering the correct value”;
cout<<“\n\n\n @ KIDS Labs\n”;
getch();
}
Thank you