Base class access specifier on the table

Base Class Access Specifier on the Table 15-1 

The base class access specifier determines the access privillege of a derived class to its base class.

In this exercise, we are going to inspect the access at three different scope:

1. Inside the Base class by the base class constuctor.

2. Inside the Derived class by the derived class constructor.

3. At the application , by referencing to the instance methods.

Detail information on the requirement is inside the starter.

Starter: lab11_starter.cpp 

Submit: lab11.cpp

Table 15-1
Base Class Access
Specification How Members of the Base Class Appear in the Derived Class.

private 

Private members of the base class are inaccessible to the derived class.
Protected members of the base class become private members of the
derived class.
Public members of the base class become private members of the derived class.

protected 

Private members of the base class are inaccessible to the derived class.
Protected members of the base class become protected members of the
derived class.
Public members of the base class become protected members of the derived
class.
public 

Private members of the base class are inaccessible to the derived class.
Protected members of the base class become protected members of the
derived class.
Public members of the base class become public members of the derived class.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lab11_starter.cpp is 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <iostream>

class Base
{
public:
int mPublic;
private:
int mPrivate;
protected:
int mProtected;
public:
Base() : mPublic(0), mPrivate(0), mProtected(0) {
std::cout << “nmPublic: ” << mPublic << std::endl
<< “mPrivate: ” << mPrivate << std::endl
<< “mProtected: ” << mProtected << “n … created Basen”;
}
int get_mPublic() {return mPublic;}
int get_mPrivate() {return mPrivate;}
int get_mProtected() {return mProtected;}
};

class Pub: public Base
{
public:
// Public inheritance means:
// mPublic stays public
int get_Pub_mPublic() { return mPublic; }
// mPrivate becomes inaccessible

// mProtected stays protected
int get_Pub_mProtected() { return mProtected; }

Pub()
{
// The derived class always uses the immediate parent’s class access specifications
// Thus, Pub uses Base’s access specifiers
mPublic = 1; // okay: anybody can access public members
//mPrivate = 2; // not okay: derived classes can’t access private members in the base class!
mProtected = 3; // okay: derived classes can access protected members
std::cout << ” … inherited and modified by cPubn”
<< “mPublic: ” << mPublic << std::endl
<< “mPrivate not available, use get_mPrivate(): ” << get_mPrivate() << std::endl
<< “mProtected: ” << mProtected << “n … created cPubn”;
}
};

class Pri: private Base
{
// Fill the blank with 
// 3 getters, if possible.
// Default constructor with same initialization values (1, 2, 3) , if possible.
// Also, make the Default constructor display the private data values, either accessing directly or via base class getter.
// If the above required feature can not be done, explain why in comment.
};

class Pro: protected Base
{
// Fill the blank with 
// 3 getters, if possible.
// Default constructor with same initialization values (1, 2, 3) , if possible.
// Also, make the Default constructor display the private data values, either accessing directly or via base class getter.
// If the above required feature can not be done, explain why in comment.

};

int main()
{
// Outside access uses the access specifiers of the class being accessed.
// In this case, the access specifiers of cPub. Because Pub has inherited publicly from Base,
// no access specifiers have been changed.
std::cout << “n … creating cPub”;
Pub cPub;
cPub.mPublic = 4; // okay: anybody can access public members
// cPub.mPrivate = 5; // not okay: can not access private members from outside class
//cPub.mProtected = 6; // not okay: can not access protected members from outside class
std::cout << ” … access cPub by applicationn”
<< “cPub.get_Pub_mPublic(): ” << cPub.get_Pub_mPublic() << std::endl
<< “cPub.get_Pub_mPrivate(): ” << “does not exist!” << std::endl
<< “cPub.get_mPrivate(): ” << ” inaccessible, a private Base method!” << std::endl
<< “cPub.get_Pub_mProtected(): ” << cPub.get_Pub_mProtected() << “n”;

std::cout << “n … creating cPri”;
Pri cPri;
// Fill the blank below
// 1. to modify the value of the private data memeber of the base class to (4, 5, 6), 
// no need to explore the modification by the setter() method.
// 2. to retrieve and display the value of base class data members via either 
// cPro class methods, if possible.
// 3. If the private data member of the base class can not be accessed, explain.

std::cout << “n … creating cPro”;
Pro cPro;
// Fill the blank below, same requirement as above.

// However, we can still can access Base members as normal through Base:
Base cBase;
cBase.mPublic = 4; // okay, mPublic is public
//cBase.mPrivate = 5; // not okay, mPrivate is private
//cBase.mProtected = 6; // not okay, mProtected is protected
std::cout << ” … access cBase by applicationn”
<< “cBase.mPrublic: ” << cBase.mPublic << std::endl
<< “cBase.mPrivate: ” << “inaccessible, a private member!” << std::endl
<< “cBase.mProtected: ” << ” inaccessible, a protected member!” << std::endl;

}

Calculate your paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Quality Papers

We value our clients. For this reason, we ensure that each paper is written carefully as per the instructions provided by the client. Our editing team also checks all the papers to ensure that they have been completed as per the expectations.

Professional Academic Writers

Over the years, our Acme Homework has managed to secure the most qualified, reliable and experienced team of writers. The company has also ensured continued training and development of the team members to ensure that it keep up with the rising Academic Trends.

Affordable Prices

Our prices are fairly priced in such a way that ensures affordability. Additionally, you can get a free price quotation by clicking on the "Place Order" button.

On-Time delivery

We pay strict attention on deadlines. For this reason, we ensure that all papers are submitted earlier, even before the deadline indicated by the customer. For this reason, the client can go through the work and review everything.

100% Originality

At Essay USA, all papers are plagiarism-free as they are written from scratch. We have taken strict measures to ensure that there is no similarity on all papers and that citations are included as per the standards set.

Customer Support 24/7

Our support team is readily available to provide any guidance/help on our platform at any time of the day/night. Feel free to contact us via the Chat window or support email: support@acmehomework.com.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Essay USA has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.

Essays

Essay Writing Services

At Essay USA, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.

Admissions

Admission and Business Papers

Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.

Editing

Editing and Proofreading

Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.

Coursework

Technical papers

We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.