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_2a.cpp < prev    next >
C/C++ Source or Header  |  1992-01-19  |  1KB  |  48 lines

  1.                                // Chapter 2 - Programming exercise 2
  2. #include <iostream.h>
  3.  
  4. class animal {
  5. public:
  6.    int weight;
  7.    int feet;
  8.    float height;
  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.  
  38.  
  39.  
  40.  
  41. // Result of execution
  42. //
  43. // The weight of dog1 is 15
  44. // The weight of dog2 is 37
  45. // The weight of chicken is 3
  46. // Dog1 height is 17.4 inches.
  47. // The chicken's height is 7.123 inches.
  48.