Hello Backx,
After working with the program I discovered that this bit of code should output one line.
1 2
|
cout << "Voer de naam van uw bestand in (let op hoofdletter en"
cout << "locatie gevoelig)" << endl;
|
To do this properly it would look like this:
1 2
|
cout << "Voer de naam van uw bestand in (let op hoofdletter en"
<< "locatie gevoelig)" << endl;
|
Or you could just use this:
|
cout << "Voer de naam van uw bestand in (let op hoofdletter en locatie gevoelig)" << endl;
|
Everything from the beginning of the program down to "codeer" appears to work without any problem.
In the function"codeer" I changed the variable "p" from int to double.
The
while (!invoer.eof())
works here because you read kar2 just before you return to the while condition, so here it works. I do not know if you did this by design or accident, but you got it right. The rest of the code down to where you figure the value of "p" appears to work.
After running the program several times I realized that the value of "p" was incorrect. It was showing me that the compression rate was 90+% when it should have said 9+%. I adjusted the formula to this
p = (1 - ((double)j / (double)k)) * 100;
to achieve the correct answer.
This leaves the output with 4 numbers to the right of the decimal point, but that can be changed with
std::cout << std::fixed << std::showpoint << std::setprecision(?); // <--- Requires the header file "<iomanip>".
where the ? is a whole number of seconds.
In the "decodeer function" I changed "int getal;" to "int iGetal" so as not to be confused with the function call "getal()". When I tested the decoding of the file all worked well.
In main I changed
cin >> filenaamin;
to
std::getline(cin, filenaamin);
just in case the file name would have a space in it. The new code looks like this now:
1 2 3
|
cout << "Enter the name of your file (note capital and location sensitive)" << endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file "<limits>".
std::getline(cin, filenaamin);
|
Line 2 needs to follow a "cin >> something" and precede any "getline()" because the "cin" will leave a "\n" in the input buffer that "getline" will extract from the buffer and move on not giving you a chance to enter anything from the keyboard. The same is true for reading from a file just change "std::cin" to the name you used for the file stream.
This may help you understand the ".ignore"
http://www.cplusplus.com/reference/istream/istream/ignore/
I opened the output file this way
uitvoer.open(filenaamuit, ios::out | std::ios::trunc | std::ios::ate);
This way the file is cleared each time the program is run, so as not to confuse you trying to figure out what you are working with. Later on you may choose to remove "trunc" if so be sure to change "ate" to "app".
In the if/else if statements I changed the condition to
if (toupper(ed) == 'E')
. If for some reason you can not use this I would suggest
if (ed == 'E' || ed == 'e')
to catch either case.
Overall you did a good job with the program. I am impressed.
The new functions that you posted look OK with the exception of "is_palindroom". I believe "Reverse" should be a function call. And the next line 16 has no point or use. Very likely to cause a compile error. I can add these functions to the program, but other than testing I am not sure where you would want to put the function calls.
There is something to work on.
Hope that helps,
Andy