slides-5

slides-5 - 1 Data Structures CSCI 102 Copyright © William...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 Data Structures - CSCI 102 Copyright © William C. Cheng CS102 C++ Object-Oriented Programming Bill Cheng http://merlot.usc.edu/cs102-s11 Polymorphism (Ch 13) Virtual functions Abstract classes Interfaces Pointers & Dynamic Objects (Ch 13) C Structs (Ch 10) Topics to cover 2 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Object-Oriented Programming C++ Classes (Ch 11) Constructors Destructors Member functions Exceptions (Ch 15) Namespaces (Ch 8) Operator Overloading (Ch 14) Class Composition & Inheritance (Ch 12) Needed a way to group components that are related, but have different data types 3 Data Structures - CSCI 102 Copyright © William C. Cheng C Structs Members are public by default NOTE: struct has changed in C++! struct Person { char name[20]; int age; }; Difficult to make sure that no one will set age to a negative value! if this object class is to be used by others An expanded data structure Can contain related data AND functions What are C++ classes? 4 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Classes A composition mechanism Create really large and powerful software systems from tiny components Split things up into manageable pieces Delegation of responsibility An abstraction mechanism Make functionality publicly available, but hide data & implementation details C++ Combine data and the functions that operate on that data into a single unit Encapsulation 5 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Class Concepts Hide all important data behind a well-controlled access interface Data/Information Hiding Separate the logic properties of an object from its implement details Data Abstraction Depend only on an interface! (e.g. a microwave) Protect yourself from users & protect your users from themselves Member variables What data must be stored? What are the main parts of a class? 6 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Classes: Overview Constructor(s) How do you build an instance? Member functions How does the user need to interact with the stored data? Destructor How do you clean up an after an instance? Most common C++ operators will not work by default (e.g. ==, +, <<, >>, etc.) Defaults is private (only class functions can access) Member data can be public or private (for now) 7 Data Structures - CSCI 102 Copyright © William C. Cheng C++ Classes: Overview Must explicitly declare something public The only ones you get are ’=’ and ’.’ Pass them to functions (by copy, reference or pointer) Classes may be used just like any other data type (e.g. int) Return them from functions C++ won’t automatically initialize member variables...
View Full Document

This note was uploaded on 02/17/2011 for the course CSI 102 taught by Professor Billcheng during the Spring '11 term at USC.

Page1 / 25

slides-5 - 1 Data Structures CSCI 102 Copyright © William...

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

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