Help needed...B4 0930 hrs Fiji Time....PLIZZZ

Write a program using C++ as the programming language to implement the various line encoding scheme as listed in Table 4.1, pages 114-115, Forouzan's Data Communication and Networking except the multilevel schemes 2B1Q, 8B6T and 4D-PAM5. So there will 6 line coding schemes altogether that needs to be implemented.

1. Your program requests users to enter 8-bit word (digital data) to encode (convert) and then come up with the corresponding digital signal.

2. The 8-bit word should be in Hexadecimal format. This Hexadecimal word should then be converted to bits before applying a line encoding scheme.

3. Your program should allow the user to select a line coding scheme to use.

4. Based on the line coding scheme in #3, your program should then write to the screen as output either +1 for a positive, 0 for zero, and -1 for a negative voltage digital signals. To make your output readable separate these with appropriate spaces.

5. Program be repeated for a new 8-bit word.

Your program should show:

1. Proper coding practices/principles as you have learned in CS111 and CS112.

a. Proper layout/structure

b. Proper use of comments

c. Proper use of functions (may use)

2. Validate all input, in this case the Hexadecimals to represent the 8-bit word.

3. For each line coding, you must ask user to state assumptions such as the last signal has a positive voltage, negative voltage, or zero voltage. Program output should consider each assumption.

4. Run a number of Test Cases and take a snapshot of the corresponding output such as applying all implemented line codings to a single input word.

5. You may add details as you would prefer.

6. The instructions here are very general, so you are free to deicide to what extend in term of details you can implement each line encoding scheme.


I have done part of it and now am stuck.....pliz help...😔

#include
#include
#include
#include

using namespace std;

void Binary_print(int [], int);
void NRZ(int []);
void NRZL(int []);
void NRZI_pos(int []);
void RZ(int []);
void AMI_pos(int []);
void AMI_neg(int []);
const int maxibit = 4;//number of bits per hexadecimal figure

