Write a procedure to add and subtract-money, C/C++ Programming

Assignment Help:

Money is immutable and is associated with a currency. When two money entities are added or subtracted be sure to consider currency conversion. You must create a money object resulting from the addition or subtraction which has the same currency as the first money entity passed to the add-money or subtract-money procedure.

(a) You are required to write the procedures: add-money and subtract-money. The procedures add-money and subtract-money have 2 arguments, both being Money.

(b) You are required to write the procedures: multiply-money and divide-money. The multiply-money and divide-money have 2 arguments, the first of which is Money, the second of which is a number.

(c) You must also write a make-money procedure, which has 2 arguments, the amount as a number and a currency, which is a symbol.

(d) Write accessor procedures for the amount and currency parts of a Money object.

(e) Write a money-as procedure. This procedure has 2 arguments, the first of which is Money, the second of which is a currency symbol. The procedure returns a new Money object of the currency requested.

(f) You must also implement a currency procedure which has a symbol argument, c, that returns the currency conversion value for that currency. Assume that 'dollars, 'pounds, and 'euros are valid currencies. The currency procedure returns #f for all other currencies. The conversion value for 'dollars should be 1.0, 0.636 for 'pounds and 0.756 for 'euros. An example is shown below:

(define dollar-amount (make-money 100 'dollars)) ; Make a $100
(define pound-amount (make-money 100 'pounds)) ; Make 100 pounds
(define dollars-plus-pounds (add-money dollar-amount pound-amount)) ; Result should be dollars
(define pounds-plus-dollars (subtract-money pound-amount dollar-amount)) ; Result should be pounds
(currency 'euros) ; Result should be 0.756

 


Related Discussions:- Write a procedure to add and subtract-money

Describe about the container class, Describe about the container class. ...

Describe about the container class. -Class to hold objects in external storage or memory. It acts as a generic holder. - It has a predefined behaviour and a known interface.

Matematic, how to make program c++

how to make program c++

Matrices, write a c program that multiplies 3 martices

write a c program that multiplies 3 martices

Arrys, Write a program that allows user to enter number of elements in an a...

Write a program that allows user to enter number of elements in an array. The program then allows user to enter the elements. Write a function called max that returns the position

Blanche has a fashion design company called BLB_Best_Clothin, Blanche has a...

Blanche has a fashion design company called BLB_Best_Clothing Pty. That she has just opened recently

Decode the code, c++ coding decode the letters from numbers

c++ coding decode the letters from numbers

C++ coursework programming for engineering, Hi there I am looking for hel...

Hi there I am looking for help with c++ coursework. Could you please provide me with email address to email a copy of it. Thanks

Program for swapping the two integers, Program for Swapping the Two Integer...

Program for Swapping the Two Integers                 For example, Swapping the two value                                 int x=4,y=6,t;                                 t

Determining the monthly payment on a mortgage loan, The following is the fo...

The following is the formula that can be used to complete that calculation: Monthly Payment = Monthly Interest Rate / (1 - (1 + Monthly Interest Rate) -Payment Interval )) *

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd