Object Oriented Programming Using C CLASS 3 IDLOOPC1998 1 Objectives To understand the software engineering concepts of encapsulation and data hiding To understand the notions of data abstraction and abstract data types ADTs To be able to create use and destroy class objects IDLOOPC1998 2 Objectives To be able to control access to object data members and member functions To begin to appreciate the value of object orientation IDLOOPC1998 3 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items entered public void initCount void decLare method void enterItem void decLare method void printTotal void decLare method IDLOOPC1998 4 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items entered Keyword class to specify that public void we re initCount void decLare method called declaring a class void enterItem void decLare method void ledger printTotal void decLare method IDLOOPC1998 5 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items The body of declaration is entered public curly brackets void delimited initCount void with decLare method void and enterItem void decLare method terminated with a void printTotal void decLare method semicolon IDLOOPC1998 6 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items entered public void initCount void decLare method void enterItem void decLare method void printTotal void decLare method Within the class the variables list and count are declared IDLOOPC1998 7 Declaring a Class class ledger can declaration of class In a class we declare ledger functions as well as variables private in define classarray arefor called floatFunctions list 100 items int count define number of items methods Declare the methods entered public initCount enterItem and void initCount void decLare method voidprintTotal enterItem void decLare method void printTotal void decLare method IDLOOPC1998 8 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items of class int count Some members define number of items entered ledger are private and public some are public void initCount void decLare method void enterItem void decLare method void printTotal void decLare method IDLOOPC1998 9 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items entered The data items are all public voidprivate initCount void decLare method void enterItem void decLare method void printTotal void decLare method IDLOOPC1998 10 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items The methods are all public entered public void initCount void decLare method void enterItem void decLare method void printTotal void decLare method IDLOOPC1998 11 Declaring a Class of class class ledger Some members declaration of class ledger ledger are private and some are public The data private float list 100 define array for items items are all private and the int count define number of items methods are all public entered public Public can be accessed void initCount void decLare method from outside themethod object and void enterItem void decLare void printTotal void decLare method private can be accessed only from within the object The keyword private is the default IDLOOPC1998 12 Declaring a Class class ledger declaration of class ledger private float list 100 define array for items int count define number of items entered public void initCount void decLare method void enterItem void decLare method void printTotal void decLare method Declaration of ledger shown above does not define any objects of class ledger It only specifies what objects will contain if they are defined IDLOOPC1998 13 void ledger intCount void a function in class ledger initializes count to 0 count 0 void ledger enterItem void a function in puts entry in list cout nEnter amount cin list count void ledger printTotal void a function in prints total of all float total 0 0 for int j 0 j count j total list j cout n nTotal is total n IDLOOPC1998 14 void ledger intCount void a function in class ledger initializes count to 0 count 0 void ledger enterItem void a function in puts entry in list cout nEnter amount cin list count void ledger printTotal void a function in prints total of all float total 0 0 for int j 0 j count j total list j cout n nTotal is total n initCount simply sets the variable count to 0 IDLOOPC1998 15 void ledger intCount void a function in class ledger initializes count to 0 count 0 void ledger enterItem void a function in puts entry in list cout nEnter amount cin list count void ledger printTotal void a function in prints total of all float total 0 0 for int j 0 j count j total list j cout n nTotal is total n enterItem prints a prompt to the user and then assigns the amount typed by the user to the array member list count IDLOOPC1998 16 void ledger intCount void a function in class ledger initializes count to 0 count 0 void ledger enterItem void a function in puts entry in list cout nEnter amount cin list count void ledger printTotal void a function in prints total of all float total 0 0 for int j 0 j count j total list j cout n nTotal is total n printTotal finds the total of the amounts and prints out the total IDLOOPC1998 17 Expense cpp Overhead IDLOOPC1998 18 Main Driver Overhead IDLOOPC1998 19 Create a Time Class Overhead IDLOOPC1998 20 Q A IDLOOPC1998 21
View Full Document
Unlocking...