Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// 7. structures
- #include<bits/stdc++.h>
- using namespace std;
- struct people{ // define data type that you want
- // data
- int age;
- double height,weight;
- pair<int,int> birthday;
- // constructor
- people(int a,double h,double w,pair<int,int> bir){
- age=a,height=h,weight=w;
- birthday=bir;
- }
- // member functions
- double get_bmi(){
- return weight/(height*height);
- }
- void lose_weight(double w){
- weight-=w;
- }
- void grow(){
- age++;
- }
- }; /// *** REMEMBER to add ';' after the structure declaration ***
- signed main(){
- double unknown=double(rand()/7000);
- people DA(16,180.1,60.0,make_pair(05,05));
- // call the constructor
- people Celine(16,158.0,unknown,make_pair(09,10));
- poeple _3t; // call the empty constructor
- DA.grow(); // member functions need to call by an object
- Celine.lose_weight(2.1);
- cout << Celine.get_bmi() << endl;
- /// ** Don't forget to add ';' at the end of the statement **
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement