fork(3) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. class treasure {
  7. public:
  8. std::string name;
  9. double value;
  10. double weight;
  11. };
  12. treasure item[] = {
  13. {"rice1", 40, 20},
  14. {"rice2", 50, 27},
  15. {"rice3", 35, 24}
  16. };
  17.  
  18. std::sort(item, item+3,
  19. [] (auto t1, auto t2) {return t1.value < t2.value;});
  20.  
  21. std::cout << std::endl << std::endl << "Item name: " << "\t" << "Item value(per kg): " << "\t" << "Item weight(in kg): " << std::endl;
  22. for (int i = 0; i < 3; i++) {
  23. std::cout << item[i].name << "\t\t" << item[i].value << "\t\t\t" << item[i].weight << std::endl;
  24. }
  25. }
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout

Item name: 	Item value(per kg): 	Item weight(in kg): 
rice3		35			24
rice1		40			20
rice2		50			27