MAKE YOUR LIFE EASIER BY USING VECTOR ALGORITHMS

#include<iostream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<algorithm>
using namespace std;
int main(){
vector<int>prizebond;
vector<int>::iterator myiterator;
vector<int>::const_iterator iter;
cout<<"the government officials have decided to launch prize bonds scheme "<<endl<<endl;
prizebond.push_back(1200);
prizebond.push_back(2400);
prizebond.push_back(1500);

cout<<endl<<"then the  state bank official requested  to send him all data about total prizebonds "<<endl;
cout<<" no# " <<" prize bond ammount"<<endl<<endl;
 int x=1;
for(iter=prizebond.begin();iter<prizebond.end();iter++){

cout<<" "<<x++<<"  "<<*iter<<"   "<<endl;
}
cout<<endl<<"then the government official decided to add anothr prize bond "<<endl;
prizebond.insert(prizebond.begin(),1000);
cout<<"then one official decided to shuffle all prize bonds "<<endl;
srand(static_cast<unsigned int>(time(0)));
random_shuffle(prizebond.begin(),prizebond.end());
cout<<endl<<"now our vector of prizebond looks like "<<endl<<endl;
x=1;
for(iter=prizebond.begin();iter<prizebond.end();iter++){

cout<<" "<<x<<"  "<<*iter<<"   "<<endl;
x++;
}
cout<<"then the prizebond committe decided to sort them in ascending order "<<endl;
sort(prizebond.begin(),prizebond.end());
cout<<endl<<"now our vector of prizebond looks like "<<endl<<endl;
x=1;
for(iter=prizebond.begin();iter<prizebond.end();iter++){

cout<<" "<<x++<<"  "<<*iter<<"   "<<endl;
}
cout<<"the director of state bank decided to search some prizebonds from data "<<endl;
cout<<"enter prizebond value "<<endl;
int value;
cin>>value;
iter=find(prizebond.begin(),prizebond.end(),value);
if(iter!=prizebond.end()){
cout<<"the prizebond is present in the vector "<<endl;
}
}




Previous
Next Post »

Comments:

Disqus Shortname