If a class have two data members and two functions to add those two numbers and to subtract them, which among the following is most efficient

Pham Quỳnh

New member
If a class have two data members and two functions to add those two numbers and to subtract them, which among the following is most efficient if the programmer wants to implement multiplication too?
A. Define a public function which multiplies two numbers
B. Define a public function that returns values of two data members
C. Define a private function which multiplies two numbers
D. Define a private function that returns values of two data members
 
Answer: b
Explanation: The best choice would be to define a public member function that returns the values of two data members of the class. This way we can implement any operation on those data members. Also there won’t be any need to modify the program and to add new functions for each new operation.
 

Tìm kiếm

Back
Top