C++改寫算bmi成class,並排序
herrDeng網內搜尋
自訂搜尋
Ads
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
你會用C的算子sizeof?
-
Python C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
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;
}
張貼留言