Question
Consider the following poem: A dozen, a gross and a score and three times the square root of four divided by seven plus five times
Consider the following poem: A dozen, a gross and a score and three times the square root of four divided by seven plus five times eleven is nine squared and not a bit more.
*** INSTRUCTIONS
Suppose I don't know how much a dozen, a gross or a score is. I'm going to use a function you create to discover values for these variables such that the above poem is true. In a file called Limerick.cpp, flesh out the function:
double eval_limerick(int dozen, int gross, int score);
It should calculate the left-hand-side (LHS) of the above poem using the supplied values for dozen, gross and score and return the result. The LHS is all the terms before the "is". Thus your function should return the quantitative result of the calculation:
dozen + gross + score + 3 * sqrt(4) / 7 + 5 * 11
But before you jump the gun, make sure to calculate it by hand and confirm that you correctly get the RHS(81).Use parentheses in the above expression to make sure you get the operand groupings that make the poem come true. You are allowed to use the math library function, sqrt().
*** TEMPLATE***
#include#include // Need this for istringstream below
#include// needed for sqrt #include // for exit()
using namespace std;
double eval_limerick(int dozen, int gross, int score) {
// TODO - Your code here
}
// I'm using command line arguments below to let me test your program with // various values from a batch file.
int main(int argc, char **argv) { int dozen, gross, score;
if (argc < 4) { cerr <<"Usage: limerick dozen-val gross-val score-val "; exit(1);
} istringstream(argv[1]) >>dozen; istringstream(argv[2]) >>gross; istringstream(argv[3]) >>score;
// Invoke the eval_limerick function correctly and print the result // with a single newline at the end of the line. // TODO - Your code here
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