Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6. struct temperatury{
  7.     std::string data;
  8.     std::string czas;
  9.     double predkosc_dz;
  10.     double temp_dzwiekiem;
  11.     double cis_atm;
  12.     double temperatura;
  13.     double wilgotnosc;
  14.     std::string kompas;
  15.     double predkosc_uv;
  16.     double predkosc_wiatru;
  17.     std::string kierunek;
  18.     double wysokosc;
  19.     double temp_wew_pom;
  20. };
  21. void min_max_med (std::vector<temperatury> &wektor){
  22.         for (unsigned int i=1; i<wektor.size(); i++){
  23.             for (int j=wektor.size()-1; j>=1;j--){
  24.                 if (wektor[j].temperatura < wektor[j-1].temperatura){
  25.                     temperatury bufor;
  26.                     bufor = wektor[j-1];
  27.                     wektor[j-1]=wektor[j];
  28.                     wektor[j]= bufor;
  29.                 }
  30.             }
  31.         }
  32.         int d = wektor.size()-1;
  33.         int m = wektor.size()/2;
  34.         std::cout<<"Najwyzsza temperatura to: "<< wektor[d].temperatura<<std::endl;
  35.         std:: cout << "Najnizsza temperatura to: " << wektor[0].temperatura<<std::endl;
  36.         std:: cout << "Mediana to: " << wektor[m].temperatura << std::endl;
  37. };
  38.  
  39.  
  40. int main()
  41. {   std::fstream file("temp02-2020.csv");
  42.     std::vector<temperatury> temper;
  43.     if (file.is_open()) {
  44.         std::string line;
  45.         std::getline(file, line);
  46.         while (std::getline(file, line)){
  47.             std::stringstream str(line);
  48.             temperatury t;
  49.             std::getline(str, t.data, ',');
  50.             std::getline(str, t.czas, ',');
  51.             std::string double_str;
  52.             std::getline(str, double_str, ',');
  53.             t.predkosc_dz = std::stod(double_str);
  54.             std::getline(str, double_str, ',');
  55.             t.temp_dzwiekiem = std::stod(double_str);
  56.             std::getline(str, double_str, ',');
  57.             t.cis_atm = std::stod(double_str);
  58.             std::getline(str, double_str, ',');
  59.             t.temperatura = std::stod(double_str);
  60.             std::getline(str, double_str, ',');
  61.             t.wilgotnosc = std::stod(double_str);
  62.             std::getline(str, t.kompas, ',');
  63.             std::getline(str, double_str, ',');
  64.             t.predkosc_uv = std::stod(double_str);
  65.             std::getline(str, double_str, ',');
  66.             t.predkosc_wiatru = std::stod(double_str);
  67.             std::getline(str, t.kierunek, ',');
  68.             std::getline(str, double_str, ',');
  69.             t.wysokosc = std::stod(double_str);
  70.             std::getline(str, double_str, ',');
  71.             t.temp_wew_pom = std::stod(double_str);
  72.             temper.emplace_back(t); }
  73.         min_max_med(temper);
  74.           }
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement