Zybooks C++ 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 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 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. 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; }

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 8RQ
icon
Related questions
Question

Zybooks

C++

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 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 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.

main.cpp

#include <iostream>
#include <string>
#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;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,