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.

b) Place the interface in the header file. What is the interface? , and 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?

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...

Answer the following statements true (T) or false (F)

1. Floating point constants are normally stored in memory as doubles. 2. C++ does not have a built-in data type for storing strings of data. 3. A named constant is like a variable, but it its content cannot be changed while the program is running. 4. C++ 11 introduced an alternative way to define variables, using the template key word and an initialization value.

Computer Science & Information Technology

(Multiples) Write a function multiple that determines for a pair of integers whether the sec- ond is a multiple of the first. The function should take two integer arguments and return true if the second is a multiple of the first, false otherwise. Use this function in a program that inputs a series of pairs of integers.

What will be an ideal response?

Computer Science & Information Technology