英國留學生經濟學dissertation范文-JewelryBoutique™
JewelryBoutique™ 屬于一種商業銷售類型。每一種銷售類型都有一個ID號與之對應,通常是一個六位整數,單位是美元。商店提供了各種折扣,主要根據不同季節的銷售狀況,主要有三種類型的折扣,一個是基本的;一個是雙倍的,還有一個是三倍的。分別在正常價格的基礎上減少10%,20%和30%。
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.
In this PART I, 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
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:
1.the item ID is 0, or 000000 if in 6 digits,
2.the input is terminated by EOF (end of file), i.e. control-Z for Windows or control-D for Unix
3.item price is negative
4.item quantity is negative
5.any numerical field containing an invalid character
6.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.
1.Write a function calculateItemCost prototyped by
2.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, http://www.mythingswp7.com/Essay_Writing/ 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.
3.(1 mark) Write a function displayTotalCost prototyped by
4.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.http://www.mythingswp7.com/Essay_Writing/2613.html 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, http://www.mythingswp7.com/Assignment_Writing/2619.html 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.
5.(2 marks) Write a function readSaleRecord prototyped by
6.int readSaleRecord(unsigned & itemId, double & itemPrice,
7. 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.
相關文章
UKthesis provides an online writing service for all types of academic writing. Check out some of them and don't hesitate to place your order.