home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 353_02 / answers / ch02_2b.cpp < prev    next >
C/C++ Source or Header  |  1992-01-19  |  841b  |  37 lines

  1.                                // Chapter 2 - Programming exercise 2
  2. #include <iostream.h>
  3.  
  4. class animal {
  5.    float height;
  6. public:
  7.    int weight;
  8.    int feet;
  9. };
  10.  
  11. main()
  12. {
  13. animal dog1, dog2, chicken;
  14. animal cat1;
  15. class animal cat2;
  16.  
  17.    dog1.weight = 15;
  18.    dog2.weight = 37;
  19.    chicken.weight = 3;
  20.  
  21.    dog1.feet = 4;
  22.    dog2.feet = 4;
  23.    chicken.feet = 2;
  24.  
  25.    dog1.height = 17.4;
  26.    dog2.height = 2.221;
  27.    chicken.height = 7.123;
  28.  
  29.    cout << "The weight of dog1 is " << dog1.weight << "\n";
  30.    cout << "The weight of dog2 is " << dog2.weight << "\n";
  31.    cout << "The weight of chicken is " << chicken.weight << "\n";
  32.  
  33.    cout << "Dog1 height is " << dog1.height << " inches.\n";
  34.    cout << "The chicken's height is " << chicken.height
  35.                                                  << " inches.\n";
  36. }
  37.