Step 5: "const" Parameters
Now, we will experiment with using the const modifier on parameters.
IMPORTANT: Before doing this step, copy your program file from the end of Step 4, which should have been called "lab4.cpp", to a new file named "lab4-bad.cpp". Then, edit this new file for this this final step of the lab.
Recall from lecture that when we add the const modifier to a parameter declaration, it is tell the compiler that the function will not be altering the parameter variable at all.
This step is also easy. Just cut-and-paste the entire definition
of MungeRecordForReal() from Step 4 and rename the new copy
of the function as
After writing this function, you should add the necessary function declaration for MungeRecordFail() at the top of your file, above main().
As before, add a call in main() to MungeRecordFail(), right after the code you added in the previous step. You should be able to cut-and-paste to duplicate the code you added into main() for Step 4, simply modifying the name of the function called.Now, try compiling the code. What happened? Why? Show the TA the results, and explain why you think the compile failed. Also show them the results of the original, pre-Step 5 version, which did compile and run. That's it--you're done with the lab!