Need Help with C++ RLE Algorithm Homework | Troubleshooting Encoder Function

  • Context: Comp Sci 
  • Thread starter Thread starter CSteiner
  • Start date Start date
  • Tags Tags
    C++
Click For Summary
SUMMARY

The discussion centers on troubleshooting a C++ Run-Length Encoding (RLE) algorithm, specifically an encoder function that fails to produce the expected output. The user reports that their function copies the input directly instead of encoding it, despite following the provided pseudo code. Key suggestions include declaring function prototypes outside of the main function, using fstream instead of separate ifstream and ofstream, and ensuring the repeats variable is an integer. Adjusting the inequality condition in the encoding logic is also recommended to resolve the issue.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with Run-Length Encoding (RLE) algorithms
  • Knowledge of file stream handling in C++ (ifstream, ofstream, fstream)
  • Experience with function prototypes and variable types in C++
NEXT STEPS
  • Review C++ file stream handling with fstream for efficient file operations
  • Learn about function prototypes and their importance in C++ programming
  • Study Run-Length Encoding algorithms and their implementation in C++
  • Experiment with debugging techniques in C++ to identify logical errors in code
USEFUL FOR

C++ students, software developers working on encoding algorithms, and anyone seeking to improve their debugging skills in C++ programming.

CSteiner
Messages
31
Reaction score
0

Homework Statement


[/B]
See this link for the given assignment.

http://eilat.sci.brooklyn.cuny.edu/cis1_5/HW5i_C.pdf

note: on the last page the output aa4bcdd0cc1 is actually supposed to be aa3bcdd1cc1c.

Homework Equations



I have no idea why my encoder function doesn't work. No matter how I try to do it (I've tried strings, arrays - everything), the function copies the input exactly instead of encoding it. I followed the given pseudo code, and it had no problems for the decoder, but I must be doing something wrong for the encoder. Any advice would be appreciated

The Attempt at a Solution


[/B]
See the attached source code.
 

Attachments

Last edited by a moderator:
Physics news on Phys.org
You didn't attach the header file you are using.
Declare your function prototypes outside of main.
Why are you creating an ifstream object, not defining it, and then passing it to your encoder function?
Instead of having both ifstream and ofstream, check out fstream.
Your repeats variable should be an int, because it is a number, not a character.
Things are getting kind of weird with your previousbyte and byte definitions. Consider using a char array or a different standard template container.
CSteiner said:
No matter how I try to do it (I've tried strings, arrays - everything), the function copies the input exactly instead of encoding it. I followed the given pseudo code, and it had no problems for the decoder, but I must be doing something wrong for the encoder. Any advice would be appreciated

This either means your encoding function is wrong, or that the inequality to encode is not being met. Try changing the inequality to != and see if it works. If it does, then something is wrong with the way you are obtaining the bytes. If it still does not work then its your encoding algorithm.
 
1. Whoops, it's attached now.
2.will do.
3. He kept on stressing that streams had to be passed by reference, so I thought he was implying it was necessary to pass streams in this assignment, and I didn't really think about it.
4. I'll play with that, thanks.
5. I had it as an integer initially, but classmate mentioned that he had success declaring it as a character, and I thought that might have been what was wrong. Turns out it didn't make a difference, but I forgot to change it back.
6. I've tried those, but it didn't help.

thanks for your tips, I'll implement them and see what happens.
 

Attachments

Similar threads

  • · Replies 17 ·
Replies
17
Views
6K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K