Select the correct rules for encapsulation. If any rules need to be imposed in a particular order, then say so, mentioning which rules.

a. Make all class member variables public members of the class.
b. Place the interface in the header file. What is the interface?
c. Place the implementation in a separate code file (with file extension required by your compiler: .cpp, .cxx, etc), called the implementation file. What is the implementation?
d. Having private members visible in the interface violates the philosophy of separating the interface from the implementation. Separate interface and implementation requires removal of all the private members from the class definition. You must put these in another part of the class definition in the implementation.

Except for a) and d), all of the above, in no particular sequence, so long as all are done. All variable members should be private, not public. The suggestion in d) to divide the class definition across the implementation and interface files is not possible.
Explanation: a) Having public data members violates encapsulation. The private members are part of the implementation, not part of the interface. Since a class in C++ cannot be split across two files and other C++ design reasons, the compromise of putting private members in the class definition was reached.
b) What is the interface? The interface is the class definition containing constructors, destructor, declarations of each basic operation of the class, declarations of friend functions. Grouped with the class definition are the declarations of ordinary functions and of nonmember overloaded operators and any needed comments that explain how to use functions.
c) What is the implementation? The implementation consists of the definitions of all member functions, overloaded operator definitions (members and nonmembers) with definitions of any helping functions or other additional items necessary to these definitions. Inclusion of the interface file in the implementation file will be necessary to compile the implementation file.
d) A class in C++ cannot be split across two files. The private members must be placed in the class definition.

Computer Science & Information Technology

You might also like to view...

What is not true about ROM (Read Only Memory)?

A) It only plays a small role in the startup process. B) It is not volatile. C) It plays a very important part in the startup process. D) It can usually only be read from, not written to.

Computer Science & Information Technology

In an Excel PivotTable, which area contains the cells that summarize quantitative data?

A) Row labels B) Values C) Column labels D) Pivot area

Computer Science & Information Technology