Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // praca23012017
  4. //
  5. // Created by Maciej Więcek on 20.01.2017.
  6. // Copyright © 2017 Maciej Więcek. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <fstream>
  12. #include <string>
  13.  
  14. using namespace std;
  15.  
  16. struct samochodziki{
  17.  
  18. int makeYear;
  19. string makeCountry;
  20. string model;
  21. int Vmax;
  22. };
  23.  
  24. void exe2(vector<samochodziki> &samoch)
  25. {
  26.  
  27. for(int i = 0; i < samoch.size(); i++)
  28. {
  29. if(samoch[i].Vmax > 300)
  30. {
  31. cout << "Pierwszym samochodem, ktory przekroczyl bariere 300 km/h byl " << samoch[i].model << " w roku " << samoch[i].makeYear << endl;
  32. break;
  33. }
  34. }
  35.  
  36.  
  37. }
  38.  
  39. void exe1(vector<samochodziki> &samoch)
  40. {
  41. int amount = 0;
  42.  
  43. for(int i = 0; i < samoch.size(); i++)
  44. if(samoch[i].Vmax > 300)
  45. amount++;
  46.  
  47. cout << "Ile samochodow przekroczylo bariere 300 km/h?\n" << amount << endl;
  48. }
  49.  
  50. int main()
  51. {
  52. fstream file( "/Users/prgres/Desktop/praca23012017/samochodziki.txt", ios::in);
  53. vector<samochodziki> samoch;
  54.  
  55. string tempLine;
  56.  
  57. if ( file.is_open())
  58. {
  59.  
  60. while(!file.eof())
  61. {
  62. samochodziki newCar;
  63.  
  64. getline (file, tempLine, ';');
  65. newCar.makeYear = stoi(tempLine);
  66. getline(file, newCar.makeCountry, ';');
  67. getline(file, newCar.model, ';');
  68. getline(file, tempLine, ' ');
  69. newCar.Vmax = stoi(tempLine);
  70. getline(file, tempLine, 'h');
  71.  
  72. samoch.push_back(newCar);
  73.  
  74. if(samoch.size() == 305)
  75. break;
  76.  
  77. }
  78.  
  79. exe1(samoch);
  80. exe2(samoch);
  81.  
  82.  
  83. }
  84.  
  85. else
  86. cout << "Nie można otworzyć samochodziki.txt" << endl;
  87.  
  88. file.close();
  89.  
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement