CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <cmath>
using namespace std;
class Person {
private:
string name;
double height, weight; //cm and kg
public:
Person(string n, double h = 0, double w = 0)
{
name = n;
height = h; //cm
weight = w; //kg
}
double BMI() const{ return weight / pow( height / 100, 2); } //kg/m^2
string Name() const { return name; }
double Height() const { return height; }
double Weight() const { return weight; }
// sort by name
bool operator < (Person b) { return name < b.name; }
// sort by height
friend bool byHeight (const Person &a, const Person &b);
// to cout
friend ostream & operator << (ostream & o, const Person &p);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run