Question: C + + Please show full code and explanation. Step 1 : Producing correct output Three commented - out lines of code exist in main

C++Please show full code and explanation. 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 class
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 1010 points
main.cpp
#include
#include
#include "LabPrinter.h"
using namespace std;
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 "2+2=4" endl;
cout "Unknown function: PrintPlus2" endl;
cout "Secret string: \"abc\"" endl;
*/
// 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;
}
LabPrinter.h
#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
 C++Please show full code and explanation. Step 1: Producing correct output

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 Databases Questions!