Question: For the starZ.cpp program, we have these rules: - Take only one command line parameter: the width. The height will automatically be set equal to
For the starZ.cpp program, we have these rules:
- Take only one command line parameter: the width. The height will automatically be set equal to the width.
The starZ function follows these rules:
- Return a string that draws the letter Z with the correct width and height, but only if width >=3
- Return an empty string if the value passed in for width is not valid, print nothing at all.
- You should add code to starZ.cpp so that you are able to invoke the internal tests by typing ./starZ -1. Note that this time, there is only one parameter.
- And, if there is not exactly one parameter, there should be an appropriate usage message that follows the pattern of the other programsexcept that there is only a width parameter in this program.
| #include #include | |
| #include | |
| using namespace std; | |
| void assertEquals(string expected, string actual, string message); | |
| string starZ(int width); | |
| void runTests(void); | |
| string starZ(int width) | |
| { | |
| string result=""; | |
| result = "stub"; // TODO: remove this line, replace with correct code | |
| return result; | |
| } | |
| void runTests(void) { | |
| string starZ3Expected = | |
| "*** " | |
| " * " | |
| "*** "; | |
| assertEquals(starZ3Expected,starZ(3),"starZ(3)"); | |
| string starZ4Expected = | |
| "**** " | |
| " * " | |
| " * " | |
| "**** "; | |
| assertEquals(starZ4Expected,starZ(4),"starZ(4)"); | |
| assertEquals("",starZ(0),"starZ(0)"); | |
| assertEquals("",starZ(2),"starZ(2)"); | |
| } | |
| void assertEquals(string expected, string actual, string message="") { | |
| if (expected==actual) { | |
| cout | |
| } else { | |
| cout | |
| } | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| // TODO: Add check for parameter | |
| // and code to print usage message | |
| // TODO: Add code to get width from cmd line arg | |
| // code that checks if it is -1; if so, call runTests() | |
| // then exit. | |
| runTests(); | |
| // TODO: Add code that calls the starZ function and prints | |
| // the result on cout (without an extra newline) | |
| return 0; | |
| }
|
Sample values returned from starZ starZ renders the letters Z, but requires a minimum width of 3. It only takes one parameter, because the height and width are always assumed to be equal Function call Returns Function call Returns Function call Returns starZ(2) starZ(3) starZ(4) starZ(5) starZ(6) starZ(7)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

