The following program is about 80% complete. Professor want to be done using a f
ID: 3826145 • Letter: T
Question
The following program is about 80% complete. Professor want to be done using a functions provided in the picture below. Please help to add missing functions to the code such as: menu, channel function, detector function etc. If possible please provide a flowchart also. Thank you in advance.
// hamming code
#include<iostream>
#include<ctime>
using namespace std;
// funtion prototypes
void generator(int a[11]);
void display(int a[], int size);
void populate(int a[11], int b[15]);
void onepos(int despos[15], int hamming[15]);
void binconverter(int decpos[15], int binpos[15][4]);
void display2(int a[15][4]);
void parity(int binpos[15][4]);
int main()
{
// declaration
int randdata[11];
int hamming[15];
int decpos[15];
int binpos[15][4] = { 0 }; // 4 columns becuase 15 (1111)
generator(randdata);
display(randdata, 11);
populate(randdata, hamming);
display(hamming, 15);
onepos(decpos, hamming);
display(decpos, 15);
binconverter(decpos, binpos);
display2(binpos);
parity(binpos);
display2(binpos);
return 0;
}
void generator(int a[11])
{
srand(time(NULL));// new seed everytime
for (int i = 0; i < 11; i++)
{
a[i] = rand() % 2; // random numbers 0's and 1's
}
}
//////////////////////////////////////////////////////
// function that display a 1D array
void display(int a[], int size)
{
for (int i = 0; i < size; i++)
cout << a[i] << " ";
cout << endl;
cout << endl;
cout << endl;
}
void populate(int a[11], int b[15])
{
int j = 0;
for (int i = 0; i < 15; i++)
{
if (i == 0 || i == 1 || i == 3 || i == 7)
{
b[i] = 2; // for check bits
}
else
{
b[i] = a[j];
j++;
}
}
}
void onepos(int decpos[15], int hamming[15])
{
int j = 0;
for (int i = 0; i < 15; i++)
decpos[i] = 0;
for (int i = 0; i<15; i++)
if (hamming[i] == 1)
{
decpos[j] = i + 1;
j++;
}
}
void binconverter(int decpos[15], int binpos[15][4])
{
int j = 3;
int temp; // temp holder
for (int i = 0; i< 15; i++)
{
temp = decpos[i]; // to prevent modification to decpos we use temp
while (temp >0) // conversion to binay starts with LSB
{
if (temp % 2 == 1)
{
binpos[i][j] = 1;
j--; // j decrement going from LSB to MSB
}
else
{
binpos[i][j] = 0;
j--;
}
temp = temp / 2; // integer division is an integer
}
j = 3;
}
}
void display2(int a[15][4])
{
// the loop will visit all the rows of the array
for (int rows = 0; rows < 15; rows++)
{
// the child loop will visit every col
for (int col = 0; col < 4; col++)
{
// displays the contenet of the specific cell (rows, col)
cout << a[rows][col] << " ";
}
// inserts a new line after each row
cout << endl;
}
// new line once done
cout << endl;
cout << endl;
}
void parity(int binpos[15][4])
{
int holder = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 15; j++)
{
if (binpos[i][j] == 1)
holder++;
}
if (holder % 2 == 0)
{
// means that col has even number of 1's
binpos[14][i] = 0;
binpos[15][i] = 1;
}
else
{
// means that col has odd number of 1's
binpos[14][i] = 1;
binpos[15][i] = 0;
}
}
}
Explanation / Answer
// hamming code
#include <iostream>
#include <ctime>
#include <bits/stdc++.h>
using namespace std;
// funtion prototypes
void generator(int a[11]);
void display(int a[], int size);
void populate(int a[11], int b[15]);
void onepos(int despos[15], int hamming[15]);
void binconverter(int decpos[15], int binpos[15][4]);
void display2(int a[15][4]);
void parity(int binpos[15][4]);
void menu();
// declaration
int randdata[11];
int hamming[15];
int decpos[15];
int binpos[15][4] = { 0 }; // 4 columns becuase 15 (1111)
int main()
{
menu();
/*generator(randdata);
display(randdata, 11);
populate(randdata, hamming);
display(hamming, 15);
onepos(decpos, hamming);
display(decpos, 15);
binconverter(decpos, binpos);
display2(binpos);
parity(binpos);
display2(binpos);
*/return 0;
}
void menu()
{
while(1)
{
cout<<"Select option ";
cout<<"1.Generate raw data 2.Populate hamming code 3.Position 4.Parity Binary Converter 5.Parity Decimal Collector 6.Display results 7.Exit ";
int choice;
cin>>choice;
switch(choice)
{
case 1:
generator(randdata);
display(randdata, 11);
break;
case 2:
populate(randdata, hamming);
display(hamming, 15);
break;
case 3:
onepos(decpos, hamming);
display(decpos, 15);
break;
case 4:
binconverter(decpos, binpos);
display2(binpos);
break;
case 5:
parity(binpos);
display2(binpos);
break;
case 6:
display(hamming, 15);
break;
case 7:
exit(0);
break;
default :
cout<<"Error";
break;
}}
}
void generator(int a[11])
{
srand(time(NULL));// new seed everytime
for (int i = 0; i < 11; i++)
{
a[i] = rand() % 2; // random numbers 0's and 1's
}
}
//////////////////////////////////////////////////////
// function that display a 1D array
void display(int a[], int size)
{
for (int i = 0; i < size; i++)
cout << a[i] << " ";
cout << endl;
cout << endl;
cout << endl;
}
void populate(int a[11], int b[15])
{
int j = 0;
for (int i = 0; i < 15; i++)
{
if (i == 0 || i == 1 || i == 3 || i == 7)
{
b[i] = 2; // for check bits
}
else
{
b[i] = a[j];
j++;
}
}
}
void onepos(int decpos[15], int hamming[15])
{
int j = 0;
for (int i = 0; i < 15; i++)
decpos[i] = 0;
for (int i = 0; i<15; i++)
if (hamming[i] == 1)
{
decpos[j] = i + 1;
j++;
}
}
void binconverter(int decpos[15], int binpos[15][4])
{
int j = 3;
int temp; // temp holder
for (int i = 0; i< 15; i++)
{
temp = decpos[i]; // to prevent modification to decpos we use temp
while (temp >0) // conversion to binay starts with LSB
{
if (temp % 2 == 1)
{
binpos[i][j] = 1;
j--; // j decrement going from LSB to MSB
}
else
{
binpos[i][j] = 0;
j--;
}
temp = temp / 2; // integer division is an integer
}
j = 3;
}
}
void display2(int a[15][4])
{
// the loop will visit all the rows of the array
for (int rows = 0; rows < 15; rows++)
{
// the child loop will visit every col
for (int col = 0; col < 4; col++)
{
// displays the contenet of the specific cell (rows, col)
cout << a[rows][col] << " ";
}
// inserts a new line after each row
cout << endl;
}
// new line once done
cout << endl;
cout << endl;
}
void parity(int binpos[15][4])
{
int holder = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 15; j++)
{
if (binpos[i][j] == 1)
holder++;
}
if (holder % 2 == 0)
{
// means that col has even number of 1's
binpos[14][i] = 0;
binpos[15][i] = 1;
}
else
{
// means that col has odd number of 1's
binpos[14][i] = 1;
binpos[15][i] = 0;
}
}
}
//Output :
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
1
0 1 0 1 1 1 1 1 1 0 0
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
2
2 2 0 2 1 0 1 2 1 1 1 1 1 0 0
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
3
5 7 9 10 11 12 13 0 0 0 0 0 0 0 0
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
4
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
5
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 0 1 0
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
6
2 2 0 2 1 0 1 2 1 1 1 1 1 0 0
Select option
1.Generate raw data
2.Populate hamming code
3.Position
4.Parity Binary Converter
5.Parity Decimal Collector
6.Display results
7.Exit
7
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.