Wednesday, 12 May 2010

Interesting Challenging problem on Code Complexity

Picked up this interesting problem from the following book:



How many execution paths can this simple three line code take:



String EvaluateSalaryAndReturnName( Employee e )
{

if
( e.Title() == "CEO" || e.Salary() > 100000 )
{

cout << e.First() << " " << e.Last() << " is overpaid" << endl;
}

return
e.First() + " " + e.Last();
}






The answer may surprise you. I have embedded the actual pages from Google books. Luckily the whole problem and solution is given. See Item 18.

No comments:

Post a Comment