im doing an assignment on c++ and im stuck on how i would add a new transaction to my work, with a user defined numShares, and pricePerShare.
i have a transaction struct which looks like this:
struct Transaction
{
string stockSymbol; // String containing the stock symbol, e.g. "AAPL"
string buyerName; // String containing the buyer's name e.g. "Mr Brown"
int buyerAccount; // Integer containing an eight digit account code
int numShares; // Integer containing the number of sold shares
int pricePerShare; // Integer containing the buy price per share
};
this is the buildTransaction class:
static Transaction* buildTransactions(int numTransactions)
{
int maxShareVolume = 100000;
int maxSharePrice = 1000;
Transaction *transactions = new Transaction[numTransactions];
for(int idx = 0; idx < numTransactions; idx++)
{
transactions[idx].stockSymbol = pickRandomStockSymbol();
std::string buyerName = pickRandomBuyer();
transactions[idx].buyerName = buyerName;
transactions[idx].buyerAccount = lookupBuyerAccount(buyerName);
transactions[idx].numShares = 1 + rand() % maxShareVolume;
transactions[idx].pricePerShare = 1 + rand() % maxSharePrice;
}
return transactions;
}
how would i use that to add data to the transactions array using this:
void Analyser::addTransactions(Transaction* transactions, int numTransactions)
i would assume from this that all i would really need to have as user input would be the amount of shares, and the price per share, but that the other information fills itself in automatically, from choosing from the arrays.