Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C++ and then test a Money class, which represents amounts of UK currency. The value is implemented as a single integer

Write a program in C++ and then test a Money class, which represents amounts of UK currency. The value is implemented as a single integer value that represents the amount of money as if it were converted to all pennies. For example, 9.95 would be stored as the value 995. This integer for the amount of money is stored in a member variable called allPence: what type would you be using for this variable? Discuss the reason why you chose that type. Make sure that you code is written in such a way to check for possible errors on the values that are used as input to build the class, and that your program terminates in a controlled way in case of wrong format of the input variables. The class Money has three constructors: one to initialise the object so that its value represents an amount with the pounds and pence given by the arguments ( pounds.pence). If the amount is negative, then both pounds and pence should be negative; one to initialise the object so its value represents pounds.00; one default constructor to initialise the object so its value represents 00.00; The class Money has two friend functions: add and equal. The function add returns a Money object whose value is the sum of the values of its two arguments; a function equal returns true if the two objects that are compared have values that represent equal amounts of money. In these functions the input parameters could be called either by value or by reference. What would be the difference in these two cases? Which one is a more efficient implementation? In the call by reference how would you indicate to the compiler that the input parameters of your functions do not change the value of the parameters? Implement and test the functions (in separate files) using the call-by-value and call-by-reference methods and show that you get the same result. The class Money has two functions, input and output to input the amount of money to compare and output the result of the comparison. Test your class with a test function that asks for an amount of money (twice), prints it and then compares the two amounts printing which one is the highest. Then add the two amounts and print out the total.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions