Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Animal
- {
- private:
- int age; //age of the animal
- protected:
- float weight; //weight of animal
- public:
- Animal() { age = 0; weight = 0.0; }
- void setAge(int x) {
- age = x;
- }
- void setWeight(int x) {
- weight = x;
- }
- int getAge() { return age; }
- int getWeight() { return weight; }
- };
- class Cat : public Animal
- {
- private:
- int age;
- int legs;
- protected:
- float weight2;
- public:
- Cat() {
- weight2 = 0.0; legs = 4;
- }
- void setLegs(int x) {
- legs = x;
- }
- int getLegs() { return legs; }
- int getWeight2() { return weight2; }
- };
- class snake : public Animal
- {
- private:
- int age2;
- bool IsPoinsonous;
- public:
- snake() { age2 = 0; IsPoinsonous = 0; }
- void setIsPoisonous(int x) {
- IsPoinsonous = x;
- }
- int getIsPoinsonpus() { return IsPoinsonous; }
- int getAge2() { return age2; }
- };
- int main()
- {
- Animal x;
- cout << "Initial value for x: " << endl;
- cout << "Age = " << x.getAge() << " Weight = " << x.getWeight() << endl;
- x.setAge(10);
- x.setWeight(20);
- cout << "Modified value for x: " << endl;
- cout << "Age = " << x.getAge() << " Weight = " << x.getWeight() << endl;
- Cat y;
- cout << "Initial value for y: " << endl;
- cout << "Age = " << y.getAge() << " Weight = " << y.getWeight() << endl;
- y.setAge(12);
- y.setWeight(17);
- cout << "Modified value for y: " << endl;
- cout << "Age = " << y.getAge() << " Weight = " << y.getWeight() << " Weight2 = " << y.getWeight2() << endl;
- snake z;
- cout << "Initial value for z: " << endl;
- cout << "Age = " << z.getAge() << "Weight = " << z.getWeight() << endl;
- z.setAge(14);
- z.setWeight(23);
- cout << "Modified value for z: " << endl;
- cout << "Age = " << z.getAge() << " Weight = " << z.getWeight() << " Age2 = " << z.getAge2() << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement