Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Animal { public: Animal ( ) ; virtual void set _ speed ( double new _ speed ) ; void accelerate ( double new

class Animal
{
public:
Animal();
virtual void set_speed(double new_speed);
void accelerate(double new_speed);
double get_speed() const;
private:
double speed;
};
Animal::Animal()
{
speed =0;
}
void Animal::set_speed(double new_speed)
{
speed = new_speed;
}
void Animal::accelerate(double new_speed)
{
speed = speed + new_speed;
}
double Animal::get_speed() const
{
return speed;
}
class Cheetah : public Animal
{
public:
Cheetah();
void set_speed(double new_speed);
virtual void accelerate(double new_speed);
double get_speed() const;
};
Cheetah::Cheetah()
: Animal()
{}
void Cheetah::set_speed(double new_speed)
{
Animal::set_speed(Animal::get_speed()+ new_speed);
}
void Cheetah::accelerate(double new_speed)
{
Animal::set_speed(new_speed);
}
double Cheetah::get_speed() const
{
return Animal::get_speed();
}
int main()
{
Cheetah ch1;
Cheetah* ch2= new Cheetah;
ch1.set_speed(100);
ch1.accelerate(200);
ch2->set_speed(100);
ch2->accelerate(200);
Animal* c1= new Animal;
c1= ch2;
cout << "Cheetah Speed: "<< ch1.get_speed()
<<"; Animal Speed: "<< c1->get_speed();
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions