
Concept explainers
Class Access Modifiers:
The feature of object oriented
There are three access specifiers used in the class to restrict the access of members inside the class. They are as follows:
- Public
- Protected
- Private
For classes and members, the default access specifier is “private”.
Sample code:
/* class Base defines the member functions and variables with appropriate access modifiers */
class Base
{
public:
//public members
protected:
// protected members
private:
// private members
};
Explanation of Solution
Private members:
From outside of a class, a member variable that is private could not be accessed, or viewed. Class could access members that are private and friend functions only.
By default, class members are private, for example in class given below “width” denotes a private member, which denotes that until a label is provided to a member, it would be assumed as a private member:
/* class lBox defines member functions “lsetWidth” and “lgetWidth”*/
class lBox
{
// Variable declarations
double lwidth;
public:
// Variable declarations
double length;
// Member function declarations
void lsetWidth( double lwid );
double lgetWidth( void );
};
The data is defined in private members, and related functions are defined in public section, so that it could be called from outside of a class, as shown in below program.
This program shows the usage of “Private” access modifier, in which member variables could not be accessed from outside of class.
// Select header files
#include <iostream>
using namespace std;
Declare the class lBox that defines the member functions “lsetWidth()” and “lgetWidth()” to set and return the width for box.
//Create the class
class lBox
{
public:
// Variable declarations
double length;
// Member function declarations
void lsetWidth( double lwid );
double lgetWidth( void );
private:
// Variable declarations
double lwidth;
};
Define the member function lgetWidth() to return width of box...
Explanation of Solution
Protected members:
A protected member function or variable denotes similarity to a private member. That is, from outside of a class, accessing a member variable or function that is protected is not possible.
- An additional benefit is that they can be accessed within child classes which are known as derived classes.
- In below example, “width” member could be accessed by the derived class “SmallBox” member function.
This program shows the usage of “Protected” access modifier, in which member variables could not be accessed from outside of a class, but it could be accessed within child classes which are termed as derived classes.
// Select header files
#include <iostream>
using namespace std;
Declare the class lBox that defines the variable “width” to set and return the width for box.
// class lBox defines “width” as a protected variable”
class lBox
{
protected:
// Variable declarations
double width;
};
Declare the class “SmallBox” that defines the member functions “lsetSmallWidth()” and “lgetSmallWidth()” to set and return the width for box...

Want to see the full answer?
Check out a sample textbook solution
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
- Describe three (3) Multiplexing techniques common for fiber optic linksarrow_forwardCould you help me to know features of the following concepts: - commercial CA - memory integrity - WMI filterarrow_forwardBriefly describe the issues involved in using ATM technology in Local Area Networksarrow_forward
- For this question you will perform two levels of quicksort on an array containing these numbers: 59 41 61 73 43 57 50 13 96 88 42 77 27 95 32 89 In the first blank, enter the array contents after the top level partition. In the second blank, enter the array contents after one more partition of the left-hand subarray resulting from the first partition. In the third blank, enter the array contents after one more partition of the right-hand subarray resulting from the first partition. Print the numbers with a single space between them. Use the algorithm we covered in class, in which the first element of the subarray is the partition value. Question 1 options: Blank # 1 Blank # 2 Blank # 3arrow_forward1. Transform the E-R diagram into a set of relations. Country_of Agent ID Agent H Holds Is_Reponsible_for Consignment Number $ Value May Contain Consignment Transports Container Destination Ф R Goes Off Container Number Size Vessel Voyage Registry Vessel ID Voyage_ID Tonnagearrow_forwardI want to solve 13.2 using matlab please helparrow_forward
- a) Show a possible trace of the OSPF algorithm for computing the routing table in Router 2 forthis network.b) Show the messages used by RIP to compute routing tables.arrow_forwardusing r language to answer question 4 Question 4: Obtain a 95% standard normal bootstrap confidence interval, a 95% basic bootstrap confidence interval, and a percentile confidence interval for the ρb12 in Question 3.arrow_forwardusing r language to answer question 4. Question 4: Obtain a 95% standard normal bootstrap confidence interval, a 95% basic bootstrap confidence interval, and a percentile confidence interval for the ρb12 in Question 3.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning




