How would a programmer perform a range match when writing an application that takes into consideration different discount rates for customers? Give an example.
What will be an ideal response?
Create two corresponding arrays and perform a range match, in which you compare a value to the endpoints of numerical ranges to find the category in which a value belongs. For example, one array can hold the five discount rates, and the other array can hold five discount range limits. If you only use the first figure in each range, you can create an array that holds five low limits:
int[] discountRangeLimit= {1, 13, 50, 100, 200};
A parallel array can hold the five discount rates:
double[] discountRate = {0, 0.10, 0.14, 0.18, 0.20};
Then, starting at the last discountRangeLimit array element, for any numOfItems greater than or equal to discountRangeLimit[4], the appropriate discount is discount[4]. In other words, for any numOrdered less than discountRangeLimit[4], you should decrement the subscript and look in a lower range.
You might also like to view...
The option that saves a Word document as a .htm or .html file format and saves an additional set of files grouped in a folder is called the Web Page, ________ option
Fill in the blank(s) with correct word
Give code and the drawing to make clear what you are doing.
Here is a diagram of a three node linked list with a head pointer and a node to be inserted. Show all steps necessary to insert the node pointed to by temp between the second and third nodes, including the search for the node prior to insertion. You are to make clear the sequence of steps by either numbering the steps, or by makingseveral copies of this drawing, with one change per drawing, numbered to show the sequence. You may assume a search routine taking a head node and data has been defined for you.