Homework help

Jul 25, 2018 at 8:28pm
Hi ,so I started on this homework but I'm having trouble finishing it and I was wondering if I could get some help.

heres the code that I have right now:
int main ()
{
short HammingCh, bit1, bit2, bit4, bit8, errantBit;

// ouput ID line
cout << ID;

// read unknown # of short ints, each representing a Hamming character
while (cin >> HammingCh)
{
// intialize errantBit to 0; i.e., assume it has no errors
errantBit = 0;

// compute parity bit1 using the Hamming's formula
bit1 = (getBit(HammingCh, 11 - 3) +
getBit(HammingCh, 11 - 5) +
getBit(HammingCh, 11 - 7) +
getBit(HammingCh, 11 - 9) +
getBit(HammingCh, 11 - 11)
) % 2;

// compare the computed value of parity bit1 versus the observed value
if (getBit(HammingCh, 11 - 1) != bit1)
{
errantBit += 1;
}

// repeat the above 2 steps for parity bits 2, 4, 8
bit2 = (getBit(HammingCh, 11 - 3) +
getBit(HammingCh, 11 - 6) +
getBit(HammingCh, 11 - 7) +
getBit(HammingCh, 11 - 10) +
getBit(HammingCh, 11 - 11)
) % 2;

if(getBit(HammingCh, 11 - 2) != bit2)
{
errantBit += 1;
}

bit4 = (getBit(HammingCh, 11 - 5) +
getBit(HammingCh, 11 - 6) +
getBit(HammingCh, 11 - 7)
) % 2;


if(getBit(HammingCh, 11 - 4) != bit4)
{
errantBit += 1;
}

bit8 = (getBit(HammingCh, 11 - 9) +
getBit(HammingCh, 11 - 10) +
getBit(HammingCh, 11 - 11)
) % 2;

if(getBit(HammingCh, 11 - 8) != bit8)
{
errantBit += 1;
}

// if errantBit is nonzero, fix HammingCh
if (errantBit != 0)
{
(11 - errantBit);

}

// build a printable ASCII character from HammingCh
char ch = 0;
ch = setBit(ch, 6, getBit(HammingCh, 11 - 3));


}
return 0;
}



This is the assignment description:

Write a program that decodes the message, correcting for single-bit
errors. The input should be read from standard input (use redirection). The message is of unknown length;
thus, your program should process integers until the end-of-data marker is encountered.
Output
The decoded message should be written to the standard output as characters, not integers.



Jul 26, 2018 at 11:21am
Hello gentrybryant,

Welcome to the forum.

While I work on your code and see if it will compile. Take a look at the following links.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

One of the frist things I did notice is that you are missing your header files. Without them I do not know what you have used and the code will not compile.

Hope that helps,

Andy
Jul 26, 2018 at 11:34am
Hello gentrybryant,

At first check the variable "ID" is undefined in main and I have no idea where or how it is defined.

Also the functions "getBit()" and "setBit" are missing.

With out these I can not compile or see what is going on. This also begs the question what exactly are you having trouble finishing?

Andy

P.S. Some kind of example of the input and output would help to know what you are trying to achieve.
Last edited on Jul 26, 2018 at 11:36am
Topic archived. No new replies allowed.