Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // praca23012017
- //
- // Created by Maciej Więcek on 20.01.2017.
- // Copyright © 2017 Maciej Więcek. All rights reserved.
- //
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <string>
- using namespace std;
- struct samochodziki{
- int makeYear;
- string makeCountry;
- string model;
- int Vmax;
- };
- void exe2(vector<samochodziki> &samoch)
- {
- for(int i = 0; i < samoch.size(); i++)
- {
- if(samoch[i].Vmax > 300)
- {
- cout << "Pierwszym samochodem, ktory przekroczyl bariere 300 km/h byl " << samoch[i].model << " w roku " << samoch[i].makeYear << endl;
- break;
- }
- }
- }
- void exe1(vector<samochodziki> &samoch)
- {
- int amount = 0;
- for(int i = 0; i < samoch.size(); i++)
- if(samoch[i].Vmax > 300)
- amount++;
- cout << "Ile samochodow przekroczylo bariere 300 km/h?\n" << amount << endl;
- }
- int main()
- {
- fstream file( "/Users/prgres/Desktop/praca23012017/samochodziki.txt", ios::in);
- vector<samochodziki> samoch;
- string tempLine;
- if ( file.is_open())
- {
- while(!file.eof())
- {
- samochodziki newCar;
- getline (file, tempLine, ';');
- newCar.makeYear = stoi(tempLine);
- getline(file, newCar.makeCountry, ';');
- getline(file, newCar.model, ';');
- getline(file, tempLine, ' ');
- newCar.Vmax = stoi(tempLine);
- getline(file, tempLine, 'h');
- samoch.push_back(newCar);
- if(samoch.size() == 305)
- break;
- }
- exe1(samoch);
- exe2(samoch);
- }
- else
- cout << "Nie można otworzyć samochodziki.txt" << endl;
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement