Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. What is the output of the following code snippet? class Car { public: Car(); void set_speed(double new_speed); double get_speed() const; private: double speed; };

1.What is the output of the following code snippet?

class Car { public: Car(); void set_speed(double new_speed); double get_speed() const; private: double speed; }; Car::Car() { speed = 0; } void Car::set_speed(double new_speed) { speed = new_speed; } double Car::get_speed() const { return speed; } class AeroCar : public Car { public: AeroCar(); void set_speed(double new_speed); void add_speed(double new_speed); double get_speed() const; }; void AeroCar::set_speed(double new_speed) { Car::set_speed(10 * new_speed); } void AeroCar::add_speed(double new_speed) { Car::set_speed(Car::get_speed() + new_speed); } double AeroCar::get_speed() const { return Car::get_speed(); } int main() { AeroCar ac1; ac1.set_speed(10); ac1.add_speed(250); cout << "Speed: " << ac1.get_speed(); return 0; }

The output is:

Group of answer choices

Speed: 250

Speed: 350

Speed: 260

Speed: 420

4. When an object inherits from a base class, it must specify that relationship in the class definition. Which answer below correctly defines Manager as a class that inherits from Employee?

class

group of the answer

class Manager : public Employee {  }

class Manager :: public Employee {  }

class Employee :: public Manager {  }

class Employee :: public Manager {  }

5. Consider the following code. Is there a syntax error, and if so, what is it?

class Car { public: Car(double tank_siz); double get_tankSize() const; void set_tankSize(double size); private: double tank_size; }; class Chevy : car { public: Chevy(); double get_mpg() const; void add_miles(double miles); private: double engine_size; double miles_travelled; };

Group of answer choices

No syntax error, but a main() using the Chevy class will not be able to call get_tankSize()

The parameter is spelled wrong in the prototype for Car (double tank_siz);. It doesn't match the private variable name.

None of these

No syntax error and no design problems

10. The Manager class inherits from the Employee base class. The Manager class overrides the Employee's get_salary()function. What will be the value returned from the following function?

double Manager::get_salary(double bonus) const { double base_salary = get_salary(bonus); return base_salary + bonus; }

Group of answer choices

The Employee base salary plus the Manager bonus

It won't compile due to syntax error(s).

It will never return, but be an infinite recursion until it crashes the program.

The Employee base salary plus twice the Manager bonus

11. What is the output of the following code snippet?

Car() { speed = 0;

}

Car::Car(double new_speed) { speed = new_speed; } double Car::get_speed() const { return speed; } class AeroCar : public Car { public: AeroCar(); AeroCar(double new_height, double new_speed); void display_data() const; private: double height; }; AeroCar::AeroCar() { height = 0; } AeroCar::AeroCar(double new_height, double new_speed) : Car(new_speed) { height = new_height; } void AeroCar::display_data() const { cout << "Speed: " << Car::get_speed() << "; Height: " << height << endl; } int main() { Car c1; Car c2(10); AeroCar ac1; AeroCar ac2(10, 20); c1 = ac1; c1.display_data(); return 0; }

Group of answer choices

There is no output because there are compilation errors.

Speed: 10; Height: 20 is the output.

Speed: 0; Height: 20 is the output.

Speed: 10; Height: 0 is the output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions