hOW TO Defines the entry point for the console application.

// Lab4_2.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <iostream>
#include <cstdlib>

using namespace std;
class Gen{
int p, k;
public:
Gen(){ p = 0; k = 0; }
Gen(int a, int b)
{
p = a;
k = b;
}

int operator () (){
return (p + rand() % +(k - p));
}
};
class PozaPrzedzialem
{
int a, b;
public:
PozaPrzedzialem(){ a = 0; b = 0; }
PozaPrzedzialem(int _a, int _b)
{
a = _a;
b = _b;
}
bool operator ()(int p)
{
return ((p<a) || (p>b));
}
};
class Przedzial
{
int a, b;
public:
Przedzial(){}
Przedzial(int _a, int _b)
{
a = _a;
b = _b;
}
bool operator()(int p)
{
return ((p >= a) && (p <= b));
}
};

int _tmain(int argc, _TCHAR* argv[])
{
vector<int>vec(40);
generate(vec.begin(), vec.end(), Gen(1, 100));
sort(vec.begin(), vec.end());
cout << "caly wektor:" << endl;
copy(vec.begin(), vec.end(), ostream_iterator<int>(cout, " "));
cout << endl;
list <int> lst;
cout << endl << endl;
cout << "Poza przedzialem [27,83]";
cout << endl;
//copy(vec.begin(), vec.end(), ostream_iterator<int>(cout, " "));

remove_copy_if(vec.begin(), vec.end(), back_inserter(lst), PozaPrzedzialem(27, 83));
remove_if(vec.begin(), vec.end(), Przedzial(27, 83));
copy(vec.begin(), vec.end(), ostream_iterator<int>(cout, " "));
cout << endl;
//vec.erase(remove_if(vec.begin(), vec.end(), Przedzial(27, 83)), vec.end());
//cout << endl;
cout << "Lista z przedzialem: " << endl;
copy(lst.begin(), lst.end(), ostream_iterator<int>(cout, " \t"));
//copy(vec.begin(), vec.end(), ostream_iterator<int>(cout, " "));


cout << endl;
cout << endl;
system("pause");

return 0;
}


Learn More :