//Person.h #pragma once #include using namespace std; class Person { private: string gender; int weight, height; public: Person(string gender, int weight, int height); string to_string() const; double ibm() const; }; struct comp { bool operator() (const Person& l, const Person& r) { return l.ibm() > r.ibm(); } }; // Person.cpp #include "Person.h" #include Person::Person(string gender, int weight, int height) { this->gender = gender; this->weight = weight; this->height = height; } string Person::to_string() const { stringstream ss; ss << ibm() << endl; return ss.str(); } //Source.cpp #include #include #include #include #include"Person.h" using namespace std; template T convert(string& s) { stringstream conv(s); T t; conv >> t; return t; } void load(ifstream& in, priority_queue, comp > pq;) { string line, gender, temp; int weight, height; while (getline(in, line)) { stringstream ss(line); getline(ss, temp, ','); // 1 getline(ss, gender, ','); //M getline(ss, temp, ',');// 77 weight = convert(temp); getline(ss, temp, ','); //182 height = convert (temp); pq.emplace(gender, weight, height); } } int main() { ifstream in("itm.csv"); if (!in) { cout << "404" << endl; return 1; } priority_queue, comp > pq; load(in, pq); in.close(); while (!pq.empty()) { cout << pq.top().to_string() << endl; pq.pop(); } return 0; }