ForeverDev

Untitled

Oct 21st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Animal {
  7.     public:
  8.         string name;
  9.         float weight;
  10.         float age;
  11. };
  12.  
  13. class Dog : public Animal {
  14.     public:
  15.         Dog(string _name, float _weight, float _age) {
  16.             name = _name;
  17.             weight = _weight;
  18.             age = _age;
  19.         }
  20.         void bark() {
  21.             cout << name << " barked!" << endl << endl;
  22.         }
  23.         void about() {
  24.             cout <<
  25.                 "Name: " << name << endl <<
  26.                 "Age: " << age << " years" << endl <<
  27.                 "Weight: " << weight << " pounds" << endl << endl;
  28.         }
  29. };
  30.  
  31. int main() {
  32.     Dog fred("Fred", 100, 7);
  33.     fred.bark();
  34.     fred.about();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment