Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: You are given a class below class Book { public: string bookName; vo

ID: 666570 • Letter: Q

Question

Question 1: You are given a class below

class Book

{

public:

            string bookName;

            void describle();

protected:

            int year;

private:

            double price;

};

1)Which fields can be accessed by the outside?

Answer:

2)Which fields can be accessed by the function describe()?

Answer:

3)Which fields can be accessed by the sub class?

Answer:

Question 2: You are given a class below, create a accessor and mutator function for field price.

class Book

{

public:

            string bookName;

            void describle();

protected:

            int year;

private:

            double price;

};

Accessor function:

Mutator function:

Question 3: What is the benefit of using inheritance?

Answer:

Explanation / Answer

1. only public will be accessible.

so bookname and describe will be accessible.

2. All the fields can be accessed.

3. Sub class can access bookname, describe and price.

public double getprice()
{
    return price;
}

public void setprice( double pri )
{
    price = pri;
}

3.

It helps in minimizing the amount of duplicate code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote