網頁

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 則留言:

  1. B10333064王韻菱2017年5月9日 上午11:37

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

    回覆刪除
  2. B10333106 劉郁芃2017年5月9日 上午11:40

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

    回覆刪除
  3. B10333070 徐承瑋2017年5月9日 上午11:41

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

    回覆刪除
  4. b10333080王育文2017年5月9日 上午11:42

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

    回覆刪除
  5. B10333055 翁恩義2017年5月9日 上午11:43

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

    回覆刪除
  6. B10333079 葉禮魁2017年5月9日 上午11:43

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

    回覆刪除
  7. B10333107-曾詠浩2017年5月9日 上午11:45

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

    回覆刪除
  8. B10333086 陳晏堂2017年5月9日 上午11:48

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

    回覆刪除
  9. b10333097胡聖恩2017年5月9日 上午11:48

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

    回覆刪除
  10. B10333086 陳晏堂2017年5月9日 上午11:50

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

    回覆刪除
  11. #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;
    }

    回覆刪除
  12. b10333083周琬芸2017年5月9日 上午11:58

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

    回覆刪除
  13. B10333063羅胤銓2017年5月9日 中午12:06

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

    回覆刪除
  14. b10233032謝翔宇2017年5月16日 清晨7:49

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

    回覆刪除
  15. b10133187 楊鈞文2017年6月20日 上午10:30

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

    回覆刪除
  16. B10333072 黃玟茜2017年6月20日 上午11:17

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

    回覆刪除
  17. B10333072 黃玟茜2017年6月20日 上午11:47

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

    回覆刪除

HTML 編輯器