Question: zybook 1 . 7 C + + Step 2 : Inspect the LabPrinter class Inspect the LabPrinter class implemented in the LabPrinter.h file. Member functions
zybook C
Step : Inspect the LabPrinter class
Inspect the LabPrinter class implemented in the LabPrinter.h file. Member functions PrintPlus and PrintSecret print strings using
std:cout.
Step : Implement CallFunctionNamed
Remove the three uncommented lines from main Then implement the CallFunctionNamed function in main.cpp to handle three
cases:
If functionName is "PrintPlus call printer's PrintPlus 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 button. Verify that the program's output is once again:
Unknown function: PrintPlus
Secret string:
Step : Submit code for points
Once CallFunctionNamed is properly implemented, submitting the code should receive out of points. The program's output is
exactly the same as the implementation from step But step s implementation uses the LabPrinter object and step does not.
Step : Understand 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 book are similar. Program output matters, but how the output is achieved matters more. Functions to implement will
commonly require use of an object passed as an argument.
LabPrinter.H read only
#ifndef LABPRINTERH
#define LABPRINTERH
#include
#include
class LabPrinter
protected:
const std::string secret;
public:
LabPrinterstd::string secretStringValue : secretsecretStringValue
virtual void PrintPlus
using namespace std;
cout endl;
virtual void PrintSecret
using namespace std;
cout "Secret string: secret endl;
;
#endif
main.ccp
#include
#include
#include "LabPrinter.h
using namespace std;
void CallFunctionNamedLabPrinter& printer, string functionName
TODO: Implement this function after completing step
int main
LabPrinter printerabc;
cout endl;
cout "Unknown function: PrintPlus endl;
cout "Secret string: abc endl;
TODO: After completing step :
Remove lines of code from step and implement the CallFunctionNamed
function above main
CallFunctionNamedprinter "PrintPlus;
CallFunctionNamedprinter "PrintPlus;
CallFunctionNamedprinter "PrintSecret";
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
