Question

(15)Given the following classes, how would you arrange them in an inheritance hierarchy? class Pen; class...

(15)Given the following classes, how would you arrange them in an inheritance hierarchy?

class Pen; class BallPoint; class Pencil; class MechnicalPencil; class WoodPencil; class WritingInstrument; class FountainPen;

Draw the inheritance diagram and relate the classes via C++ code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Your Inheritance diagram would look like this:

  

The class will be related as follows:

class WritingInstrument // super class of Pen and Pencil
{
  
}

class Pen : public WritingInstrument// pen is Writing instrument
{
  
}

class Pencil : public WritingInstrument// pencil is writing instrument
{
  
}

class BallPoint : public Pen // BallPoint is a Pen
{
  
}

class MechanicalPencil : public Pencil // MechanicalPencil is a Pencil
{
  
}

class WoodPencil : public Pencil // WoodPencil is a Pencil
{
  
}

class FountainPen : public Pen// FountainPen is a pen
{
  
}

Hope it clears your doubt, and you like it. :)

Add a comment
Know the answer?
Add Answer to:
(15)Given the following classes, how would you arrange them in an inheritance hierarchy? class Pen; class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships...

    UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships Labwork Please read all of the directions carefully. You will create a UML class diagram reflecting the class hierarchy for a fictional program that manages university personnel as constructed according to the graph displayed below. You will need to think about the attributes and behaviors that are unique to each class, and also those attributes and behaviors that are common amongst the subclasses and...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • Create classes to implement the following inheritance hierarchy: Book TextBook E-Book All books have a title,...

    Create classes to implement the following inheritance hierarchy: Book TextBook E-Book All books have a title, an ISBN number, a cost and a size (i.e., number of pages). Textbooks also have an area designation (such as ComputerScience or Anthropology) and a student discount percentage. E-books contain a platform designation (such as Kindle or Nook). You need only list the elds and a constructor for each class.

  • 1. Given the following code snippet, what is the scope of the variable pen on Line...

    1. Given the following code snippet, what is the scope of the variable pen on Line 1? <script> 1.    var pen = "ball point"; 2.    var pencil = "0.7mm lead"; 3.    function writeIt() 4.    { 5.          document.write(I have a " + pen + " pen."); 6.          pen = "gel ink"; 7.         document.write("You have a " + pen + " pen."); 8.          var pencil = "0.5mm lead"; 9.          document.write("I prefer pencils with " + pencil + "."); 10.   } <script> A. global B....

  • Consider the following Scala code that uses classes, objects, inheritance and dynamic method binding abstract class...

    Consider the following Scala code that uses classes, objects, inheritance and dynamic method binding abstract class A { def m) Int 1 val a Int = 2 class B extends A { val b: String "one" override def m() : Int = 3 def n(): Int 4 class C extends A { val x : Int 5 override def m() : Int = 6 val array an array of ten A objects array (5) val obj: A obj.m() = (a)...

  • You are given a specification for some Java classes as follows.   A building has a number...

    You are given a specification for some Java classes as follows.   A building has a number of floors, and a number of windows. A house is a building. A garage is a building. (This isn’t Florida-like … it’s a detached garage.) A room has a length, width, a floor covering, and a number of closets. You can never create an instance of a building, but every object that is a building must have a method that calculates the floor space,...

  • Java is an object-oriented programming language that enables us to define classes and to instantiate them...

    Java is an object-oriented programming language that enables us to define classes and to instantiate them into objects. These objects then call each other’s methods to implement the behavior of the application. The Unified Modeling Language (UML) is an object-oriented visual notation to document the design of object-oriented classes. For this discussion, you will practice designing a Java class called Course, drawing a UML class diagram for the Course class, and then implementing the Course class in Java code. Review...

  • Java Lab In this lab, you will be implementing the following class hierarchy. Your concrete classes...

    Java Lab In this lab, you will be implementing the following class hierarchy. Your concrete classes must call the superclass constructor with the proper number of sides (which is constant for each concrete shape). The perimeter method is implemented in the superclass as it does not change based on the number of sides. The area method must be overridden in each subclass as the area is dependent on the type of polygon. The areas of an equilateral triangle, square, and...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT