Im not sure if Im doing this right but i need some help with this problem. I just have some of the basic stuff right now. Not sure what variables to use for calculating an investment. Thanks if anyone could help a bit.
Problem:
Create an Investment class that includes the appropriate data members for various types of investments. Write appropriate get and set functions for each data member.
Also include a data member that holds the investment’s total value. Use a parameterized constructor to receive the name of each investment in a string* pointer. Be sure to include a destructor to clean up the heap when each object is destroyed. Also include a static data member and a static member function that calculates the total worth of an investment portfolio by adding together the total value of data members for each instantiated object. Add the Investment class to a console application, and then instantiate an Investment object and initialize its data. Create two additional Investment objects by copying the original object. You will need to write a copy constructor for when you duplicate objects. Retrieve and print the data members for each object. Also print the contents of the static data member using a statement similar to “Your investments are worth a total of $100,000.”
Header File:
Code:
#include <iostream>
#include <string>
using namespace std;
class Investment
{
public:
Investment();
void Investment(string*);
~Investment();
string* getName();
int getValue();
void setValue();
void setName(string*);
double calcInvestment(double);
private:
static long totalInvestment;
int iNumInvestments;
};
Main:
Code:
#include <iostream>
#include "Investment.h"
using namespace std;
int main()
{
cout << "Your investment is worth a total of " << totalInvestment;
};
Implementation:
Code:
Investment::Investment()
{
pName = new string;
}
void Investment::Investment(string* pName)
{
pName = new string;
*pName =
}
Investment::~Investment()
{
delete pName;
cout << "Previous Investment deleted" << endl;
}
string* Investment::getName(void) const
{
return *pName;
}
void Investment::setName()
{
return pName;
}
void Investment::setValue()
{
return sharesValue;
}
int Investment::getValue()
{
return sharesValue;
}
Here is what the output is supposed to be:
Code:
Your investment in Cisco
based on 100 shares at $67.5
is worth $6750
Your investment in Janus Fund
based on 200 shares at $98.5
is worth $19700
Your investments are worth a total of $26450
Your investment in California Municipal Bonds
based on 500 shares at $23.5
is worth $11750
Your investments are worth a total of $38200