Using Set and Get Functions

A class's private data members can be accessed only by member functions (and friends) of the class. Classes often provide public member functions to allow clients of the class to set (i.e., write) or get (,.e., read) the values of private data members. These functions need not be called set and get specifically, but they often are. The program of Figs. 1.26-1.30 enhances class Time to include set and get functions for the private data members hour, minute, and second.























Figure 1.26: Time class definition with set and get functions.
\includegraphics[scale=0.45]{figures/img66.ps}
\includegraphics[scale=0.45]{figures/img67.ps}
Figure 1.27: Time class member-function definitions,including set and get functions. (part 1 of 2)
\includegraphics[scale=0.45]{figures/img68.ps}
\includegraphics[scale=0.45]{figures/img69.ps}
Figure 1.28: Time class member-function definitions,including set and get functions. (part 2 of 2)
\includegraphics[scale=0.45]{figures/img70.ps}
\includegraphics[scale=0.45]{figures/img71.ps}
Figure 1.29: Set and get functions manipulating an object's private data. (part 1 of 2)
\includegraphics[scale=0.45]{figures/img72.ps}
\includegraphics[scale=0.45]{figures/img73.ps}
Figure 1.30: Set and get functions manipulating an object's private data. (part 2 of 2)
\includegraphics[scale=0.45]{figures/img74.ps}
\includegraphics[scale=0.45]{figures/img75.ps}
2004-07-29