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; | |
} |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started