Instructions
Objective
Write a C++ assignment program to implement portfolios.
Requirements and Specifications
C++ Programming Assignment 7
Portfolio
Classes are getting to be more realistic with each programming assignment. This assignment includes the valuable aspect of inheritance to facilitate reuse of code and operator overloading to allow the usage of familiar operators tailored specifically to the Stocks, Bonds, and Securities classes.
The objective of this assignment is to demonstrate an ability to implement inheritance and overload operators in a program.
Instructions
You are working for a financial advisor who creates portfolios of financial securities for his clients. A portfolio is a conglomeration of various financial assets, such as stocks and bonds, that together create a balanced collection of investments.
When the financial advisor makes a purchase of securities on behalf of a client, a single transaction can include multiple shares of stock or multiple bonds.
For example:
Client-A purchases 100 shares of IBM $1 par value common stock on Jan. 20, 2020, for a total purchase price of $10,000 USD. Dividends for the year have been declared at $5 per share of common.
Client-A purchases 5 bonds is1sued by Intel Corporation with a face value of $1000 per bond and a stated interest rate of 7.5% on Jan 3, 2020, for a total purchase price of $5,000 USD. The bonds mature on Dec. 31, 2025.
It is your job to create an object-oriented application that will allow the financial advisor to maintain the portfolios for his/her clients. You will need to create several classes to maintain this information: Security, Stock, Bond, Portfolio, and Date.
The characteristics of stocks and bonds in a portfolio are shown below:
Stocks | Bonds |
---|---|
Purchase date (Date) | Purchase date (Date) |
Purchase price (double) | Purchase price (double) |
Quantity purchased (int) | Quantity purchased (int) |
Ticker symbol (string) | Issuer (string) |
Par value (int) | Face value (int) |
Stock type (i.e. Common or Preferred) (enum) | Stated interest rate (double) |
Dividends per share (double) | Maturity date (Date) |
Several of the data members above require the use of dates. Strings will not be acceptable substitutes for date fields.
Source Code
#ifndef portfolio_h
#define portfolio_h
#include
#include
#include
#include
#include "stock.h"
#include "bond.h"
using namespace std;
// Create a portfolio that holds stocks and bonds
class Portfolio
{
public:
// Create a portfolio
Portfolio()
{
name = "";
}
// Initialize the name
void setName(const string &name)
{
this->name = name;
}
// Return the name
string getName() const
{
return name;
}
// Allow adding of stock
void addSecurity(const Stock &stock)
{
stocks.push_back(stock);
}
// Add a bond
void addSecurity(const Bond &bond)
{
bonds.push_back(bond);
}
// Display the contents of the portfolio
friend ostream& operator << (ostream &output, Portfolio &portfolio)
{
if (!portfolio.stocks.empty())
{
// Sort the stocks
sort(portfolio.stocks.begin(), portfolio.stocks.end());
output << "These are the STOCKS in your " << portfolio.name << " portfolio:" << endl;
for (unsigned i = 0; i < portfolio.stocks.size(); i++)
output << portfolio.stocks[i] << endl;
}
if (!portfolio.bonds.empty())
{
//Sort the bonds
sort(portfolio.bonds.begin(), portfolio.bonds.end());
output << "These are the BONDS in your " << portfolio.name << " portfolio:" << endl;
for (unsigned i = 0; i < portfolio.bonds.size(); i++)
output << portfolio.bonds[i] << endl;
}
return output;
}
private:
string name;
vector stocks;
vector bonds;
};
#endif
Similar Samples
Discover exemplary samples of completed programming assignments at ProgrammingHomeworkHelp.com. Our carefully selected examples demonstrate our proficiency in tackling diverse coding challenges. Whether you need assistance with Java, Python, or any other language, explore our samples to see how we ensure top-quality solutions for students worldwide. Visit us today to experience expert guidance in programming homework
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++
C++