CEng 242 Homework 3
Due: 7th April 2000
Define an abstract data type Wallet with the following
features:
It can contain cash (bills with values 1,5,10,25,100 only, and
there can be at most 20 bills in a WALLET in total) and credit cards
(card names are strings, and there can be at most 5 credit cards
in a WALLET). Cash are tagged with CASH and credit cards are
tagged with CARD. Each credit card also has a credit limit
which is a positive integer less than 1000.
All the cash can be ``assigned''from a WALLET to another WALLET.
Implement following functions and attributes:
Your abstract data type should produce the following invalid
Wallet types:
- CreditOverFlow
Result of addCard exceeds the credit per card limit 1000.
- CardOverFlow
Result of addCard exceeds the number of cards 5.
- InvalidBill
Argument of addBill or deleteBill is not a valid bill
type.
- BillOverFlow
Result of addBill exceeds the total bill number 20.
- CardnotFound
Card name in deleteCard is not found.
- NotEnoughBill of int
There is not enough number of bills in wallet for deleteBill
request and int argument indicates the required number
of bills to complete request.
- NotEnoughAmount of int
There is not enough amount in the bills or credit cards to
make the payment in pay request and int
indicates the amount which could not be paid.
- InvalidWalletArg
Wallet parameter of all functions other than display
is an invalid Wallet.
display function should produce the following explanation for errors
in the output. Type tags should be invisible to user.
-
CreditOverFlow "Credit limit for card is exceeded."
CardOverFlow "Too many cards."
InvalidBill "No such bill."
BillOverFlow "Too many bills."
CardnotFound "Card does not exist."
NotEnoughBill "Not enough bill of that type, %d is missing."
NotEnoughAmount "Not enough cash and/or credit, %d$ is missing."
InvalidWalletArg "Wallet argument is not a valid wallet."