herrDeng網內搜尋

自訂搜尋

Ads

2017年5月9日 星期二

C++ bmi class

請用C++11 random產生30筆身高、體重的資訊,用class ,並且使用適當地虛擬隨機亂數,以class method的方式計算bmi
提示:
person X[30];
mt19937 gen(clock());
// Mersenne Twister algorithm is based on the
// Mersenne prime 219937−1
normal_distribution dis0(163, 7);
normal_distribution dis1(55, 5);
……

17 則留言:

B10333064王韻菱 提到...

#include
#include
#include
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<

B10333106 劉郁芃 提到...

#include <iostream>
#include <random>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"weight="<<weight<<"\t";
cout<<"bmi="<<bmi()<<endl;
}
};

int main()
{
person X[30];
mt19937_64 gen(clock());
normal_distribution<double> dis0(163,7);
normal_distribution<double> dis1(55,5);
for(int i=0;i<30;i++){
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h,w);
X[i].print(i);
}
return 0;
}

B10333070 徐承瑋 提到...

#include <iostream>
#include <algorithm>
#include <random>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){

cout<<"第"<<i<<"位同學的BMI:"<<bmi()<<"\t";
cout<<"身高:"<<height<<"\t";
cout<<"體重:"<<weight<<"\t"<<endl;
}
};
int main(){

person X[30];
mt19937 gen(clock());
normal_distribution <double> A(160,7);
normal_distribution <double> B(50,10);
for (int i=1;i<31;i++){
double height=A(gen);
double weight=B(gen);
X[i]=person(height,weight);
X[i].print(i);
}
return 0;
}

b10333080王育文 提到...

#include <iostream>
#include <random>
#include <ctime>

using namespace std;

class person{
public:


double height, weight;
int i;
person(){}
person(double height, double weight)
{
this->height=height;
this->weight=weight;
}


double bmi(){
return 10000*weight/height/height;
}
void print(int i)
{
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"weight="<<weight<<"\t";
cout<<"bmi="<<bmi()<<endl;
}
};

int main()
{
person X[30];
mt19937_64 gen(clock());
normal_distribution<double> dis0(163,7);
normal_distribution<double> dis1(55,5);
for (int i=0;i<30;i++){
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h,w);
X[i].print(i);
}


return 0;
}

B10333055 翁恩義 提到...

#include <iostream>
#include <random>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"weight="<<weight<<"\t";
cout<<"bmi="<<bmi()<<endl;
}
};

int main()
{
person X[30];
mt19937 gen(clock());
normal_distribution<double> dis0(163, 7);
normal_distribution<double> dis1(55, 5);
for(int i=0; i<30; i++){
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h, w);
X[i].print(i);
}
return 0;
}

B10333079 葉禮魁 提到...

#include <iostream>
#include <random>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}

person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"weight="<<weight<<"\t";
cout<<"bmi="<<bmi()<<endl;
}
};


int main()
{
person X[30];
mt19937_64 gen(clock());
normal_distribution<double> dis0(163, 7);
normal_distribution<double> dis1(55, 5);
for (int i = 0; i < 30; i++) {
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h,w);
X[i].print(i);
}

return 0;
}

B10333107-曾詠浩 提到...

#include <iostream>
#include <algorithm>
#include <random>
#include <fstream>
#include <cstdlib>
#include <ctime>

using namespace std;
class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print (int i){
cout<<"第"<<i<<"位同學"<<":\t";
cout<<"身高="<<height<<"\t";
cout<<"體重="<<weight<<"\t";
cout<<"BMI="<<bmi()<<"\t";
if(bmi()<18.5)
cout<<"體重過輕"<<endl;

else if(bmi()<24)
cout<<"正常範圍"<<endl;

else if (bmi()>=24)
cout<<"體重過重"<<endl;
}
};

int main()
{
person X[30];
mt19937 gen(clock());
normal_distribution<double> g1(163, 7);
normal_distribution<double> g2(55, 5);
for (int i = 1; i<31; i++)
{
double h = g1(gen);
double w = g2(gen);
X[i]=person(h,w);
X[i].print(i);

}
return 0;
}

B10333086 陳晏堂 提到...

#include
#include
#include

