herrDeng網內搜尋

自訂搜尋

Ads

2017年11月15日 星期三

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

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

39 則留言:

B10533062 洪尚郁 提到...

#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;
}

B10433065劉勝威 提到...

#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");
}

B10433201 提到...

#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;
}

B10433065劉勝威 提到...

#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");
}

B10433072廖翊翔 提到...

#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;
}

b10433201 提到...

#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;
}

B10533007 魏辰熾 提到...

#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;
}

B10533018 陳郁傑 提到...

#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;
}

B10533062 洪尚郁 提到...

#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;
}

b10433081 巫明芬 提到...

#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;
}

B10433065劉勝威 提到...

#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");
}

B10533011 江道逸 提到...

#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;
}

B10533006 劉純賓 提到...

#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;
}

B10533007 魏辰熾 提到...

#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;
}

B10533017 古峻衛 提到...

#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;
}

B10533008 張士晟 提到...

#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;
}

B10533009 張仲崴 提到...

#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;
}

B10533018 陳郁傑 提到...

#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;
}

B10433073何明宗 提到...

#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;
}

B10433094 簡筱芸 提到...

#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;
}

B10433107袁婕寧 提到...

#include
#include
#include

using namespace std;

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

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

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

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

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


system("pause");
return 0;
}

B10433099 駱婉婷 提到...

#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;
}

B10433106簡瑋佑 提到...

#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;
}

B10433090 蔡語鋐 提到...

#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;

}

B10533010蕭凱維 提到...

#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;
}

b10333093徐子軒 提到...

#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;
}

B10533083徐士興 提到...

#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;
}

B10533132許敏茹 提到...

#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;
}

B10533088葉俊江 提到...

#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;
}

B10537208楊蕊筑 提到...

#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;
}

B10533071徐琮淇 提到...

#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;
}

b10433071 雷昕翰 提到...

#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;
}

B10533076 姜國傑 提到...

#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;
}

b10433088葉凱文 提到...

#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;
}

b10533075 陳詔瑋 提到...

#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;
}

b10533029 游淑娥 提到...

#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;
}

b10533073黃叡哲 提到...

#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;
}

B10533093許永炎 提到...

#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;
}

B10533093許永炎 提到...

#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;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章