Item 18. Code Complexity—Part 1
Difficulty: 9
This problem presents
an interesting challenge: How many execution paths can there be in
a simple three-line function? The answer will almost certainly
surprise you.
How many execution paths could there be in the
following code?
String EvaluateSalaryAndReturnName( Employee e )
{
if( e.Title() == "CEO" || e.Salary() > 100000 )
{
cout << e.First() << " " << e.Last() << " is overpaid" << endl;
}
return e.First() + " " + e.Last();
}
To provide a little structure here, you should
start by relying on the following three assumptions, and then try
to expand on them.
-
Different orders
of evaluating function parameters are ignored, and failed
destructors are ignored.
-
Called
functions are considered atomic.
-
To count as a
different execution path, an execution path must be made up of a
unique sequence of function calls performed and exited in the same
way.
|