Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <charconv>
- #include <fstream>
- using namespace std;
- class Island
- {
- public:
- string name = "";
- int area = NULL;
- string location;
- Island() {};
- Island(istream& input)
- {
- this->operator>>(input);
- }
- int get_area() const { return area; }
- ostream& display(ostream& output) const
- {
- return output << name << ' ' << area << ' ' << location;
- }
- void operator >> (istream& input)
- {
- string value;
- input >> name;
- input >> value;
- from_chars(value.data(), value.data() + value.size(), area);
- input >> location;
- }
- bool operator < (const Island& object)
- {
- return this->area < object.area;
- }
- bool operator >(const Island& object)
- {
- return this->area > object.area;
- }
- };
- ostream& operator <<(ostream& output, const Island& object)
- {
- return object.display(output);
- }
- int main()
- {
- const int N = 12;
- Island islands[N];
- fstream file;
- int max;
- string max_name;
- string max_loc;
- file.open("./island.txt");
- if (file.is_open())
- {
- int i = 0;
- while (not file.eof())
- {
- islands[i++] = Island(file);
- }
- max = islands[0].get_area();
- for (int i = 0; i < N; i++)
- if (islands[i].get_area() > max)
- {
- max = islands[i].get_area();
- max_name = islands[i].name;
- max_loc = islands[i].location;
- }
- }
- file.close();
- cout << "Max: " << max_name << ' ' << max_loc << endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement