Advertisement
pdpd123

Untitled

Feb 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. /// 7. structures
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. struct people{ // define data type that you want
  7.  
  8.     // data
  9.     int age;
  10.     double height,weight;
  11.     pair<int,int> birthday;
  12.  
  13.     // constructor
  14.     people(int a,double h,double w,pair<int,int> bir){
  15.         age=a,height=h,weight=w;
  16.         birthday=bir;
  17.     }
  18.  
  19.     // member functions
  20.     double get_bmi(){
  21.         return weight/(height*height);
  22.     }
  23.     void lose_weight(double w){
  24.         weight-=w;
  25.     }
  26.     void grow(){
  27.         age++;
  28.     }
  29.  
  30. }; /// *** REMEMBER to add ';' after the structure declaration ***
  31.  
  32. signed main(){
  33.  
  34.     double unknown=double(rand()/7000);
  35.     people DA(16,180.1,60.0,make_pair(05,05));
  36.     // call the constructor
  37.     people Celine(16,158.0,unknown,make_pair(09,10));
  38.  
  39.     poeple _3t; // call the empty constructor
  40.  
  41.     DA.grow(); // member functions need to call by an object
  42.     Celine.lose_weight(2.1);
  43.     cout << Celine.get_bmi() << endl;
  44.  
  45.     /// ** Don't forget to add ';' at the end of the statement **
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement