C++改寫算bmi成class,並排序
herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
python pandas對黃金、外匯匯率的爬蟲練習,並使用matplotlib.pyplot的函數plot, scatter做資料視覺化處理,採用numpy的統計函數,分析黃金價格波動與歐元走勢的關聯。
-
Python C C++ 2 pointer速解Leetcode 2337 Move Pieces to Obtain a String 多日Leetcode的問題都可用2-pointer法來解,今日2337. Move Pieces to Obtain a String也不例...
-
你會用C的算子sizeof?
-
Leetcode的1652. Defuse the Bomb是絕佳的練習題,特別是針對Python的使用者,雖說是sliding window 是簡單的那種,還可練習loop, slicing, minus index etc . https://leetcode.com/pro...
39 則留言:
#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;
}
張貼留言