//======================================================================= // Please gloss over the details of this first section. // // The code provides a convenient utility to generically convert // objects to their string representation, but I don't want to explain // how it works at this point in time. #include #include template std::string ToString(const T& val) { std::stringstream strm; strm << val; return strm.str(); } //======================================================================= #include "CreditCard.h" // provides CreditCard // standard constructor CreditCard::CreditCard(string no, string nm, int lim, double bal) { number = no; name = nm; balance = bal; limit = lim; } // make a charge bool CreditCard::chargeIt(double price) { if (price + balance > double(limit)) return false; // over limit balance += price; return true; // the charge goes through } // card information as string string CreditCard::toString() const { string result; result = "Number = " + number + "\n" + "Name = " + name + "\n" + "Balance = " + ToString(balance) + "\n" + "Limit = " + ToString(limit) + "\n"; return result; } std::ostream& operator<<(std::ostream& out, const CreditCard& c) { out << c.toString(); return out; }