Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

USING INHERITANCE TO CREATE A DERIVED CLASS IN C++ In this lab, you create a derived class from a base class and then use the derived class in a C++ program. The program should create two Motorcycle objects and then set the Motorcycle's speed, accelerate the Motorcycle object, and check its side car status. Use the Vehicle and Automobile classes that you worked with earlier in this chapter as a guide.

1. Open the file named Motorcycle.cpp using Notepad or the text editor of your choice.

2. Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation.

3. In the Motorcycle class, create a private attribute named sidecar. The sidecar attribute should be data type bool.

4. Write a public set method to set the value for sidecar.

5. Write a public get method to retrieve the value of sidecar.

6. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This Motorcycle cannot go that fast".

7. Save this class file, Motorcycle.cpp, in a directory of your choice and then open the file named MyMotorcycleClassProgram.cpp.

8. In the MyMotorcycleClassProgram, create two Motorcycle objects named motorCycleOne and motorCycleTwo.

9. Set the sidecar value of motorcycleOne to true and the sidecar value of motorcycleTwo to false.

10. Set motorcycleOne's maximum speed to 90 and motorcycleTwo's maximum speed to 85.

11. Set motorcycleOne's current speed to 65 and motorcycleTwo's current speed to 60.

12. Accelerate motorcycleOne by 30 miles per hour (mph) and accelerate motorcycleTwo by 20 mph.

13. Print the current speed of motorcycleOne and motorcycleTwo.

14. Determine if motorcycleOne and motorcycleTwo have side cars. If yes, display the following: "This motorcycle has a side car". If not, display the following: "This motorcycle does not have a side car".

15. Save MyMotorcycleClassProgram.cpp in the same directory as Motorcycle.cpp.

16. Compile the source code file MyMotorCycleClassProgram.cpp.

17. Execute the program.

18. Record the output below.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92207214

Have any Question?


Related Questions in Computer Engineering

Explain the risk of having hacking tools installed on your

Explain the risk of having hacking tools installed on your computer and why you should contact local law enforcement agencies before installing those tools.

Please discuss the design principles that guide the authors

Please discuss the design principles that guide the authors of instruction sets in making the right balance. Provide examples of application of each of the three design principles while designing instruction sets.

Suppose you insert 125 integer keys into a hash table with

Suppose you insert 125 integer keys into a hash table with an initial capacity of 25 and load factor threshold of 2. THe hash code is the key itself,and the function key mod table_capacity is used to map a key into a tab ...

Scenarioyour friend tim hall is an expert in creating

Scenario Your friend, Tim Hall, is an expert in creating websites. In Hall's opinion, creation of websites is now a simple task using tools such as Adobe Dreamweaver, and therefore, he does not feel the need to learn HTM ...

Shading and illuminating algorithmsa explain in your own

Shading and illuminating algorithms. a) Explain, in your own words, how the Phong illumination model works and what its strong and weak features are. b) Compare flat and Gouraud shading algorithms.

Question suppose you are stranded on a desert island on

Question : Suppose you are stranded on a desert island on which queues are plentiful, but you need a stack. How can you implement a stack using two queues? What is the big-Oh running time of the stack operations?

Sectuon 112 build draw binary search tree with the names

Sectuon 11.2: Build draw binary search tree with the names Doc, Grumpy, Happy, Sleepy, a Bashful, Sneezy, Dopey, inserted in the order provided here. Assume that, on future searche of this tree, each name is equally like ...

Couriers such as ups and fedex complete on service and

Couriers such as UPS and FedEx complete on service and price. One way to reduce cost is to keep labor cost low by hiring and laying off workers to meet the demand. This strategy requires managers to hire and train new wo ...

The literature on honeypots or so called fake networks to

The literature on honeypots or so called "fake networks" to attract hackers and attackers frequently mentions "entrapment" as one of the legal issues that must be considered. How of a concern is entrapment? What are some ...

Select two application areas for data mining not discussed

Select two application areas for data mining NOT discussed in the text book and briefly discuss how data mining is being used to solve a problem (or to explore an opportunity)?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As