Below is a program that uses a fuction to compute the cost of hiring an attorney
ID: 3840771 • Letter: B
Question
Below is a program that uses a fuction to compute the cost of hiring an attorney from Wright & Co.law office,which is priced in dollars
Answer the following questions. Refer to line numbers if you find it helpful in your answers.
(a) Listallofthefunctionargumentsinthisprogram.
(b) Listall ofthe function parameters in this program.
(c) Listallofthevariablesthatarenotarguments orparameters.
(d) What is the scope of:
i. number_of_trial_days ii. total_cost
iii. cost1
(e) How many function definitions are in this program?
(f) How many function calls are in this program?
(g) Whatarethe valuesreferredtobycost1andcost2when the programends?
1 def cost-of-attorney number-of-trial-days price-per-day number-of-witnesses, price-per-witness) Computes the cost of an attorney which is in dollars number-of-trial days the number of days the trial lasts price-per-day cost of an attorney working for 1 day in dollars number of witnesses how many witnesses need to be CrOSS examined during the trial price-per-witness price of an attorney per witness that needs to be cross examined in dollars Returns total cost of an attorney 14 15 total-cost-per-day number-of-trial days price-per-day 16 total witness-cost number-of-witnesses price-per-witness 17 total-cost total cost-per-day total-witness-cost return total cost 20 compute the cost of a trial that lasts 2 days, 21 each day costs 600$, there are 3 witnesses, and it costs 100$ per witness 22 cost 1 cost-of-attorney (2 600 3, 100 24 compute the cost of a trial that lasts 9 days 25 each day costs 400$, there are 13 witnesses, and it costs 100$ per witness 26 cost cost-of-attorney (9 400 13 100)Explanation / Answer
Food for thought before we move on: parameter is a value which usually is a part of the function's declaration and argument is the expression used while calling the function. Let us begin now:-
(a) Arguments are while calling the function. As function is called twice so, in the first call the arguments are: 2, 600, 3, 100 and the second call the arguments are 9, 400, 13, 100. (Line:22,26)
(b) Function parameters are part of it's declaration. Hence, function parameters are: number_of_trail_days, price_per_day, number_of_witnesses, price_per_witness.(Line:1,2)
(c) So, variables left are neither arguments nor parameters and they are: cost1, cost2, total_cost, total_witness_cost, total_cost_per_day.
(d) Food for thought: variable defined in the main body of the program --> global variable and variables declared inside a function is local to that function
i. number_of_trial_days --> as it is a formal parameter so the scope will be within the function defined
ii. total_cost --> local variable which is defined inside a function, so scope will be limited to the function only !
iii. cost1 --> globally defined, scope is throughout the program life
(e) Just one cost_of_attorney (Line:1)
(f) two times it is called, one for cost1 and another for cost2. (Line:22,26)
(g) It is simple math, just calculate it !
cost1= 2×600+3×100 = 1500$
cost2= 9×400+13×100 =4900$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.