In the heydey of the British empire, Great Britain used a monetary system based on pounds, shillings, and pence with the following conversions: 1 pound = 20 shillings 1 shilling = 12 pence The program should prompt the user to enter two currency values represented in £PP.SS.CC format (2 digits for pounds, 2 digits for shillings, and 2 digits for pence). Each element within a currency value can be entered separately without decimal points if you wish. Store each currency value in a structure with the following format: struct Currency { int Pounds; int Shillings; int Pence; }; Convert each currency value (pounds, shillings, pence) to total pence (type long int), add the two pence totals together and convert that sum back to the pounds-shillings-pence format shown above and display the result. The pence value should not exceed 11. The shillings value should not exceed 19. The pounds value will be limited such that its value should not exceed 99. If any of these values do exceed the maximum value, they must wrap around to 0, etc. The program must use the seven functions defined below with the exact names and prototypes given (any deviation will result in severe point reduction). A description follows each function prototype: (1) void Input_Cur(Currency&); Inputs the first currency value (pounds, shillings, pence) and returns it using a reference parameter. (2) Currency Input_Cur(); Inputs the second currency value and returns it using the return statement. (3) int Validate_Cur(Currency); Accepts a currency value and returns a code indicating valid or invalid data. (4) void Display_Cur(Currency); Accepts a currency value (pounds, shillings, pence) fpr printing and returns nothing (5) long Cur_To_Pence(Currency); Accepts pounds, shillings, pence and returns the total equivalent pence (6) Currency Pence_To_Cur(long); Accepts total pence and returns a currency value in pounds, shillings, and pence. (7) void Print_Zero(int); Prints leading zeros if necessary. Accepts a pounds, shillings, or pence value, and prints a zero only if the value < 10. If the value passed is ≥ 10, nothing is printed. Called from Display_Cur(). The input and output dialogue should appear as follows: Case 1 Enter Currency 1: 19 15 11 Enter Currency 2: 7 9 5 Currency 1: £19.15.11 Currency 2: £07.09.05 Result: £27.05.04 Case 2 Enter Currency 1: 3 12 16 Enter Currency 2: 43 18 7 Currency 1: £03.12.16 Currency 2: £43.18.07 Result: Invalid currency was entered Case 3 Enter Currency 1: 0 0 1 Enter Currency 2: 99 19 11 Currency 1: £00.00.01 Currency 2: £99.19.11 Result: £00.00.00 For each case, print the two input values and the resulting sum in £PP.SS.CC format. When displaying the result, some compilers use the hex character constant ‘\x9c’ (decimal 156) to generate the pound symbol £. Generating the pound symbol, however, is not required. Each pound, shilling, and penny value should be printed as two-digit values with zero fill for all values less than 10. Do not use the setfill manipulator; use the Print_Zero function to zero fill. Use no global variables. The Validate_Cur function should validate the input values and return a zero if the data are valid and a -1 if the data are invalid. If the data are invalid, print the currency value (pounds, shillings, and pence with decimal points) and an appropriate error message and continue with the next case; do not calculate the sum. Output all currency values using Display_Cur invoked from the main function. Use a looping mechanism of your choice to process an arbitrary number of cases of data. Your program must work for error cases as well as valid cases. Error cases may include negative values and values that exceed the maximums. |
|
|
|
|
public:
appears. This delineation is not important until you get more into Object-Oriented programming though.