Question

Question 2 Answer the questions (i) to (iv) based on the following: class PRODUCT { int...

Question 2

Answer the questions (i) to (iv) based on the following:

class PRODUCT

{

int Code:

char Item[20];

protected:

float Qty;

public:

PRODUCT ( );

void GetIn( ); void Show( ):

};

class WHOLESALER

{

int WCode;

protected:

char Manager[20];

public:

WHOLESALER();

void Enter();

void Display ();

};

class SHOWROOM : public PRODUCT,

private WHOLESALER

{

char Name[20],City[20];

public:

SHOWROOM();

void Input ();

void View ( );

};

(i) Which type of Inheritance out of the following is illustrated in the above example?

(ii) Write the names of all the data members, which are directly accessible from the member functions of class SHOWROOM.

(ii) Write the names of all the member functions, which are directly accessible by an object of class SHOWROOM.

(iii) What will be the order of execution of the constructors, when an object of class SHOWROOM is declared?

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

Here is the answer of all 4 parts one by one.

i) MULTIPLE INHERITANCE

Reason: Since class "SHOWROOM" is inheriting more than one class i.e "PRODUCT" and "WHOLESALER"

-----------------------------------------------------------------------------------------------------------------------------------------------------

ii) The data members that are directly accesible in member function of SHOWROOM class are :

a) float Qty ------- from PRODUCT class

b) char Manager[20] ---------- from WHOLESALER class

Explanation: all other data members such as [  int Code, char Item[20] ] in PRODUCT class is private and also data member [ int WCode ] is private in WHOLESALER class. and you can not access a private member of a class to any other class.

-------------------------------------------------------------------------------------------------------------------------------------------------

iii)

GetIn();
Show();

These two member function arefrom PRODUCT class and we can access them in SHOWROOM class.

Enter();
Display();

These two member function arefrom WHOLESALER class and we can access them in SHOWROOM class.

So all member function from both class are accessible in SHOWROOM class

Reason: Since all the member function are public, so all of them are accessible in SHOWROOM class

------------------------------------------------------------------------------------------------------------------------------------------------

iv) Order of execution of constructor:

PRODUCT()

WHOLESALER()

SHOWROOM()

Reason: Order of execution is defined by order of inheritance and when you make an object the super class constructor will be excuted first.

  

Add a comment
Know the answer?
Add Answer to:
Question 2 Answer the questions (i) to (iv) based on the following: class PRODUCT { int...
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
  • Question 1 10 pts Inheritance is a capability of C++ to represent increased specialization that is...

    Question 1 10 pts Inheritance is a capability of C++ to represent increased specialization that is often found in real world relationships. True False Question 2 10 pts Inheritance between a child and parent object exhibits an 'relationship. Question 3 10 pts As you move down an inheritance relationship from parent to child, you typically move from a general to specific description. True False Question 4 10 pts The syntax for declaring DerivedClass to publicly inherit from BaseClass is given...

  • C++ class Time { public: Time(); Time(int hrs, int min, int sec); private: int hours; int...

    C++ class Time { public: Time(); Time(int hrs, int min, int sec); private: int hours; int minutes; int seconds; }; 1. Write the class definition for ExtendedTime which derives from Time via public inheritance. Add private data member time_zone which is an enum type TimeZone (enum TimeZone { PACIFIC, MOUNTAIN, CENTRAL, EASTERN } ). Add a default and alternate constructors to ExtendedTime to initialize all class (including the base class) data; use the base member initialization list. NOTE: This implies...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {    super();    System.out.println(“B() called”);...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {   super();   System.out.println(“B() called”); } public...

  • C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement...

    C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement the constructors and member function of each of the classes (Marks 15) class Fraction{ private: int numerator; int denominator; public: Fraction(int, int); float fractionValue();//determines the value of numerator/denominator }; class Problem{ private: Fraction f[3]; public: Problem(int, int, int, int, int, int); Fraction largestFraction();//Returns the fraction having largest fraction value }; Question 2: In the following Inheritance problem #include<iostream> #include<string> using namespace std; class Animal{...

  • D Question 6 4 pts Figure 1: clock Type |-hr: int -min: int -sec; int setTime...

    D Question 6 4 pts Figure 1: clock Type |-hr: int -min: int -sec; int setTime (int, int, int): void get Time (inte, int&, int&) const: void printTime() const: void increment seconds(): int +incrementMinutes(): int +increment Hours(): int -equalTime (const clockType.) const: bool Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? none zero two three D Question 4 4 pts Consider the following class...

  • 1. Questions on inheritance. (a) Consider the following program segment: 1 class Array2 2 private: ClassX...

    1. Questions on inheritance. (a) Consider the following program segment: 1 class Array2 2 private: ClassX a: // ClassY b: // assume class ClassY is defined. assume class ClassX is defined . 3 4 5 public: 6 Array2 (int size) ( a new Clas sX [ size]; // a is an array of ClassX objects b new ClassY [size]: 1/ b is an array of ClassY objects 7 8 9 ) 10 ClassX getA() (return a; ) ClassY getB ()...

  • please this is Java and i need help Question 5 public class Food { public void...

    please this is Java and i need help Question 5 public class Food { public void Foodmethod_1 (int i) { public void Foodmethod_2 (int i) { } public static void Foodmethod_3(int i) { public class Bankudade extends Food { public static void Foodmethod_1 (int i) { public void Foodmethod_2 (int i) { public void Foodmethod_3 (int i) { > 7 a) Determine which method in the subclass overrides a method in the super class? (6 marks) EV b) Determine which...

  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee {        private:             int age;             int id;             float salary;        public:             Employee( ); // default constructor: age=0, id=0, and salary=0             Employee(Employee &x);   // copy constructor           Employee& operator = (Employee &x); // equal sign operator             void setAge(int x);    // let age = x...

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