/* Client program that uses financial classes. Output: value: $1234.56 cost: $1234.56 profit: $ 0.00 value: $ 475.00 cost: $ 500.00 profit: $ -25.00 value: $3500.00 cost: $2000.00 profit: $1500.00 value: $1234.56 cost: $1234.56 profit: $ 0.00 value: $ 475.00 cost: $ 500.00 profit: $ -25.00 value: $3500.00 cost: $2000.00 profit: $1000.00 */ #include #include #include "Cash.h" #include "Stock.h" #include "DividendStock.h" using namespace std; // declarations for functions to print info about various kinds of assets. void printInfo(const Cash& cash); void printInfo(const Stock& stock); void printInfo(const DividendStock& dividend); int main() { // create several investments Cash* cash = new Cash(1234.56); Stock* stock = new Stock("MSFT"); stock->purchase(50, 10.00); stock->setSharePrice(9.50); DividendStock* dividend = new DividendStock("INTC"); dividend->purchase(100, 20.00); dividend->payDividend(5.00); dividend->setSharePrice(30); // display info about each investment cout << setprecision(2); cout << fixed; printInfo(*cash); printInfo(*stock); printInfo(*dividend); delete cash; delete stock; delete dividend; return 0; } // Prints information about a Cash asset. void printInfo(const Cash& asset) { cout << " value: $" << setw(7) << asset.marketValue() << endl; cout << " cost: $" << setw(7) << asset.cost() << endl; cout << "profit: $" << setw(7) << asset.profit() << endl << endl; } // Prints information about a Stock asset. void printInfo(const Stock& asset) { cout << " value: $" << setw(7) << asset.marketValue() << endl; cout << " cost: $" << setw(7) << asset.cost() << endl; cout << "profit: $" << setw(7) << asset.profit() << endl << endl; } // Prints information about a DividendStock asset. void printInfo(const DividendStock& asset) { cout << " value: $" << setw(7) << asset.marketValue() << endl; cout << " cost: $" << setw(7) << asset.cost() << endl; cout << "profit: $" << setw(7) << asset.profit() << endl << endl; }