Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- // library
- #include <string>
- #include <vector>
- #include <fstream>
- #include <iostream>
- using std::string;
- using std::vector;
- using std::ifstream;
- using std::ios;
- using std::cerr;
- struct Data {
- string country_name;
- int num_of_days_since_first_case;
- int num_of_current_cases;
- };
- class CovidData {
- private:
- vector<Data>* covid_data;
- size_t num_of_data;
- public:
- CovidData() {
- covid_data = new vector<Data>;
- num_of_data = 0;
- }
- int readData(string filename) {
- ifstream file(filename, ios::in);
- if (!file.is_open()) {
- cerr << "file cannot be open";
- }
- while (!file.eof()) {
- Data d;
- file >> d.country_name
- >> d.num_of_days_since_first_case
- >> d.num_of_current_cases;
- covid_data->push_back(d);
- num_of_data++;
- }
- return num_of_data;
- }
- int getMinCases(string country) {
- int min_cases = -1;
- for (const Data& elem : *covid_data) {
- if (elem.country_name == country) {
- if (elem.num_of_current_cases < min_cases
- || min_cases == -1)
- min_cases = elem.num_of_current_cases;
- }
- }
- return min_cases;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement