Question: zybook 1 . 7 C + + Step 2 : Inspect the LabPrinter class Inspect the LabPrinter class implemented in the LabPrinter.h file. Member functions

zybook 1.7 C++
Step 2: Inspect the LabPrinter class
Inspect the LabPrinter class implemented in the LabPrinter.h file. Member functions Print2Plus2() and PrintSecret() print strings using
std.:cout.
Step 3: Implement 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 Print2Plus20 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:
2+2=4
Unknown function: PrintPlus2
Secret string: abc
Step 4: Submit code for 1010 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: 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 LABPRINTER_H
#define LABPRINTER_H
#include
#include
class LabPrinter {
protected:
const std::string secret;
public:
LabPrinter(std::string secretStringValue) : secret(secretStringValue){
}
virtual void Print2Plus2(){
using namespace std;
cout "2+2=4" endl;
}
virtual void PrintSecret(){
using namespace std;
cout "Secret string: \"" secret "\"" endl;
}
};
#endif
main.ccp
#include
#include
#include "LabPrinter.h"
using namespace std;
void CallFunctionNamed(LabPrinter& printer, string functionName){
// TODO: Implement this function after completing step 1
}
int main(){
LabPrinter printer("abc");
cout "2+2=4" endl;
cout "Unknown function: PrintPlus2" endl;
cout "Secret string: \"abc\"" endl;
// TODO: After completing step 1:
// Remove lines of code from step 1 and implement the CallFunctionNamed()
// function above main().
CallFunctionNamed(printer, "Print2Plus2");
CallFunctionNamed(printer, "PrintPlus2");
CallFunctionNamed(printer, "PrintSecret");
return 0;
}
zybook 1 . 7 C + + Step 2 : Inspect the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!