Hi,
I am trying to display the contents of a vector.
The vector is defined from a class I created. I seem to be only storing the most recent values in my vector. I am not sure where my logic is incorrect. I am trying to store multiple objects in my vector. Any help would be greatly appreciated. Code is below:
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
class SalesOrder
{
int bidPrice, lots, accountNumber;
public:
void eSalesOrder(int, int, int);
bool executable(int);
void execute();
void showInfo(int&, int&, int&) const;
SalesOrder();
};
SalesOrder::SalesOrder() //default constructor
{
bidPrice = 0;
lots = 0;
accountNumber = 0;
}
int main(int argc, char* argv[])
{
cout<<"This is a simulated trading Program\n\n\n"
<<"Please choose from the following options\n\n"
<<"Choose \'B\' to Bid\n"
<<"Choose \'O'\ to change Offer Price\n"
<<"Choose \'Q'\ to Quit\n\n";
vector <SalesOrder> sOList;
int bP, l, aN;
unsigned int counter;
char selection;
selection = 'd';
while(selection != 'Q')
{
cin>>selection;
SalesOrder salesOrder;
switch (selection)
{
case 'b':
cout << "Please enter the bid Price, lots, and the account number, \neach followed by a space: ";
cin >> bP >> l >> aN;
salesOrder.eSalesOrder(bP, l, aN);
sOList.push_back(salesOrder);
for(counter = 0; counter < sOList.size(); counter++)
{
sOList[counter].showInfo(bP, l, aN);
}
break;
case 'B':
cout<<"B\n";
break;
case 'q':
cout<<"Q\n";
selection = 'Q';
break;
case 'Q':
cout<<"Q\n";
selection = 'Q';
break;
case 'O':
cout<<"O\n";
break;
case 'o':
cout<<"O\n";
break;
case 'd':
cout<<"Please make a selection\n";
break;
}//end switch
cout<<"Please choose from the following options\n\n"
<<"Choose \'B\' to Bid\n"
<<"Choose \'O'\ to change Offer Price\n"
<<"Choose \'Q'\ to Quit\n\n";
}//end while
system("pause");
return 0;
}
void SalesOrder::eSalesOrder(int bidPrice, int lots, int accountNumber)
{
bool reEnter = true;
while(reEnter == true)
{
cout<<"You entered bid price: "<<bidPrice<<"\n";
cout<<"You entered lots: "<<lots<<"\n";
cout<<"You entered account number: "<<accountNumber<<"\n\n\n";
if (lots % 100 > 0)
{
cout<<"Invalid Lots amount\n\n";
cout << "Please enter the bid Price, lots, and the account number, \neach followed by a space: ";
cin >> bidPrice >> lots >> accountNumber;
}//end if
else
reEnter = false;
}//end while
}//end eSalesOrder function
void SalesOrder::showInfo(int& bidPrice, int& lots, int& accountNumber) const
{
cout << "The bid price is " << bidPrice << "\n";
cout << "The lot size is " << lots << "\n";
cout << "The account number is " << accountNumber << "\n\n";
}