Should An Array Of Class Objects Be Used On This Trade Stock Project C++

Hello, I was wondering if I could get advice on a project me and my friend are working on. Basically it's on a Trade Stock based system that is user interactive, and right now we're trying to make it possible for the user to be able to insert the Amount of shares they want to buy of one stock. We're thinking of using an ARRAY OF CLASS OBJECTS method to solve this issue, but we keep getting stuck on it. Can someone please explain if that might be helpful or if we need to use something else? If you'd like to see the main file, I'll post it in a comment, just because it's too long for it to be here. Any advice would really be helpful, please respond soon, Thank You.

STOCK.H
#ifndef STOCK_H
#define STOCK_H

#include<iostream>
#include<string>
using namespace std;

class Stock
{

public:
Stock(const string, const string, double, int = 500); // number of shares defaults to 500 if nothing is entered in
//Stock s[int];

void setCompanyName(const string);
string getCompanyName();

void setTradingTicker(const string);
string getTradingTicker();

void setPricePerShare(double);
double getPricePerShare();

void setNumOfAvailableShares(int);
int getNumOfAvailableShares();

//const Stock operator=(const Stock &); //copy constructor


private:
string CompanyName;
string TradingTicker;
double PricePerShare;
int NumberOfShares;
};

#endif

STOCK.CPP
#include<iostream>
#include "Stock.h"
using namespace std;

Stock::Stock(const string cname, const string trade, double price, int amount)
{
setCompanyName(cname);
setTradingTicker(trade);
setPricePerShare(price);
setNumOfAvailableShares(amount);
}

void Stock::setCompanyName(const string cname)
{
CompanyName = cname;
}

string Stock::getCompanyName()
{
return CompanyName;
}

void Stock::setTradingTicker(const string trade)
{
if((trade.length() > 1) && (trade.length() < 4))
TradingTicker = trade;
else
throw invalid_argument ( "Trading ticker name must be more than 1 character and less than 4 characters.");
}

string Stock::getTradingTicker()
{
return TradingTicker;
}

void Stock::setPricePerShare(double price)
{
if(price > 0)
PricePerShare = price;
else
throw invalid_argument ("Price must be greater than 0.");
}

double Stock::getPricePerShare()
{
return PricePerShare;
}

void Stock::setNumOfAvailableShares(int amount)
{
if(amount > 0)
NumberOfShares = amount;
else
throw invalid_argument ("Invalid number of shares entered. Number of shares set to 500.");
}

int Stock::getNumOfAvailableShares()
{
return NumberOfShares;
}

ACCOUNT.H
#include<iostream>
#include "Stock.h"
#include <string>

#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account
{
public:
Account(const string, double, const int, Stock s[5]);

void setAccountName(const string);
string getAccountName();
void buyStock(Stock&, Stock s[5], Account&);
void sellStock(Stock&, Stock s[5], Account&);

void setAccountFunds(double);
double getAccountFunds();

void setAccountID(const int);
int getAccountID();

friend class Stock;
//void

private:
string AccountName;
double AccountFunds;
int AccountID;
};

#endif

ACCOUNT.CPP
#include <iostream>
#include <vector>
#include "Account.h"
#include "Stock.h"
using namespace std;

Account::Account(const string userName, double money, const int identification, Stock s[5])
{
setAccountName(userName);
setAccountFunds(money);
setAccountID(identification);
}

void Account::setAccountName(const string userName)
{
AccountName = userName;
}

string Account::getAccountName()
{
return AccountName;
}

void Account::setAccountFunds(double money)
{
if(money > 0)
AccountFunds = money;
else
throw invalid_argument ("Negative funds entered.");
}
double Account::getAccountFunds()
{
return AccountFunds;
}

void Account::setAccountID(const int identification)
{
AccountID = identification;
}

int Account::getAccountID()
{
return AccountID;
}

/*void Account::buyStock(Stock&, Stock s[5], Account&)
{
vector < Stock * > stocks( 5 );

stocks[0] = 0;
stocks
Stock *stockObj = new Stock s[5];
//Stock[] stockObj = new Stock[5];
*/
We're thinking of using an ARRAY OF CLASS OBJECTS method to solve this issue, but we keep getting stuck on it.
When it comes to design look at the real world. Where do stocks and accounts reside? The answer: Bank.

In other words: Make another class like Bank where you implement buyStock() and which has the vector for Stock and Account
Topic archived. No new replies allowed.