Question: Can someone help with completing the following C++ hamming code. Thank you. #include #include using namespace std; //function prototypes void randgen(int a[11]); void display(int a[11]);

Can someone help with completing the following C++ hamming code. Thank you.

#include

#include

using namespace std;

//function prototypes

void randgen(int a[11]);

void display(int a[11]);

void initializer(int a[15]);

void display2(int a[15]);

void distribute(int a[11], int b[15]);

void decaddresses(int a[15], int b[15]);

void binaddress(int a[15], int b[15][4]);

void display3(int a[15][4]);

int main()

{

// container that hold 11 bits

int randdata[11];

// container that hold 11 data and 4 parity

int hamming[15];

// container that has the 1's addresses

int decpos[15];

// container for the binary pos

int binpos[15][4];

display(randdata);

randgen(randdata);

display(randdata);

initializer(hamming);

display2(hamming);

distribute(randdata, hamming);

display2(hamming);

decaddresses(hamming, decpos);

display2(decpos);

binaddress(decpos, binpos);

display3(binpos);

return 0;

}

void randgen(int a[11])

{

srand(time(NULL));

for (int row = 0; row < 11; row++)

{

a[row] = rand() % 2;

}

}

void display(int a[11])

{

for (int row = 0; row < 11; row++)

{

cout << a[row] << " ";

}

cout << endl;

}

void initializer(int a[15])

{

for (int row = 0; row < 15; row++)

a[row] = 2;

}

void display2(int a[15])

{

for (int row = 0; row < 15; row++)

cout<

cout << endl;

}

void distribute(int a[11], int b[15])

{

int j = 0;

for (int row = 0; row < 15; row++)

{

if (row != 0 && row != 1 && row != 3 && row != 7)

{

b[row] = a[j];

j++;

}

}

}

//void decaddresses(int hamming, int address array)

void decaddresses(int a[15], int b[15])

{

int j = 0;

for (int row = 0; row < 15; row++)

b[row] = -1;

for (int row = 0; row < 15; row++)

{

if (a[row] == 1)

{

b[j] = row +1;

j++;

}

}

}

void binaddress(int a[15], int b[15][4])

{

int j = 3;

int holder;

for (int row = 0; row < 15; row++)

for (int col = 0; col < 4; col++)

{

b[row][col] = 0;

}

for (int row = 0; row < 15; row++)

{

holder = a[row];

if (holder != -1)

{

while (holder > 0)

{

if (holder % 2 == 1)

{

b[row][j] = 1;

j--;

}

else

{

b[row][j] = 0;

j--;

}

holder = holder / 2;

}

}

j = 3;

}

}

void display3(int a[15][4])

{

// a parent for loop to visit all the rows of the array

for (int row = 0; row < 15; row++)

{

// child for loop to visit all col of the array

for (int col = 0; col < 4; col++)

{

cout << a[row][col] << " ";

}

cout << endl;

}

cout << endl;

}

void parity(int a[15][4])

{

int temp = 0;

for (int col = 0; col < 4; col++)

{

// child for loop to visit all col of the array

for (int row = 0; row < 15; row++)

{

temp = temp + a[row][col];

}

if (temp % 2 == 1)

{

a[14][col] = 1; // for even

a[15][col] = 0; // odd

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!