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

Lexicographically preceding permutation, Given an integer n and a permutati...

Given an integer n and a permutation of numbers 1, 2 ... , n-1, n write a program to print the permutation that lexicographically precedes the given input permutation. If the given

Function that have parameter and makes an integer mask, Write a function th...

Write a function that has an int parameter n, makes an integer mask having the bit 1 at the nth place from the rightmost bit, and returns the mask. For example, when n = 5 is passe

Virtual ATM, #questio A charitable organization wants to design a special A...

#questio A charitable organization wants to design a special ATM machine to be used by needy people. The association supplies the needy person with a pin number to be able to use

Metric number, how are metric numer change the number of metric

how are metric numer change the number of metric

Program to check even and odd numbers, Program to check even and odd number...

Program to check even and odd numbers: int main() {                 int  your_number;                 cout                 cin >> your_number;

Data structure and algorithm, implement two stacks in one array A[1...n] in...

implement two stacks in one array A[1...n] in such a way that neither stack overflows unless the total number of elements in both stacks together is n. For this you need to produce

Pointers, Pointers are just numbers, representing addresses in memory. You ...

Pointers are just numbers, representing addresses in memory. You can add to and subtract from pointers, for instance. It is pretty easy to make mistakes with pointer math, however,

Class booking system, I want source code for class booking system by using ...

I want source code for class booking system by using C++ Programming...Urgent

Dynamic constructor, dynamic initialization of object using constructor in ...

dynamic initialization of object using constructor in C++

Algorithm, Sine function computation

Sine function computation

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