int main()
{
char input[2];//hexadecimal input
int x1[maxibit];// 4-bit binary conversion for first hexadecimal input
int x2[maxibit];// 4-bit binary conversion for second hexadecimal input
int array1, array2;
bool bool_arrayA,bool_arrayB;

cout << "Enter a 8-bit word (in Hexadecimal): ";
cin >> input[0] >> input[1];
cout << endl;

if (!(input[0] == 'a' || input[0] == 'A' || input[0] == 'b' || input[0] == 'B' || input[0] == 'c' || input[0] == 'C' || //validating first array element
input[0] == 'd' || input[0] == 'D' || input[0] == 'e' || input[0] == 'E' || input[0] == 'f' || input[0] == 'F' ||
input[0] == '0' || input[0] == '1' || input[0] == '2' || input[0] == '3' || input[0] == '4' || input[0] == '5' ||
input[0] == '6' || input[0] == '7' || input[0] == '8' || input[0] == '9')||
!(input[1] == 'a' || input[1] == 'A' || input[1] == 'b' || input[1] == 'B' || input[1] == 'c' || input[1] == 'C' || //validating second array element
input[1] == 'd' || input[1] == 'D' || input[1] == 'e' || input[1] == 'E' || input[1] == 'f' || input[1] == 'F' ||
input[1] == '0' || input[1] == '1' || input[1] == '2' || input[1] == '3' || input[1] == '4' || input[1] == '5' ||
input[1] == '6' || input[1] == '7' || input[1] == '8' || input[1] == '9'))
{
cout << "Invalid Input!\n\n";
}
else
{
cout << "Hexadecimal input: " << input[0] << input[1] << endl << endl;
cout << "Binary conversion: ";

switch (input[0]) // assigning integer value to first character element and printing it's binary value
{
case '0': array1 = 0;
Binary_print(x1, array1);
break;
case '1': array1 = 1;
Binary_print(x1, array1);
break;
case '2': array1 = 2;
Binary_print(x1, array1);
break;
case '3': array1 = 3;
Binary_print(x1, array1);
break;
case '4': array1 = 4;
Binary_print(x1, array1);
break;
case '5': array1 = 5;
Binary_print(x1, array1);
break;
case '6': array1 = 6;
Binary_print(x1, array1);
break;
case '7': array1 = 7;
Binary_print(x1, array1);
break;
case '8': array1 = 8;
Binary_print(x1, array1);
break;
case '9': array1 = 9;
Binary_print(x1, array1);
break;
case 'a': array1 = 10;
Binary_print(x1, array1);
break;
case 'A': array1 = 10;
Binary_print(x1, array1);
break;
case 'b': array1 = 11;
Binary_print(x1, array1);
break;
case 'B': array1 = 11;
Binary_print(x1, array1);
break;
case 'c': array1 = 12;
Binary_print(x1, array1);
break;
case 'C': array1 = 12;
Binary_print(x1, array1);
break;
case 'd': array1 = 13;
Binary_print(x1, array1);
break;
case 'D': array1 = 13;
Binary_print(x1, array1);
break;
case 'e': array1 = 14;
Binary_print(x1, array1);
break;
case 'E': array1 = 14;
Binary_print(x1, array1);
break;
case 'f': array1 = 15;
Binary_print(x1, array1);
break;
case 'F': array1 = 15;
Binary_print(x1, array1);
break;
default:
;
}

switch (input[1]) // assigning integer value to second character element and printing it's binary value
{
case '0': array2 = 0;
Binary_print(x2, array2);
break;
case '1': array2 = 1;
Binary_print(x2, array2);
break;
case '2': array2 = 2;
Binary_print(x2, array2);
break;
case '3': array2 = 3;
Binary_print(x2, array2);
break;
case '4': array2 = 4;
Binary_print(x2, array2);
break;
case '5': array2 = 5;
Binary_print(x2, array2);
break;
case '6': array2 = 6;
Binary_print(x2, array2);
break;
case '7': array2 = 7;
Binary_print(x2, array2);
break;
case '8': array2 = 8;
Binary_print(x2, array2);
break;
case '9': array2 = 9;
Binary_print(x2, array2);
break;
case 'a': array2 = 10;
Binary_print(x2, array2);
break;
case 'A': array2 = 10;
Binary_print(x2, array2);
break;
case 'b': array2 = 11;
Binary_print(x2, array2);
break;
case 'B': array2 = 11;
Binary_print(x2, array2);
break;
case 'c': array2 = 12;
Binary_print(x2, array2);
break;
case 'C': array2 = 12;
Binary_print(x2, array2);
break;
case 'd': array2 = 13;
Binary_print(x2, array2);
break;
case 'D': array2 = 13;
Binary_print(x2, array2);
break;
case 'e': array2 = 14;
Binary_print(x2, array2);
break;
case 'E': array2 = 14;
Binary_print(x2, array2);
break;
case 'f': array2 = 15;
Binary_print(x2, array2);
break;
case 'F': array2 = 15;
Binary_print(x2, array2);
break;
default:
;
}

cout << endl << endl;

cout << "Select a line encoding scheme with its assumption from the menu below:\n\n";//displaying menu for the line coding schemes to choose from
cout << " UNIPOLAR:\n\n";
cout << " \t1. NRZ\n\n";
cout << " POLAR:\n\n";
cout << " \t2. NRZ-L\n\n";
cout << " \t3. NRZ-I (Assuming previous signal is postive)\n\n";
cout << " \t4. NRZ-I (Assuming prevoius signal is negative)\n\n";
cout << " \t5. RZ\n\n";
cout << " \t6. Manchester\n\n";
cout << " \t7. Differential Manchester (Assuming previous signal is postive)\n\n";
cout << " \t8. Differential Manchester (Assuming prevoius signal is negative)\n\n";
cout << " BIPOLAR:\n\n";
cout << " \t9. AMI (Assuming previous signal is postive)\n\n";
cout << " \t10. AMI (Assuming prevoius signal is negative)\n\n";
cout << " \t11. Pseudoternary\n\n";
cout << " MULTITRANSITION:\n\n";
cout << " \t12. MLT-3 (Assuming previous signal is postive)\n\n";
cout << " \t13. MLT-3 (Assuming prevoius signal is negative)\n\n";
cout << " \t14. MLT-3 (Assuming prevoius signal is a zero)\n\n";

cout << "Choose a number from the menu: ";
string scheme_choice;
cin >> scheme_choice;
cout << endl;


while (!(scheme_choice == "1" || scheme_choice == "2" || scheme_choice == "3" ||
scheme_choice == "5" || scheme_choice == "9" || scheme_choice == "10"))//validating input of number choice
{
cout << "Invalid entry! Enter Number again: ";
cin >> scheme_choice;
cout << endl;
}

if (scheme_choice == "1")
{
NRZ(x1);
NRZ(x2);
}
else if (scheme_choice == "2")
{
NRZL(x1);
NRZL(x2);
}
else if (scheme_choice == "3")
{
NRZI_pos(x1);
NRZI_pos(x2);
}
else if (scheme_choice == "5")
{
RZ(x1);
RZ(x2);
}
else if (scheme_choice == "9")
{
AMI_pos(x1);
AMI_pos(x2);
}
else if (scheme_choice == "10")
{
AMI_neg(x1);
AMI_neg(x2);
}
else
{
;
}


}//ending brace for first if-else statement

system("PAUSE");
return 0;
}

void Binary_print(int array[], int num)
{
for (int i = 0; i < maxibit; i++)
{
array = num % 2;
num = num/2;
}

for (int i = 3; i >= 0; i--)
{
cout << array;
}
}

void NRZ(int array[])
{
for (int i = (maxibit-1); i >= 0; i--)
{
if (array == 0)
{
cout << " 0 ";
}
else
{
cout << " +1 ";
}
}
}

void NRZL(int array[])
{
for (int i = (maxibit-1); i >= 0; i--)
{
if (array == 0)
{
cout << " +1 ";
}
else
{
cout << " -1 ";
}
}
}

void RZ(int array[])
{
for (int i = (maxibit-1); i >= 0; i--)
{
if (array == 0)
{
cout << " -1 0 ";
}
else
{
cout << " +1 0 ";
}
}
}

void AMI_pos (int array[])
{
string prev1 = "+1"; //assuming that previous 1 bit produces positive voltage
for (int i = (maxibit-1); i >= 0; i--)
{
if (array == 0)
{
cout << " 0 ";
}
else
{
if (array == 1 && prev1 == "+1")
{
cout << " -1 ";
prev1 = "-1";
}
else
{
cout << "+1";
prev1 = "+1";
}
}
}
}

void AMI_neg (int array[])
{
string prev1 = "-1"; //assuming that previous 1 bit produces negative voltage
for (int i = (maxibit-1); i >= 0; i--)
{
if (array == 0)
{
cout << " 0 ";
}
else
{
if (array == 1 && prev1 == "+1")
{
cout << " -1 ";
prev1 = "-1";
}
else
{
cout << "+1";
prev1 = "+1";
}
}
}
}

void NRZI_pos(int array[])
{
int lastbit = 0;
string bit1 = "+1"; //previous change caused by 1 voltage

//testing these 8 cominations in the format (lastbit array bit1): 00+1 00-1 01-1 01+1 11-1 11+1 10+1 10-1
for (int i = (maxibit-1); i >= 0; i--)
{
if (lastbit == 0 && array == 0 && bit1 == "+1") // the previous bit was a 0 which is positive so current bit 0 will be positive
{
cout << " +1 ";
lastbit = 0;
bit1 = "+1";
}
else if (lastbit == 0 && array == 0 && bit1 == "-1") // the previous bit was a 0 which is negative so current bit 0 will be negative
{
cout << " -1 ";
lastbit = 0;
bit1 = "-1";
}
else if (lastbit == 0 && array == 1 && bit1 == "-1")
{
cout << " +1 ";
lastbit = 1;
bit1 = "+1";
}
else if (lastbit == 0 && array == 1 && bit1 == "+1")
{
cout << " -1 ";
lastbit = 1;
bit1 = "-1";
}
else if (lastbit == 1 && array == 1 && bit1 == "-1")// the previous bit was a 1 which is negative so current bit 1 will be positive
{
cout << " +1 ";
lastbit = 1;
bit1 = "+1";
}
else if (lastbit == 1 && array == 1 && bit1 == "+1")
{
cout << " -1 ";
lastbit = 1;
bit1 = "-1";
}
else if (lastbit == 1 && array == 0 && bit1 == "+1")
{
cout << " +1 ";
lastbit = 0;
bit1 = "+1";
}
else//(lastbit == 1 && array == 0 && bit1 = "-1")
{
cout << " -1 ";
lastbit = 0;
bit1 = "-1";
}
}
}

Replies

You are reading an archived discussion.

Related Posts

Facebook is rolling out a new feature to find out how the pages are performing. The new feature is likely to be called 'People Talking About' and will display below...
I recently saw on TV (show called Gadget Guru) that said Windows Mobile Operating System, Mango is going to change the way we interact with our mobile phones and the...
QR codes are simple codes that open a web page without you having to type the URL. Simply point your phone to the QR code - the camera will scan...
Soon after independence, various social housing schemes have been initiated under the framework of the national five-year plan programmes to speed up housing development. Varying degree of success has been...
Hi, According to ISO 15693, 1 out of 256 or 1 out of 4 Pulse position coding is used for communication between reader and tag. Firstly, I didn't understand the...