[CODE=cpp]#include<iostre am>
#include<iomani p>
using namespace std;
class Currency
{
public:
Currency(double v = 0.0)
{
unit = v;
cent = int((v - unit) * 100.0 + 0.5);
}
virtual void display(ostream & out) = 0;
protected:
unsigned int unit;
unsigned int cent;
};
class USDollar : public Currency
{
public:
USDollar(double v = 0.0) : Currency(v)
{}
virtual void display(ostream & out)
{
out << unit << ". " << setfill("0") << setw(2) << cent << setfill(" ") << " $";
}
};
class DMark : public Currency
{
public:
DMark(double v = 0.0) : Currency(v)
{}
virtual void display(ostream & out)
{
out << unit << ". " << setfill("0") << setw(2) << cent << setfill(" ") << " DM";
}
};
ostream& operator<<(ostr eam& o, Currency& c)
{
c.display(o);
return o;
}
void fn( Currency& c)
{
cout << c << "\n";
}
int main(int argcs, char* pArgs[])
{
USDollar usd(1.50);
fn(usd);
DMark d(3.00);
fn(d);
return 0;
}[/CODE]
I honestyl don't know what's wrong with this code. I'm using Microsoft Visual C++ 2005 Express Edition. It simply doesn't compile. Any help?
#include<iomani p>
using namespace std;
class Currency
{
public:
Currency(double v = 0.0)
{
unit = v;
cent = int((v - unit) * 100.0 + 0.5);
}
virtual void display(ostream & out) = 0;
protected:
unsigned int unit;
unsigned int cent;
};
class USDollar : public Currency
{
public:
USDollar(double v = 0.0) : Currency(v)
{}
virtual void display(ostream & out)
{
out << unit << ". " << setfill("0") << setw(2) << cent << setfill(" ") << " $";
}
};
class DMark : public Currency
{
public:
DMark(double v = 0.0) : Currency(v)
{}
virtual void display(ostream & out)
{
out << unit << ". " << setfill("0") << setw(2) << cent << setfill(" ") << " DM";
}
};
ostream& operator<<(ostr eam& o, Currency& c)
{
c.display(o);
return o;
}
void fn( Currency& c)
{
cout << c << "\n";
}
int main(int argcs, char* pArgs[])
{
USDollar usd(1.50);
fn(usd);
DMark d(3.00);
fn(d);
return 0;
}[/CODE]
I honestyl don't know what's wrong with this code. I'm using Microsoft Visual C++ 2005 Express Edition. It simply doesn't compile. Any help?
Comment