Ouch. What a mess :) You need to address the C++ errors, and logical errors as well.
Works well to line 11
Add ; to lines 66 and 67
Your line 15: how do you know that the character last seen was 0? You should initialize that value to the first value in the data_stream
Line 18: "for( bit<=data_stream); " is not a valid C++ statement. See http://www.cplusplus.com/doc/tutorial/control/
the for loop.
|for (initialization; condition; increase) statement;|
So you need a counter for position along the data string. Before the for loop declare
the initialization can be
, the condition is to be before the end of the string
and the increase is
After the for(...) you need to put a statement. The syntax for that is either
for (initialization; condition; increase) statement;
for (initialization; condition; increase)
Please note where you have semicolons.
Further errors: the assignment operator in C++ is "=", not ":="
"this" is a c++ reserved keyword. Do not use it until you are a little bit more advanced.
For the logic of your code, here is the first half (replace this between lines 18 and 38)
// stuff a zero bit after four consecutive bits of the same value.
std::string stuffed_stream ;
int cnt = 0 ;
int stuff_bits_added = 0 ;
for( size_t p=0;p<data_stream.size();p++) //for each bit in the data_stream
//1st step: copy the bit - you always need to do this step
if(cnt==0) // this condition occurs either at the beginning, or after 4 occurences have been found
//set the bit_last_seen, increase the cnt to 1, then move to the next bit
else //do your processing
if( bit==bit_last_seen) //it is the same as the previous bit
else //different bit
bit_last_seen = bit ;
cnt = 1 ; // restart count at 1
if( cnt == 4 ) // there are four consecutive bits of the same value
stuffed_stream += '0' ; // stuff with a zero bit
cnt = 0 ; // and reset cnt to zero
++stuff_bits_added ; // increment the count of stuff bits added
i suggest you comment out the rest of your code, except the printing, run the first part, understand the explanations, then write the second part.