Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void plus300(vector<auta> &x, vector<auta> &plus) {
- vector<auta>::iterator iter;
- for (auto itr = x.begin(); itr != x.end(); ++itr) {
- if (itr->power >= 300) {
- iter = itr;
- plus.push_back(*iter);
- }
- }
- cout << plus.size() << " samochodow przekroczylo bariere 300" << endl << endl;
- }
- bool najmniejszy(auta a1, auta a2) {
- if (a1.year < a2.year)
- return true;
- else
- return false;
- }
- void first300(vector<auta> &plus) {
- vector<auta>::iterator itr = min_element(plus.begin(), plus.end(), najmniejszy);
- cout << "Pierwszy bariere 300 przekroczyl " << itr->model << " w roku " << itr->year << endl;
- }
- bool sortByYear(auta a1, auta a2) {
- if (a1.model < a2.model)
- return true;
- else
- return false;
- }
- void sortowanie(vector<auta> &x) {
- fstream plik;
- plik.open("cars_sorted.txt", ios::out);
- if (plik.is_open()) {
- sort(x.begin(), x.end(), sortByYear);
- for (auto &itr : x) {
- plik << itr.year << "|" << itr.country << "|" << itr.model << "|" << itr.power << endl;
- }
- }
- else
- cout << "ERROR SORT!" << endl;
- }
- bool theFastest(auta a1, auta a2) {
- if (a1.power < a2.power)
- return true;
- else
- return false;
- }
- void najszybszy(vector<auta> &x) {
- vector<auta>::iterator itr = max_element(x.begin(), x.end(), theFastest);
- cout << "Model: " << itr->model << endl;
- cout << "Rok: " << itr->year << endl;
- cout << "Kraj: " << itr->country << endl;
- cout << "Moc: " << itr->power << endl;
- }
- void zad1() {
- fstream file;
- file.open("auta2.txt", ios::in);
- vector<auta> v_cars;
- vector<auta> above300;
- auta car;
- if (file.is_open()) {
- while (!file.eof()) {
- char tmp;
- string lastString;
- file >> car.year; file >> tmp;
- getline(file, car.country, ';');
- getline(file, car.model, ';');
- file >> car.power; file >> lastString;
- v_cars.push_back(car);
- }
- plus300(v_cars, above300);
- first300(above300);
- sortowanie(v_cars);
- najszybszy(v_cars);
- /*for (auto &itr : v_cars)
- cout << itr.year << "|" << itr.country << "|" << itr.model << "|" << itr.power << endl;*/
- }
- else
- cout << "ERROR!" << endl;
- file.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement