Answer to Question #30816 in C++ for Jake

Question #30816
Define an array of 10 CStockAccount elements.

#include <iostream>
#include <string>
#include "StockHolding.h"
using namespace std;

class CStockAccount
{
public:
//default constructor to initialize the ID to “NoID” and the cash balance to 10,000
CStockAccount(void);
//parameterized constructor to initialize the ID and the cash balance to specific values
CStockAccount(string, double);
//destructor. Should be empty.
~CStockAccount(void);

void addStock();
void addStock(string, int);
void addStock(CStockHolding);

void deleteStock();
void deleteStock(string, int);
void deleteStock(CStockHolding);

void list();

//data member for the ID
string m_ID;
//data member for the cash balance
double m_CashBalance;
//data member for 10 stock holdings
CStockHolding m_Holdings[10];

private:
//private function to find the index of the stock symbol in the array m_Holdings.
//Return -1 if not found.
int searchSymbol(string);
//private memb
1
Expert's answer
2013-05-20T04:07:42-0400
There are at least 3 ways to do it. 1. Declare array of objects:
CStockAccount stock_accounts[10];
toaccess you can do such things like:
stock_accounts.addStock(); and so on

2. Declare pointer to array (but dont forget to deleteit)
CStockAccount* p_stock_accounts = new CStockAccount[10] ; //dosomething
delete[] p_stock_account;
3. Declare vector (or list) from STL
#include<vector>
usingnamespace std;

vector<CStockAccount> stock_account (10);

You also can addand delete elements from vector. And memory will be freed automatically.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
21.05.13, 14:31

You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!

Jake
20.05.13, 18:01

I appreciate your generosity for your helpfulness

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS