CEng 242 Homework 4
Due: 28 th April 2000
Define a C++ class Wallet with the following
features:
It can contain cash with 5 types of bills: 1,5,25,50 and 100.
There can be at most 20 bills in a Wallet. Also a Wallet
can contain at most 5 credit cards. Each credit card has a name with
at most 40 characters (longer names should simply be
cropped) and a positive limit which is not greater than
1000. Credit card storage should be allocated when the first
card is added and deallocated when the last card is deleted.
Also you should write the destructor deallocating it.
Your should implement the following methods or functions:
Note that bill configuration is changed. New configuration can be solved in a very easy algorithm: start from the greatest bill, pay the maximum smaller than amount, than pay the rest from smaller bills using the same algorithm.
1*4+5*2+25*0+50*1+100*3=364 "HiperBank": 175 "HirsizBank": 950 "UltraBank": 200 Credit: 1325 Total: 1689
All functions are methods of Wallet except the last one that is an overloading of the operator <<. You should also overload assignment operator = to have the result of assignment work properly (instead of pointer assignment).
For errors you are given the following definitions:
#define NOERR 0 #define CREDITOVERFLOW 1 #define CARDOVERFLOW 2 #define INVALIDBILL 3 #define BILLOVERFLOW 4 #define CARDNOTFOUND 5 #define NOTENOUGHBILL 6
For all of the operations except cash(),credit() and total() you should return the following values:
For cases with both INVALIDBILL and BILLOVERFLOW, return INVALIDBILL. For cases with both CARDOVERFLOW and CREDITOVERFLOW generate CARDOVERFLOW. When constructor(s) are used with invalid parameters causing BILLOVERFLOW or any other errors, then silenty create an empty Wallet without any bill.
When an operation with an error is requested, object will not be modified and one of the listed return values will be returned. There should be no invalid Wallet object generated by your methods.
You should implement your homework in 3 files:
wallet.h, wallet.cpp and hw4.cpp.
wallet.h will contain your class definition only.
wallet.cpp will include this header file
and contain the implementation of your methods and
functions. hw4.cpp will include the header file and
contain your main()
function. You will submit a tared,gziped file of
wallet.h and wallet.cpp only. For example:
tar cf - wallet.h wallet.cpp | gzip -c >hw4.tar.gz
submit242 hw4.tar.gz
Do not include the file with main program into your submission!
During your development, you can use the following makefile. Indentation in the second line comes from a tab character. Write these lines into a file called makefile and for compilation just write make:
hw4: wallet.h wallet.cpp hw4.cpp g++ -o hw4 wallet.cpp hw4.cpp
Details of the submission procedure and output format may be changed. Changes will be announced in the newsgroup.