這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
#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;}
#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");}
#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;}
#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");}
#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;}
#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;}
#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;}
#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;}
#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");}
#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;}
#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;}
#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;}
#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;}
#include #include #includeusing 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;}
#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;}
#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;}
#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;}
#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;}
#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;}
#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;}
#include#include#includeusing 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;}
#include#include#includeusing 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 編輯器
#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;
}
#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");
}
#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;
}
#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");
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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");
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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 排序==============\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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}