Question
1.7 LAB: Introduction to data structures labs Step 1: Producing correct output Three commented-out lines of code exist in main(). Uncomment the lines and click
1.7 LAB: Introduction to data structures labs
Step 1: Producing correct output
Three commented-out lines of code exist in main(). Uncomment the lines and click the "Run program" button. Verify that the program's output is:
2 + 2 = 4 Unknown function: PrintPlus2 Secret string: "abc"
Submit your code for grading. Your submission will pass the "Compare output" test only, achieving 1 of the possible 10 points.
Step 2: Inspecting the LabPrinter class3
Inspect the LabPrinter class implemented in the LabPrinter.h file. Access LabPrinter.h by clicking on the orange arrow next to main.cpp at the top of the coding window. Member functions Print2Plus2() and PrintSecret() print strings using std::cout.
Step 3: Implementing CallFunctionNamed()
Remove the three uncommented lines from main(). Then implement the CallFunctionNamed() function in main.cpp to handle three cases:
If functionName is "Print2Plus2", call printer's Print2Plus2() member function.
If functionName is "PrintSecret", call printer's PrintSecret() member function.
If functionName is anything other than the two strings mentioned above, print "Unknown function: xyz", where xyz is functionName's value.
After implementing CallFunctionNamed(), click the "Run program" button. Verify that the program's output is, once again:
2 + 2 = 4 Unknown function: PrintPlus2 Secret string: "abc"
Step 4: Submitting code for 10/10 points
Once CallFunctionNamed() is properly implemented, submitting the code should receive 10 out of 10 points. The program's output is exactly the same as the implementation from step 1. But step 3's implementation uses the LabPrinter object and step 1 does not.
Step 5: Understanding the difference
The unit test uses a different implementation of LabPrinter than what's shown in LabPrinter.h. Calls to each member function are tracked, so the unit test determines whether or not CallFunctionNamed() was actually implemented according to lab requirements.
Most labs in this material are similar. Program output matters, but how the output is achieved matters more. Functions you implement will commonly require use of an object passed as a parameter.
--------------------------------------------------------------------------------------------------
ALL CHANGES MUST BE MADE IN THE main.cpp FILE. LabPrinter.h is read only and cannot be edited.
--------------------------------------------------------------------------------------------------
main.cpp:
#include
void CallFunctionNamed(LabPrinter& printer, string functionName) { // Only implement this function after completing step 1 }
int main (int argc, char *argv[]) { LabPrinter printer("abc"); // Step 1: // Uncomment the block below and submit code for grading. Note that the // submission passes the "Compare output" test, but fails each unit test. /* cout
LabPrinter.h:
#ifndef LABPRINTER_H #define LABPRINTER_H #include
class LabPrinter { protected: const std::string secret;
public: LabPrinter(std::string secretStringValue) : secret(secretStringValue) { } virtual void Print2Plus2() { using namespace std; cout
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started