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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.