11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

168Part III: Introduction to ClassesActivating Our ObjectsYou use classes to simulate real-world objects. The Savings class tries torepresent a savings account. This allows you to think in terms of objectsrather than simply lines of code. The closer C++ objects are to the real world,the easier it is to deal with them in programs. This sounds simple enough.However, the Savings class doesn’t do a very good job of simulating a savingsaccount.Simulating real-world objectsReal-world objects have data-type properties such as account numbers andbalances, the same as the Savings class. This makes Savings a good startingpoint for describing a real object. But real-world objects do things. Ovenscook. Savings accounts accumulate interest, CDs charge a substantial penaltyfor early withdrawal — stuff like that.Functional programs “do things” via functions. A C++ program might callstrcmp() to compare two strings or max() to return the maximum of twovalues. In fact, Chapter 24 explains that even stream I/O (cin >> and cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!