JewelryBoutique is a jewelry shop selling various types of jewelries. Each type of jewllery item is represented by a unique item ID number, a 6 digit positive integer, and has an item price in dollars. The shop offers various different promotion discounts, depending on the season and the stock level. On top of the normal (N) prices, there are 3 types of discount prices: basic (B), double (D) and triple (T), reducing the normal prices by 10%, 20% and 30% respectively. Although each item ID maps eventually to the corresponding full item name, each sale record is in fact neatly represented in terms of the item ID, item price, discount rate, as well as the quantity sold for the same type of items. This way, a single order record such as

123456 19.99 D 3

implies a sale order is made for the jewelry product 123456, which originally costs \$19.99 per item, now having a discount of 20%, and 3 same items have been ordered for this sale. Hence the total sale price in this case is \$19.95 * 0.8 *3 = \$47.88. The product 123456 could for instance refer to a 30cm long necklace of white natural pearls.

You are required to develop a solution to read in such sale records in terms of item ID, price, discount and quantity, and calculate the total cost of all the items in the sale records. The total cost will then be displayed before the program terminates.

For simplicity, we assume that a valid item ID is a postive integer of no more than 6 digits, a valid item price is a non-negative number, a valid discount rate is either "N" (0%), or "B" (10%), or "D" (20%) or "T" (30%), and a valid quantity is also a non-negative integer. A typical list of sale records could thus be entered as the following set

101023 149.95 B 1
101024 199.95 D 1
100001 19.99 N 5
100002 39.99 N 2
103067 1999.00 T 1
000000

The program will thus read all the sale records, and calculate and display the total price before terminating. To make the program behave more rationally, we require that the program will keep reading the sale records until any of the following circumstances appears:

• the item ID is 0, or 000000 if in 6 digits,
• the input is terminated by EOF (end of file), i.e. control-Z for Windows or control-D for Unix
• item price is negative
• item quantity is negative
• any numerical field containing an invalid character
• discount rate is not one of the characters N, B, D and T

In the last 4 cases corresponding to erroneous records, the program should display a pertinent error message before terminating.

### Basic Program Requirements

This problem in PART I is relatively simple, but modular design for the solution is still required.

Write a function calculateItemCost prototyped by

double calculateItemCost(double itemPrice, char discountType, unsigned quantity);

so that the execution of this function will return the price for quantity number of the item priced originally at itemPrice each, and currently discounted according to discountType. For instance, calculateItemCost(10.90, 'D', 2) will return 17.44 because 17.44=10.9*0.8*2. Likewise calculateItemCost(5.50, 'B', 4) will return the value 19.8=5.50*0.9*4.

Write a driver program to illustrate the use of this function calculateItemCost unless the illustration will be done in your complete program jewelrySale.cpp.

Write a function displayTotalCost prototyped by

void displayTotalCost(double totalCost, unsigned recordNum, bool aborted);

so that the execution of this function will first display the total sale cost stored in variable totalCost and the total number of sale records stored in recordNum. If aborted is true, then the function will also display an error message to the effect "Input terminated by invalid data at record" followed by the corresponding record value. For example, displayTotalCost(55.55, 3, false) could just display Total sale cost (3 records) = \$55.55

While displayTotalCost(66.66, 7, true) could display Total sale cost (7 records) = \$66.66 Input terminated by invalid data at record 8. Write a driver program to illustrate the use of this function displayTotalCost unless the illustration will be done in your complete program jewelrySale.cpp.

Write a function readSaleRecord prototyped by

int readSaleRecord(unsigned & itemId, double & itemPrice, char & discountType, unsigned & quantity);

so that the execution of this function will retrieve 4 fields, i.e. the item ID itemId, the original item price itemPrice, the discount type discountType and the quantity

quantity, from the stdin device. The returned value will be 0 if the reading has been successful, and will be non-zero if otherwise. In fact, when the record is not successfully read, the returned value will be 1 if it's due to receiving 0 for the item ID or hitting the EOF, and will be -1 if otherwise. Explain (i) what do the ampersands "&" do in the prototyping; (ii) is this function still syntactically correct if some of these 4 ampersands are removed from the function header; and (iii) will your program still work if one of these 4 ampersands is removed and why. Please also use the following interface for the input.

Enter
-> item ID: 101024
-> full item price: 199.95
-> discount type: D
-> quantity: 1

Write a driver program to illustrate the use of this function readSaleRecord unless the illustration will be done in your complete program jewelrySale.cpp.

Complete the rest of the program to fulfill all the program requirements for the problem described in this PART I. For your reference, below is the screenshot of executing a possible implementation. See image.

Draw the Structure Diagram for your solution algorithm. Please beware that your complete C++ program for this PART I needs to match this structure diagram.