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

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

 

Posted Date: 3/25/2013 1:04:29 AM | Location : United States







Related Discussions:- Write a procedure to add and subtract-money, Assignment Help, Ask Question on Write a procedure to add and subtract-money, Get Answer, Expert's Help, Write a procedure to add and subtract-money Discussions

Write discussion on Write a procedure to add and subtract-money
Your posts are moderated
Related Questions
Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules. a. A call made between 8:00 AM and

write a programme that computes the price of shares and options. do the options in one-period binomial model.

Ques.Implement a c/c++ program to find a shortest path between two nodes in a network?network should be taken as an adjacency matrix.

A more advanced data type is the structure; here we can define a template as a collection of different variables e.g.     struct birthdate   {     int month;     int day;

Write a simple telephone book program that stores the names and phone numbers of your friends/acquaintances in a file. Your program should have the abilities to: a. Add entries (n

t a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with these

Relationship between an Array and Pointers. Consider the following. int arr[] = {0,1,2,3,4,5,6,7,8,9}; If we write arr , it is considered as the address of the first elem

please answer the question of following Write a function that calculates the number of elapsed days between two dates. For example the days between Feb 3, 1970 and June 21, 1980? B

Question 1 What is function overloading? Write a c++ program to implement a function overloaded Question 2 Explain about the constructors and Destructors with suitable exampl