using namespace std;
class person{
double height, weight;
public:
person(){}
person(double height,double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<":\t";
cout<<"height="< dis0(163, 7);
normal_distribution dis1(55, 5);
for(int i=0; i<30; i++){
double h=dis0(gen);
double w=dis1(gen);
x[i]=person(h,w);
x[i].print(i);
}
return 0;
}

b10333097胡聖恩 提到...

#include <iostream>
#include <random>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"weight="<<weight<<"\t";
cout<<"bmi="<<bmi()<<endl;
}
};
int main()
{
person x[30];
mt19937_64 gen(clock());
normal_distribution <double>dis0(163, 7);
normal_distribution <double>dis1(55, 5);
for(int i=0; i<30; i++){
double h=dis0(gen);
double w=dis1(gen);
x[i]=person(h,w);
x[i].print(i);
}
return 0;
}

B10333086 陳晏堂 提到...

#include
#include
#include

using namespace std;
class person{
double height, weight;
public:
person(){}
person(double height,double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<":\t";
cout<<"height="< dis0(163, 7);
normal_distribution dis1(55, 5);
for(int i=0; i<30; i++){
double h=dis0(gen);
double w=dis1(gen);
x[i]=person(h,w);
x[i].print(i);
}
return 0;
}

B10333094 提到...

#include <iostream>
#include <random>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"height="<<height<<":\t";
cout<<"weight="<<weight<<":\t";
cout<<"bmi="<<bmi()<<endl;
}
};
int main()
{
person X[30];
mt19937_64 gen(clock());
normal_distribution<double> dis0(163, 7);
normal_distribution<double> dis1(55, 5);
for(int i=0; i<30; i++){
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h, w);
X[i].print(i);

}
return 0;
}

b10333083周琬芸 提到...

#include <iostream>
#include<random>
#include<ctime>
using namespace std;

class person{
double height ,weight;


public :
person(){}
person (double height,double weight){
this->height=height;
this->weight=weight;


}
double bmi()
{
return 10000*weight/height/height;
}


void print(int i){
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"bmi="<<bmi()<<endl;

}
};
int main()
{
person X[30];
mt19937 gen(clock());
normal_distribution<double> dis0(163, 7);
normal_distribution <double>dis1(55, 5);
for(int i=0;i<30;i++){
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h,w);
X[i].print(i);

}
return 0;
}

B10333063羅胤銓 提到...

#include <iostream>
#include <random>
#include <ctime>
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"高="<<height<<":\t";
cout<<"體重="<<weight<<":\t";
cout<<"bmi="<<bmi()<<endl;
}
};

int main()
{person x[30];
mt19937_64 gen(clock());
normal_distribution<double>dis0(163,7);
normal_distribution<double>dis1(55,5);
for(int i=0; i<30;i++){
double h=dis0(gen);
double w=dis1(gen);
x[i]=person(h,w);
x[i].print(i);
}
return 0;
}

b10233032謝翔宇 提到...

#include
#include
#include
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<<i<<":\t";
cout<<"高="<<height<<":\t";
cout<<"體重="<<weight<<":\t";
cout<<"bmi="<<bmi()<<endl;
}
};

int main()
{person x[30];
mt19937_64 gen(clock());
normal_distribution<double>dis0(163,7);
normal_distribution<double>dis1(55,5);
for(int i=0; i<30;i++){
double h=dis0(gen);
double w=dis1(gen);
x[i]=person(h,w);
x[i].print(i);
}
return 0;
}

b10133187 楊鈞文 提到...

#include
#include
#include

using namespace std;

class person{
public:


double height, weight;
int i;
person(){}
person(double height, double weight)
{
this->height=height;
this->weight=weight;
}


double bmi(){
return 10000*weight/height/height;
}
void print(int i)
{
cout<<i<<":\t";
cout<<"height="<<height<<"\t";
cout<<"weight="<<weight<<"\t";
cout<<"bmi="<<bmi()<<endl;
}
};

int main()
{
person X[30];
mt19937_64 gen(clock());
normal_distribution<double> dis0(165,7);
normal_distribution<double> dis1(55,5);
for (int i=0;i<30;i++){
double h=dis0(gen);
double w=dis1(gen);
X[i]=person(h,w);
X[i].print(i);
}


return 0;
}

B10333072 黃玟茜 提到...

#include
#include
#include
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<

B10333072 黃玟茜 提到...

#include
#include
#include
using namespace std;

class person{
double height, weight;
public:
person(){}
person(double height, double weight){
this->height=height;
this->weight=weight;
}
double bmi(){
return 10000*weight/height/height;
}
void print(int i){
cout<

Related Posts Plugin for WordPress, Blogger...

熱門文章