Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How can a new subtype of shape, like a pentagon, be added to a program according to the text?

  1. By modifying generic shape functions

  2. By deriving from the base shape class

  3. Through dynamic allocation only

  4. By overriding all existing shape functions

The correct answer is: By deriving from the base shape class

To add a new subtype of shape, such as a pentagon, to a program, the base shape class must first be extended or derived from. This allows the new subtype to inherit the properties and methods of the base class. Option A is incorrect because modifying generic shape functions would only change the existing shapes and not add a new subtype. Option C is incorrect because dynamic allocation is a specific method of allocating memory and does not pertain to creating a new subtype of shape. Option D is incorrect because overriding all existing shape functions would not create a new subtype, but rather modify the existing ones. Thus, the correct answer is B as it explains the essential step of extending the base shape class to create a new subtype.