home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / CTUTOR / ANSWERS.ZIP / CH02_2A.CPP < prev    next >
C/C++ Source or Header  |  1990-07-20  |  1KB  |  49 lines

  1.                                // Chapter 2 - Programming exercise 2
  2. #include "iostream.h"
  3.  
  4. class animal {
  5. public:
  6.    int weight;
  7.    int feet;
  8.    int number_of_ways;
  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.number_of_ways = 17;
  26.    dog2.number_of_ways = 21;
  27.    chicken.number_of_ways = 7;
  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 can do things " << dog1.number_of_ways
  34.                                            << " different ways\n";
  35.    cout << "The chicken can do things " << chicken.number_of_ways
  36.                                            << " different ways\n";
  37. }
  38.  
  39.  
  40.  
  41.  
  42. // Result of execution
  43. //
  44. // The weight of dog1 is 15
  45. // The weight of dog2 is 37
  46. // The weight of chicken is 3
  47. // Dog1 can do things 17 different ways
  48. // The chicken can do things 7 different ways
  49.