Sunteți pe pagina 1din 1

CPSC2150:Instructor Nalin Wijesinghe

Assignment 1: design Due September 09, 08


Naoya Makino: 100106040
Purpose: Design a currency ADT what will handle currencies without round off errors.
Assumptions
• Two decimal point. ie) 1,234,567,890.12
• It does not handle over two decimal places.
• The currency representation of given output is in English.
• There is “,” at every three digits. Ie) 1,234,567,890.12
• Operations are done with the same currency. Ie) $1.00 + $2.00 = $3.00
• This does not handle currency conversions.
• Amount is able to handle a range of 0.00 to 99,999.99 inclusive (incrementing by a
penny.)

Currency ADT
Method Description Implementation
Constructors
Currency(string symbol, string Create a new amount
name, double amount)
Currency(Currency &that) A copy constructor
~Currency() A deconstructor
Accessors
String english(currency amount) returns an English currency
representation of the given amount
Currency english( string words ) returns the numerical currency
amount given some English text
void print_out_amount() Display an amount in a number
Mutators
Void change_amount(int amount) Enter new amount
Overloading
Currency operator+(const Add two amounts Amount1 + amount2
Currency&)
Currency operator-(const Subtracts two amounts Amount1 – amount2
Currency&)
Currency operator*(const Multiply an amount Amount1 * int
Currency&)
Currency operator+/(const Divide an amount Amount1 / int
Currency&)
Private:
double amount Amount * 100 to handle round-off
errors
String symbol Currency symbols such as $
A solution to the round-off errors
After an operation, Amount * 100 and divide by 100 when I see an answer of the operation.
Sample: 10/3 = 3.33 -> 3.33*100 = 333. And do some operations such as (333*2 = 999)
Then the amount divides by 100 to get an answer. 999/100 = 9.99 but not 10.00
Sample Users input
Currency amount1($, dollar, 0.0);
amount1.change_amount(123456);
amount1.print_out_amount();//displays “$1,234.56”
Currency amunt2($, dollar, 0.0);
Currency amount3($, dollar, 0.0);
amount2.change_amount(7890);
amount3 = amount1 + amount2; // add amount1 and amount2 to amount3

S-ar putea să vă placă și