lecture34-apr23 - 4/23/10 Lecture 34 Check it out

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
4/23/10 1 Lecture 34 Check it out http://www.swisseduc.ch/stromboli/perm/iceland/eyafallajokull_20100416-de.html • Assignment 6 – write down your stats • Assignment 7 – out today –due last day of classes • Topics of the day – More OO Bank Accounting – Access speciFers – Member function variations – More on constructors/destructors this pointer – Object operators – Overloaded operators – Dynamic storage allocation Banking OO Program BankAccount class Driver (client) Program Models bank accounts. It deFnes the instance variables, and functions to be used on all objects created from this class (a template) Uses the BankAccount class to create and then manipulate bank account objects. The main function is here. Class DeFnition - version 2 class BankAccount // the template for bank account objects { private: // here are the instance variables int accountNumber; string ownersName; double balance; public: // all the member functions are defined here BankAccount(int account, string name,double initialBalance ) { accountNumber = account; ownerName = name; balance = initialBalance; } ~BankAccount ( ) { } // do nothing destructor void deposit(double amount) { if (amount < 0) { cout << “negative deposit not allowed”; } else balance = balance + amount; } void withdraw(double amount) { if (amount > balance) { cout << “insufficient funds to withdraw”; } else balance = balance - amount; } double getBalance() { return balance; } } BankAccount Class Additions // get and set functions for all instance variables are useful public: int getAcctNumber ( ) { return accountNumber}; string getOwner ( ) { return ownersName } ; // already have a get balance function // (re)set value functions void setAcctNumber (int acctno ) { accountNumber = acctno;}; void setOwner (string owner) {ownersName = owner; } void setBalance (double bal) { balance = bal; } The class is now fully OO Access Specifers Members of a class are divided into access control categories: private (scope only within the class definition) - private members are known only inside of objects of that class public (scope within it’s object’s declaration scope), typically in OOD the public parts provide a controlled interface to the private parts protected (similar to private, but access is also available to derived classes and objects) Keep the client programmer’ s hands off those data and private member functions that they are not supposed to touch Also to ease the life of the programmer because he/she doesn’t have to learn too many interfaces
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

lecture34-apr23 - 4/23/10 Lecture 34 Check it out

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online