Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the specifications for the function below The price of an item that you wa

ID: 3783614 • Letter: W

Question

Write the specifications for the function below

The price of an item that you want to buy is given by two integers as priceDollars dollars and priceCents cents. You pay for it in cash by giving the clerk payDollars dollars and payCents cents. Write specifications (documentation) for a function that computes the change, if any, that you should receive. The correct change should be passed back in two function parameters as changeDollars and changeCents (that are passed by reference). Include a statement of purpose, the pre- and postconditions, and a description of the parameters, Be precise in the relationship between the inputs and outputs (don't just say, "the correct change is computed"). Do not write code to implement the function. Just write the specifications. Do not using floating point. Money is not subject to round-off error.

Explanation / Answer

/*pre-condition: priceDollars and priceCents should be greater than or equal to zero and greater than zero, respectively. payDollars and payCents should be greater than or equal to priceDollars and priceCents, combinely.*/

function change ( changeDollars, changeCents)

{

// purpose statement: calculate changes after paying bill

changeCents = payCents - priceDollars //if payCents is less than priceDollars then increase payCents by 100 and reduce the payDollar by 1 and

changeDollars = payDollars - priceDollars // payDollars should be greater than or equal to priceDollars

//relation between input and output: changes value should be less than that of values paid by the user i.e., value of change dollar can't be greater than that what user have paid

}

/*post-condition: changeCents and changeDollars should be greater than or equal to 0 and they should be less than that of payDollars and payCents