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.

Chapter 13Making Classes WorkIn This Chapter Adding active properties to the class Declaring and defining a member function Accessing class member functions Overloading member functionsProgrammers use classes to group related data elements into a singleobject. The following Savings class associates an account balance witha unique account number:class Savings{public:unsigned accountNumber;float balance;};Every instance of Savings contains the same two data elements:void fn(void){Savings a;Savings b;a.accountNumber = 1; // this is not the same as...b.accountNumber = 2; // ...this one}The variable a.accountNumber is different from the variableb.accountNumber, just as the balance in my bank account is different fromthe balance in yours, even though they’re both called balance (or, in the caseof my account, lack of balance).

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

Saved successfully!

Ooh no, something went wrong!