Hey,
Ok i needed quick help on vectors in C++.I have a vector which consits of a complete bidlist for Traders i.e Askers and Buyers. Now what i want to do is,Get the first ask bid and compare that with the Buy bids,via the price and quantity.

Now what i want to do is in another class called Simulator, i want to be able to get the first asker and compare it with the buyers via their prices and quantity.

How do extract the first element in the vector and compare it?Im new to vectors so im not quite sure on how to do it:S
This is what ive beena able to do so far:

``````class Bid
{
private:

public:
static int BidID;
{
bidID = Bid::BidID++;
}
//**************************************************

void show(ostream &out) const
{
}

//***************************************
void show2(ostream &out) const
{
}
//********************************************
void show3(ostream &out) const
{
}

//********************************************

bool operator<(const Bid &other) const
{
return price < other.price;
}

};

int Bid:: BidID=0;

//*******************Sets the values for the Bid List*********************************
Bid getBids()
{
int MinPrice=50, MaxPrice=150;
int range1=(MaxPrice-MinPrice)+1;
int MinQuantity=30, MaxQuantity=100;
int range2=(MaxQuantity-MinQuantity)+1;

int quantity = MinQuantity+int(range1*rand()/(RAND_MAX + 1.0));
int price =  MinPrice+int(range2*rand()/(RAND_MAX + 1.0));

int NUMBIDS=10;
int bidID = Bid::BidID;
if(bidID<NUMBIDS)
{
}
else
{
}

}

//*****************************************Adds the random values to the Vector*******************
void theBidlist(vector<Bid> &list)
{
int numbids=20;
for (int i=0;i<numbids;i++)
{
list.push_back(getBids());
}
}

//*******************************************Scans through the vector****************************
void show(const vector<Bid> &vect)
{
cout<<"********************************************"<<endl;

for(vector<Bid>::const_iterator sh=vect.begin(); sh != vect.end(); ++sh)
{
sh->show(cout);
}
cout << endl;
}

//****************************************************************************************************

void show2(const vector<Bid> &vect)
{

for(vector<Bid>::const_iterator sh=vect.begin(); sh != vect.end(); ++sh)
{
sh->show2(cout);
}
cout << endl;
}

//**************************************************************************************************

void show3(const vector<Bid> &vect)
{

for(vector<Bid>::const_iterator sh=vect.begin(); sh != vect.end(); ++sh)
{
sh->show3(cout);
}
cout << endl;
}
``````

(Does pretty much nothing for now.I needed it to work for matching.But im not sure on how to do it:S)

Simulator:

``````#include<iostream>
using namespace std;
class Simulator
{

vector<Bid> BidList;

public:
void run();

};

void Simulator::run()
{
theBidlist(BidList);
show(BidList);
cout<<"Bid list after sort:"<<endl;
sort(BidList.begin(), BidList.end());
show2(BidList);
show3(BidList);
}
``````

I dont need u to give me a whole program i just need help on figuring out on how i can actually get a element in a vector and compare it with the rest.

Please use code tags. Wrap all your code inside the code tags, like ..

[code]

[/code]

You still have ~15 minutes to edit your post.

## All 4 Replies

Please use code tags. Wrap all your code inside the code tags, like ..

[code]

[/code]

You still have ~15 minutes to edit your post.

Woopppsss didnt know that!sorry!

Uhh i cant edit it!:(

Il just post it again:S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.