Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #pragma once
  2.  
  3. // library
  4. #include <string>
  5. #include <vector>
  6. #include <fstream>
  7. #include <iostream>
  8.  
  9. using std::string;
  10. using std::vector;
  11. using std::ifstream;
  12. using std::ios;
  13. using std::cerr;
  14.  
  15. struct Data {
  16.     string country_name;
  17.     int num_of_days_since_first_case;
  18.     int num_of_current_cases;
  19. };
  20.  
  21. class CovidData {
  22.     private:
  23.         vector<Data>* covid_data;
  24.         size_t num_of_data;
  25.  
  26.  
  27.     public:
  28.         CovidData() {
  29.             covid_data = new vector<Data>;
  30.             num_of_data = 0;
  31.         }
  32.  
  33.         int readData(string filename) {
  34.             ifstream file(filename, ios::in);
  35.  
  36.             if (!file.is_open()) {
  37.                 cerr << "file cannot be open";
  38.             }
  39.  
  40.             while (!file.eof()) {
  41.                 Data d;
  42.                 file >> d.country_name
  43.                      >> d.num_of_days_since_first_case
  44.                      >> d.num_of_current_cases;
  45.  
  46.                 covid_data->push_back(d);
  47.                 num_of_data++;
  48.             }
  49.  
  50.             return num_of_data;
  51.         }
  52.  
  53.         int getMinCases(string country) {
  54.             int min_cases = -1;
  55.  
  56.             for (const Data& elem : *covid_data) {
  57.                 if (elem.country_name == country) {
  58.                     if (elem.num_of_current_cases < min_cases
  59.                         || min_cases == -1)
  60.                         min_cases = elem.num_of_current_cases;
  61.                 }
  62.             }
  63.  
  64.             return min_cases;
  65.         }
  66.  
  67.  
  68. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement