I l@ve RuBoard Previous Section Next Section

Item 18. Code Complexity桺art 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.

  1. Different orders of evaluating function parameters are ignored, and failed destructors are ignored.

  2. Called functions are considered atomic.

  3. 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.

    I l@ve RuBoard Previous Section Next Section