網頁

2017年11月15日 星期三

ex7 C++改寫算bmi成class,並排序

C++改寫算bmi成class,並排序

39 則留言:

  1. B10533062 洪尚郁2017年11月15日 下午2:49

    #include<iostream>
    #include<cstdlib>
    #include<algorithm>

    using namespace std;

    class Person {
    public:
    double h ;
    double w ;
    Person (){}
    Person(double h, double w) : h(h), w(w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for ( int i = 0; i < 4 ; i++)
    cout << X[i].bmi() << endl;

    cout << "========bmi_less========\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "==========W_less======\n";
    sort(X, X + 4, w_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "=========H_less========\n";
    sort(X, X + 4, h_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    system("pause");
    return 0;
    }

    回覆刪除
  2. #include<iostream>
    #include<cstdlib>
    #include<ctime>
    #include<random>
    #include<algorithm>
    class Person {
    public:
    double h;
    double w;
    Person() {};
    Person(double _h, double _w) :h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    using namespace std;
    int main() {
    int n = 0;
    cout << "請輸入人數: ";
    cin >> n;
    Person* X=new Person[n]; //指標
    mt19937_64 RV(time(0)); // 給亂數值 身高體重
    normal_distribution<double> H(172, 7.5);
    normal_distribution<double> W(60, 4.5);
    for (int i = 0; i < n; i++) {
    X[i] = Person(H(RV), W(RV));
    }
    cout << "原始BMI\n";
    cout << "==================\n";
    for (int i = 0; i < n; i++) { //原始排序
    cout << X[i].bmi() << endl; }
    cout << "排序後的BMI\n";
    sort(X, X + n, bmi_less); //排序
    cout << "==================\n";//bmi
    for (int i = 0; i<n; i++)
    cout << X[i].bmi() << endl;
    cout << "排序後的身高\n";
    cout << "==================\n";//height
    for (int i = 0; i<n; i++)
    cout << X[i].h << endl;
    cout << "排序後的體重\n";
    cout << "==================\n";//weight
    for (int i = 0; i<n; i++)
    cout << X[i].w << endl;
    cout << "==================\n";
    cout << "Hello~\n";
    delete[]X; //釋放記憶體
    system("PAUSE");
    }

    回覆刪除
  3. #include
    #include
    #include
    using namespace std;
    class person {
    public:
    double h;
    double w;
    Person()()
    Person(double_h, double, _v) : h(_h).w(_w) {}
    public
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << end1;
    cont << "\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << end;
    cout << "hello.\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  4. #include<iostream>
    #include<cstdlib>
    #include<ctime>
    #include<random>
    #include<algorithm>
    class Person {
    public:
    double h;
    double w;
    Person() {};
    Person(double _h, double _w) :h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    using namespace std;
    int main() {
    int n = 0;
    cout << "請輸入人數: ";
    cin >> n;
    Person* X=new Person[n]; //因陣列式變動的 VC需要用到指標 才能過編譯
    mt19937_64 RV(time(0)); // 給亂數值 身高體重
    normal_distribution<double> H(172, 7.5);
    normal_distribution<double> W(60, 4.5);
    for (int i = 0; i < n; i++) {
    X[i] = Person(H(RV), W(RV));
    }
    cout << "原始BMI\n";
    cout << "==================\n";
    for (int i = 0; i < n; i++) { //原始排序
    cout << X[i].bmi() << endl; }
    cout << "排序後的BMI\n";
    sort(X, X + n, bmi_less); //排序
    cout << "==================\n";//bmi
    for (int i = 0; i<n; i++)
    cout << X[i].bmi() << endl;
    cout << "排序後的身高\n";
    cout << "==================\n";//height
    sort(X, X + n, h_less);//排序
    for (int i = 0; i<n; i++)
    cout << X[i].h << endl;
    cout << "排序後的體重\n";
    cout << "==================\n";//weight
    sort(X, X + n, w_less);//排序
    for (int i = 0; i<n; i++)
    cout << X[i].w << endl;
    cout << "==================\n";
    cout << "Hello~\n";
    delete[]X; //釋放記憶體
    system("PAUSE");
    }

    回覆刪除
  5. #include<iostream>
    #include<cstdlib>
    #include<algorithm>

    using namespace std;

    class Person{
    public:
    double h ;
    double w ;
    Person(){}
    Person(double _h, double _w): h(_h),w(_w)
    {}
    public:
    double bmi()
    {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    cout << "BMI:\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    {
    cout << X[i].bmi() << endl;
    }
    cout << "===============\n";
    cout << "身高:\n";
    sort(X, X + 4, h_less);
    for (int e = 0; e < 4; e++)
    {
    cout << X[e].h << endl;
    }
    cout << "===============\n";
    cout << "體重:\n";
    sort(X, X + 4, w_less);
    for (int z = 0; z < 4; z++)
    {
    cout << X[z].w << endl;
    }
    cout << "===============\n";
    system("pause");
    return 0;
    }

    回覆刪除
  6. #include
    #include
    #include
    using namespace std;
    class person {
    public:
    double h;
    double w;
    Person()()
    Person(double_h, double, _v) : h(_h).w(_w) {}
    public
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << end1;
    cont << "\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << end;
    cout << "hello.\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  7. B10533007 魏辰熾2017年11月15日 下午3:38

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person(){}
    Person(double h, double w) :h(h), w(w) {}
    public:
    double bmi (){
    return 10000 * w / (h*h);

    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 5);
    X[1] = Person(50, 60);
    X[2] = Person(150, 60);
    X[3] = Person(172, 80);
    print(X);
    cout << "\nbmi 排序===================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    print(X);
    cout << "\nh 排序===================\n";
    sort(X, X + 4, h_less);
    print(X);

    print(X);
    cout << "\nw 排序===================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  8. B10533018 陳郁傑2017年11月15日 下午3:39

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person(){}
    Person(double h, double w) :h(h), w(w) {}
    public:
    double bmi (){
    return 10000 * w / (h*h);

    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 5);
    X[1] = Person(50, 60);
    X[2] = Person(150, 60);
    X[3] = Person(172, 80);
    print(X);
    cout << "\nbmi 排序===================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    print(X);
    cout << "\nh 排序===================\n";
    sort(X, X + 4, h_less);
    print(X);

    print(X);
    cout << "\nw 排序===================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  9. B10533062 洪尚郁2017年11月15日 下午3:40

    #include<iostream>
    #include<cstdlib>
    #include<algorithm>

    using namespace std;

    class Person {
    public:
    double h ;
    double w ;
    Person (){}
    Person(double h, double w) : h(h), w(w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for (int i = 0; i < 4; i++) {
    cout <<"身高:" << X[i].h << endl;
    cout << "體重:"<<X[i].w << endl;
    cout << "BMI:"<<X[i].bmi() << endl;
    }
    cout << "========bmi_less========\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++) {
    cout << "身高:" << X[i].h << endl;
    cout << "體重:" << X[i].w << endl;
    cout << "BMI:" << X[i].bmi() << endl;
    }
    cout << "==========W_less======\n";
    sort(X, X + 4, w_less);
    for (int i = 0; i < 4; i++) {
    cout << "身高:" << X[i].h << endl;
    cout << "體重:" << X[i].w << endl;
    cout << "BMI:" << X[i].bmi() << endl;
    }
    cout << "=========H_less========\n";
    sort(X, X + 4, h_less);
    for (int i = 0; i < 4; i++) {
    cout << "身高:" << X[i].h << endl;
    cout << "體重:" << X[i].w << endl;
    cout << "BMI:" << X[i].bmi() << endl;
    }
    system("pause");
    return 0;
    }

    回覆刪除
  10. b10433081 巫明芬2017年11月15日 下午3:41

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;

    class Person {
    public:
    double h ;
    double w ;
    Person() {}
    Person(double _h, double _w) : h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h <<"\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48,3);
    X[1] = Person(145,41);
    X[2] = Person(162,43);
    X[3] = Person(180, 88);

    print(X);
    cout << "\nbmi 排序========================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序========================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序========================\n";
    sort(X, X + 4, w_less);
    print(X);

    cout << "hello. 排序真好玩!\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  11. #include<iostream>
    #include<cstdlib>
    #include<ctime>
    #include<random>
    #include<algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person() {};
    Person(double _h, double _w) :h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person* X, int n) {
    for (int i = 0; i<n; i++)
    cout <<"bmi=\t" <<X[i].bmi()
    <<" h =\t" << X[i].h
    <<" w =\t" << X[i].w << endl;
    }

    int main() {
    int n = 0;
    cout << "請輸入人數: ";
    cin >> n;
    Person* X=new Person[n]; //因陣列式變動的 VC需要用到指標 才能過編譯
    mt19937_64 RV(time(0)); // 給亂數值 身高體重
    normal_distribution<double> H(172, 7.5);
    normal_distribution<double> W(60, 4.5);
    for (int i = 0; i < n; i++) {
    X[i] = Person(H(RV), W(RV));
    }
    cout << "原始BMI\n";
    cout << "==================\n";
    print(X, n);
    cout << "排序後的BMI\n";
    sort(X, X + n, bmi_less); //排序
    cout << "==================\n";//bmi
    print(X, n);
    cout << "排序後的身高\n";
    cout << "==================\n";//height
    sort(X, X + n, h_less);//排序
    print(X, n);
    cout << "排序後的體重\n";
    cout << "==================\n";//weight
    sort(X, X + n, w_less);//排序
    print(X, n);;
    cout << "==================\n";
    cout << "Hello~\n";
    delete[]X; //釋放記憶體
    system("PAUSE");
    }

    回覆刪除
  12. B10533011 江道逸2017年11月15日 下午3:42

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  13. B10533006 劉純賓2017年11月15日 下午3:42

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;

    class person {
    public:
    double h = 0;
    double w = 0;
    person(){}
    person(double _h, double _w) : h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000*w/(h*h);
    }
    };

    bool bmi_less(person x, person y) {
    return x.bmi() < y.bmi();
    }

    bool h_less(person x, person y) {
    return x.h < y.h;
    }

    bool w_less(person x, person y) {
    return x.w < y.w;
    }

    void print(person x[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << x[i].h << "\tw=" << x[i].w << "\tbmi=" << x[i].bmi() << endl;
    }
    int main()
    {
    person x[4];
    x[0] = person(48, 3);
    x[1] = person(170, 70);
    x[2] = person(175, 76);
    x[3] = person(172, 64);

    print(x);
    cout << "\nbmi 排序=============\n";
    sort(x, x + 4, bmi_less);
    print(x);

    cout << "\nh 排序=============\n";
    sort(x, x + 4, h_less);
    print(x);

    cout << "\nw 排序=============\n";
    sort(x, x + 4, w_less);
    print(x);

    cout << "hello. 排序真好玩!\n";
    system("pause");
    return 0;
    }

    回覆刪除
  14. B10533007 魏辰熾2017年11月15日 下午3:42

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  15. B10533017 古峻衛2017年11月15日 下午3:42

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;

    class person {
    public:
    double h = 0;
    double w = 0;
    person(){}
    person(double _h, double _w) : h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000*w/(h*h);
    }
    };

    bool bmi_less(person x, person y) {
    return x.bmi() < y.bmi();
    }

    bool h_less(person x, person y) {
    return x.h < y.h;
    }

    bool w_less(person x, person y) {
    return x.w < y.w;
    }

    void print(person x[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << x[i].h << "\tw=" << x[i].w << "\tbmi=" << x[i].bmi() << endl;
    }
    int main()
    {
    person x[4];
    x[0] = person(48, 3);
    x[1] = person(170, 70);
    x[2] = person(175, 76);
    x[3] = person(172, 64);

    print(x);
    cout << "\nbmi 排序=============\n";
    sort(x, x + 4, bmi_less);
    print(x);

    cout << "\nh 排序=============\n";
    sort(x, x + 4, h_less);
    print(x);

    cout << "\nw 排序=============\n";
    sort(x, x + 4, w_less);
    print(x);

    cout << "hello. 排序真好玩!\n";
    system("pause");
    return 0;
    }

    回覆刪除
  16. B10533008 張士晟2017年11月15日 下午3:42

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  17. B10533009 張仲崴2017年11月15日 下午3:43

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  18. B10533018 陳郁傑2017年11月15日 下午3:43

    #include <iostream>
    #include <cstdlib>
    #include <algorithm>

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  19. #include<iostream>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person() {}
    Person(double _h, double _w) : h(_h), w(_w) {}
    public:
    double bmi() {
    return 100000*w/(h*h);
    }
    };

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h" << X[i].h << "\tw" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(180,88);
    X[2] = Person(145,41);
    X[3] = Person(162,43);

    print(X);
    cout << "\nbmi 排序==============\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序===============\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序=================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello.排序真好玩!\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  20. B10433094 簡筱芸2017年11月15日 下午3:48

    #include<iostream>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person() {}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i< 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;

    }


    int main() {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(180, 88);
    X[2] = Person(145, 41);
    X[3] = Person(162, 43);

    print(X);
    cout << "\nbmmi 排序 \n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序 \n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序 \n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello.排序真好玩!\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  21. #include
    #include
    #include

    using namespace std;

    class Person {
    public:
    double h;
    double w;
    Person() {}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].bmi() << endl;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(165, 58);
    X[1] = Person(155, 45);
    X[3] = Person(153, 43);
    X[4] = Person(155, 50);

    print(X);
    cout << "\nbmi &#25490;&#24207;==============\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh &#25490;&#24207;==============\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw &#25490;&#24207;==============\n";
    sort(X, X + 4, w_less);
    print(X);


    system("pause");
    return 0;
    }

    回覆刪除
  22. B10433099 駱婉婷2017年11月15日 下午3:48

    #include <iostream>
    #include <cstdlib>
    #include<algorithm>

    using namespace std;

    class Person {
    public:
    double h;
    double w;
    Person() {}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].bmi() << endl;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(165, 58);
    X[1] = Person(155, 45);
    X[3] = Person(153, 43);
    X[4] = Person(155, 50);

    print(X);
    cout << "\nbmi 排序==============\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==============\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==============\n";
    sort(X, X + 4, w_less);
    print(X);


    system("pause");
    return 0;
    }

    回覆刪除
  23. #include<iostream>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person() {}
    Person(double _h, double _w) : h(_h), w(_w) {}
    public:
    double bmi() {
    return 100000*w/(h*h);
    }
    };

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h" << X[i].h << "\tw" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(180,88);
    X[2] = Person(145,41);
    X[3] = Person(162,43);

    print(X);
    cout << "\nbmi 排序==============\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序===============\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序=================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello.排序真好玩!\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  24. B10433090 蔡語鋐2017年11月15日 下午3:50

    #include <iostream>
    #include <cstdlib>
    #include<algorithm>
    using namespace std;

    class Person {
    public:
    double h;
    double w;
    Person(){}
    Person (double _h, double _w) : h(_h),w(_w){}
    public:
    double bmi ( ) {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw" << X[i].w << "\tbmi" << X[i].bmi() << endl;
    }
    int main()

    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);

    print(X);
    cout << "\nbmi 排序===============\n";
    sort(X, X + 4, bmi_less);
    print(X);
    cout << "\nbmi 排序===============\n";
    sort(X, X + 4,h_less);
    print(X);
    cout << "\nbmi 排序===============\n";
    sort(X, X + 4, w_less);
    print(X);
    system("Pause");
    return 0;

    }

    回覆刪除
  25. #include
    #include
    #include
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person(){}
    Person(double _h, double _w) : h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool h_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X, Person Y) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw="<<X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);

    print(X);
    cout << "\nbmi 排序=====================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nbmi 排序=====================\n";
    sort(X, X + 4, h_less);
    print(X);


    cout << "\nbmi 排序=====================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello. \n";
    system("Pause");
    return 0;
    }

    回覆刪除
  26. #include
    #include
    #include
    using namespace std;

    class Person {
    public:
    double h = 0;
    double w = 0;
    Person(){}
    Person(double h, double w): h(h), w(w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }

    };
    bool bmi_less(Person X, Person Y){
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for(int i=0; i<4; i++)
    cout << X[i].bmi() << endl;
    cout << "\nbmi 排序=======================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);


    cout << "hello.排序真好玩!\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  27. #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person(){}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tv" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(108, 88);
    X[2] = Person(145, 41);
    X[3] = Person(162, 43);

    print(X);
    cout << "\nbmi 排序=======================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello. 排序真好玩\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  28. #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person(){}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tv" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(108, 88);
    X[2] = Person(145, 41);
    X[3] = Person(162, 43);

    print(X);
    cout << "\nbmi 排序=======================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello. 排序真好玩\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  29. #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person(){}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tv" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(108, 88);
    X[2] = Person(145, 41);
    X[3] = Person(162, 43);

    print(X);
    cout << "\nbmi 排序=======================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello. 排序真好玩\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  30. #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    class Person {
    public:
    double h;
    double w;
    Person(){}
    Person(double _h, double _w): h(_h), w(_w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }

    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }

    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }
    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tv" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(108, 88);
    X[2] = Person(145, 41);
    X[3] = Person(162, 43);

    print(X);
    cout << "\nbmi 排序=======================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);

    cout << "\nh 排序=======================\n";
    sort(X, X + 4, w_less);
    print(X);
    cout << "hello. 排序真好玩\n";
    system("Pause");
    return 0;
    }

    回覆刪除
  31. #include
    #include
    #include

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  32. b10433071 雷昕翰2017年11月15日 下午6:49

    #include
    #include
    #include

    using namespace std;

    class Person{
    public:
    double h ;
    double w ;
    Person(){}
    Person(double _h, double _w): h(_h),w(_w)
    {}
    public:
    double bmi()
    {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    cout << "BMI:\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    {
    cout << X[i].bmi() << endl;
    }
    cout << "===============\n";
    cout << "身高:\n";
    sort(X, X + 4, h_less);
    for (int e = 0; e < 4; e++)
    {
    cout << X[e].h << endl;
    }
    cout << "===============\n";
    cout << "體重:\n";
    sort(X, X + 4, w_less);
    for (int z = 0; z < 4; z++)
    {
    cout << X[z].w << endl;
    }
    cout << "===============\n";
    system("pause");
    return 0;
    }

    回覆刪除
  33. #include
    #include
    #include

    using namespace std;

    class Person {
    public:
    double h ;
    double w ;
    Person (){}
    Person(double h, double w) : h(h), w(w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for ( int i = 0; i < 4 ; i++)
    cout << X[i].bmi() << endl;

    cout << "========bmi_less========\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "==========W_less======\n";
    sort(X, X + 4, w_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "=========H_less========\n";
    sort(X, X + 4, h_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    system("pause");
    return 0;
    }

    回覆刪除
  34. #include
    #include
    #include

    using namespace std;

    class Person{
    public:
    double h ;
    double w ;
    Person(){}
    Person(double _h, double _w): h(_h),w(_w)
    {}
    public:
    double bmi()
    {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    cout << "BMI:\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    {
    cout << X[i].bmi() << endl;
    }
    cout << "===============\n";
    cout << "身高:\n";
    sort(X, X + 4, h_less);
    for (int e = 0; e < 4; e++)
    {
    cout << X[e].h << endl;
    }
    cout << "===============\n";
    cout << "體重:\n";
    sort(X, X + 4, w_less);
    for (int z = 0; z < 4; z++)
    {
    cout << X[z].w << endl;
    }
    cout << "===============\n";
    system("pause");
    return 0;
    }

    回覆刪除
  35. b10533075 陳詔瑋2017年12月27日 下午2:56

    #include
    #include
    #include

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  36. b10533029 游淑娥2017年12月27日 下午2:56

    #include
    #include
    #include

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  37. b10533073黃叡哲2018年1月3日 下午2:35

    #include
    #include
    #include

    using namespace std;
    class Person {

    public:
    double h = 0;
    double w = 0;
    Person() {}
    Person (double h , double w):h(h),w(w){}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };
    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.h < Y.h;
    }
    bool w_less(Person X, Person Y) {
    return X.w < Y.w;
    }

    void print(Person X[4]) {
    for (int i = 0; i < 4; i++)
    cout << "h=" << X[i].h << "\tw=" << X[i].w << "\tbmi=" << X[i].bmi() << endl;
    }
    int main()
    {
    Person X[4];
    X[0] = Person (48,5);
    X[1] = Person(173, 26.3);
    X[2] = Person(150, 49);
    X[3] = Person(110, 65);

    print(X);
    cout << "\nbmi 排序==================\n";
    sort(X, X + 4, bmi_less);
    print(X);

    cout << "\nh 排序==================\n";
    sort(X, X + 4, h_less);
    print(X);

    cout << "\nw 排序==================\n";
    sort(X, X + 4, w_less);
    print(X);

    system("pause");
    return 0;
    }

    回覆刪除
  38. B10533093許永炎2018年1月3日 下午2:40

    #include
    #include
    #include

    using namespace std;

    class Person {
    public:
    double h ;
    double w ;
    Person (){}
    Person(double h, double w) : h(h), w(w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for ( int i = 0; i < 4 ; i++)
    cout << X[i].bmi() << endl;

    cout << "========bmi_less========\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "==========W_less======\n";
    sort(X, X + 4, w_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "=========H_less========\n";
    sort(X, X + 4, h_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    system("pause");
    return 0;
    }

    回覆刪除
  39. B10533093許永炎2018年1月3日 下午2:41

    #include
    #include
    #include

    using namespace std;

    class Person {
    public:
    double h ;
    double w ;
    Person (){}
    Person(double h, double w) : h(h), w(w) {}
    public:
    double bmi() {
    return 10000 * w / (h*h);
    }
    };

    bool bmi_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool w_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    bool h_less(Person X, Person Y) {
    return X.bmi() < Y.bmi();
    }
    int main()
    {
    Person X[4];
    X[0] = Person(48, 3);
    X[1] = Person(145, 41);
    X[2] = Person(162, 43);
    X[3] = Person(180, 88);
    for ( int i = 0; i < 4 ; i++)
    cout << X[i].bmi() << endl;

    cout << "========bmi_less========\n";
    sort(X, X + 4, bmi_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "==========W_less======\n";
    sort(X, X + 4, w_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    cout << "=========H_less========\n";
    sort(X, X + 4, h_less);
    for (int i = 0; i < 4; i++)
    cout << X[i].bmi() << endl;

    system("pause");
    return 0;
    }

    回覆刪除

HTML 編輯器