|
|
|
|
|
|
|
In Figure 4-7, we picture the cin and cout objects as entities that have a private part and a public part. The private part includes data that the user cannot access and doesn't need to know about in order to use the object. The public part, shown as ovals in the side of the object, consists of operations that are available to programmers wishing to use the object. In C++, these public operations are written as functions and are called member functions. Except for the < and >> operations, a member function is invoked by giving the name of the class object, then a dot, and then the function name and parameter list: |
|
|
|
|
|
|
|
|
cin.ignore(100, \n);
cin.get(someChar);
cin >> someInt; |
|
|
|
|
|
|
|
|
OOD leads to programs that are collections of objects. Each object is responsible for one part of the entire solution, and the objects communicate with each other by calling one another's member functions. OOD is especially suitable for large software projects for three reasons. First, objects within a program often model real-life objects in the problem to be solved. In a banking problem, it may be easier to design a solution by thinking about what objects are requireda savings account object, a checking account object, a teller object, a cash drawer objectthan by thinking about what actions are required (do this step, then that step, then the next step, and so |
|
|
|
|
|
|
|
|
Figure 4-7
Objects and Their Operations |
|
|
|
|
|