Question: Consider the following code snippet: class Car { public: Car ( ) ; virtual void set _ speed ( double new _ speed ) ;

Consider the following code snippet:
class Car { public: Car(); virtual void set_speed(double new_speed); void set_speed(); void accelerate(double new_speed); double get_speed() const; private: double speed; }; Car::Car(){ speed =0; } void Car::set_speed(double new_speed){ speed = new_speed; } void Car::accelerate(double new_speed){ speed = speed + new_speed; } void Car::set_speed(){ speed =100; } double Car::get_speed() const { return speed; } class AeroCar : public Car { public: AeroCar(); void set_speed(double new_speed); virtual void accelerate(double new_speed); double get_speed() const; }; AeroCar::AeroCar() : Car(){} void AeroCar::set_speed(double new_speed){ Car::set_speed(Car::get_speed()+ new_speed); } void AeroCar::accelerate(double new_speed){ Car::set_speed(new_speed); } double AeroCar::get_speed() const { return Car::get_speed(); } int main(){ AeroCar* ac1= new AeroCar; ac1->set_speed(10); ac1->accelerate(20); Car* c1= new Car; c1->set_speed(30); cout << "First Object Speed: "<< ac1.get_speed()<<"; Second Object Speed: "<< c1->get_speed(); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!