Making Change|Programming Assignment 5 Write a complete C++
program to do the following:
1. Read a single input record from the text le transactions.dat containing
the initial number of each coin and currency type in a till from which
change for purchases in a shop is to be made. Echo this information to
the text le change.out.
2. Read an arbitrary number of input records from the same le, each con-
taining shop transactions consisting of a purchase cost followed by the
amount tendered by the customer to pay for the purchase. For each trans-
action, print to the text le change.out the following information:
(a) the cost
(b) the payment
(c) the change and the number of each coin and banknote in the change
(d) the resulting till contents (the number of each respective coin or cur-
rency type remaining in the till after the transaction is completed).
As a simplifying assumption the total amount tendered by the cus-
tomer for the purchase goes into a lock box, not into the till. This
implies that the till contants will either remain the same (no change
for the transaction) or decrease by the number of each coin or cur-
rency provided in the change.
If the input le transactions.dat contains:
5 5 10 20 40 50 40 50
2.83 3.00
2.34 20.00
2.53 100.00
Then the output to change.out will be:
Initial Till Contents:
5 twenties 5 tens 10 fives 20 dollars 40 quarters 50 dimes 40 nickels 50 pennies
Cost = 2.83
Payment = 3.00
Change = 0.17, consisting of:
1 dime 1 nickel 2 pennies
Till Contents:
5 twenties 5 tens 10 fives 20 dollars 40 quarters 49 dimes 39 nickels 48 pennies
Cost = 2.34
Payment = 20.00
Change = 17.66, consisting of:
1 tenner 1 fiver 2 dollars 2 quarters 1 dime 1 nickel 1 penny
Till Contents:
5 twenties 4 tens 9 fives 18 dollars 38 quarters 48 dimes 38 nickels 47 pennies
Cost = 2.53
Payment = 100.00
Change = 97.47, consisting of:
4 twenties 1 tenner 1 fiver 2 dollars 1 quarter 2 dimes 2 pennies
Till Contents:
1 twenty 3 tens 8 fives 16 dollars 37 quarters 46 dimes 38 nickels 45 pennies
The following function is required in your solution:

void make_change(float cost, float payment, float &change,
int &twentiesInTill, int &tensInTill, int &fivesInTill,
int &dollarsInTill, int &quartersInTill, int &dimesInTill,
int &nickelsInTill, int &penniesInTill, int &twentiesInChange,
int &tensInChange, int &fivesInChange, int &dollarsInChange,
int &quartersInChange, int &dimesInChange,
int &nickelsInChange, int &penniesInChange)
/*
* For a purchase 'cost' and payment tendered in 'payment', makeChange
* calculates and returns 'change' and the number of each individual
* banknote or coin contained in that change from twenty dollar
* banknotes to pennies as well as the resulting quantity for each
* coin and currency remaining in the till.
*
* pure import parameters:
* cost - the cost of the item purchased
* payment - the payment tendered for the purchased item
* pure export parameters:
* change - difference between the cost and payment
* twentiesInChange - the number of twenty dollar banknotes in change
* tensInChange - the number of ten dollar banknotes in change
* fivesInChange - the number of five dollar banknotes in change
* dollarsInChange - the number of one dollar banknotes or coins in change
* quartersInChange - the number of quarter dollar coins in change
* dimesInChange - the number of dime coins in change
* nickelsInChange - the number of nickel coins in change
* penniesInChange - the number of penny coins in change
* import/export parameters
* (Each of the following initially contain as import parameters the
* number of the respective coin or currency in the till prior to the
* transaction. As export parameters, they each contain the number of
* the respective coin or currency in the till following the transaction.
* Because of the problem simplification, the amount remaining of each
* quantity is simply what was there prior to the transaction minus the
* number given out in change.)
* twentiesInTill - the number of twenty dollar banknotes in the till
* tensInTill - the number of ten dollar banknotes in the till
* fivesInTill - the number of five dollar banknotes in the till
* dollarsInTill - the number of one dollar banknotes or coins in the till
* quartersInTill - the number of quarter dollar coins in the till
* dimesInTill - the number of dime coins in the till
* nickelsInTill - the number of nickel coins in the till
* penniesInTill - the number of penny coins in the till
*
* If the change in pennies to be returned to the customer is 4605 (representing
* $46.05 in change) and twentiesInTill is at least 2, then twentiesInChange
* would be set to 2 (which would be subtracted from twentiesInTill) and the
* change in pennies would become 605. However, if there were only 1
* twenty-dollar note in the till, that would be given in the change instead.
* twentiesInTill would then be zero; twentiesInChange would be set to 1 and
3
* the change in pennies would become 2605.
* The total number of banknotes and coins provided in the change is minimised.
*/
{
}
An important hint here is that the change in pennies has to be assigned the
following after the value of change is calculated:
changeInPennies = static_cast<int>(change * 100.0 + 0.001);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.