Velocity Reviews > C++ > Currency Conversion using OO

# Currency Conversion using OO

Willing 2 Learn
Guest
Posts: n/a

 10-12-2005
I'm still having trouble getting my program to do arithmetic in
cents(keeping all #'s) then convert the answer in a format of dollars &

cents. The main program should add, subtract, scalar multiply(by int)&

show, have a constructor w/ & w/out arguments. Header file should have
private data & all 6 functions from above.Class definition file should
implement my ADT class.
What I have so far:
Main program
#include "jahcurrency.h"
#include <iostream.h>
void main()
{
Currency a(4,3);
Currency b(2,1);
Currency total;

total=a.add(b);
total.show();
total=a.sub(b);
total.show();
total=a.multiply(5);
total.show();

}

Header file
class Currency
{
private:
double cents;
public:
Currency();
Currency(int d,int c);
Currency add(Currency b);
Currency sub(Currency b);
Currency multiply(double d);
double calc(Currency s);
double calc2(Currency f);
void show(void);

};

Class definition
#include "jahcurrency.h"
#include <iomanip.h>
#include <math.h>
#include <iostream.h>

char sign='\$';

Currency::Currency()
{
x=0;

}

Currency::calc2(Currency f)
{

f=(x*100)-(x%100);

return f;

}

Currency::calc(Currency s)
{

s=(x%100);

return s;

}

Currency::Currency(int d, int c)
{

d=(x*100)-(x%100);
c=(x%100);

return d;

}

Currency::add(Currency b)
{
Currency x;
x.cents= x+ b.x;

return x;

}

Currency::sub(Currency b)
{
Currency x;
x.cents= x- b.x;

return x;

}

Currency::multiply(Currency d)
{
Currency x;
x.cents= x*d.x;

return x;

}

Currency::show()
{
cout<<sign<<d<<". "<<s<<endl;

}

How different would the program be if cents is in long then convert
ans. for each opeartion to dollars & cents ?
Your help would be appreciated in how to fix this problem.

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Willing 2 Learn C++ 2 10-12-2005 03:14 PM Willing 2 Learn C++ 3 10-11-2005 05:03 PM Just starting out C Programming 14 09-12-2005 02:38 AM Martyn Fewtrell ASP .Net 0 06-21-2005 03:59 PM powerranger ASP .Net Web Services 1 01-26-2004 06:57 AM

Advertisments