Lec14 - Lecture 14: Classes Todd Wittman PIC 10A Sec 5.1:...

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

View Full Document Right Arrow Icon
1 Lecture 14: Classes Todd Wittman PIC 10A Sec 5.1 : Classes s Recall that a class is a suped-up data type equipped with special member functions . s We call an instance of a class an object . s The string class is an example of a class. string my_string = “hobbit”; class name object name value of object s The insert function is an example of a member function. my_string.insert(3,”orc”); //Use with a period after object name. s In Chapter 3, we saw some classes defined by your textbook author. s The Time class s The Employee class s Graphics classes: Point, Circle, Line, Message
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Why Use Classes? s In Chapter 6, we’ll learn how to create our own classes. s Why bother? OK, that’s a fair question. s Suppose you’re a computer graphics programmer. s What other graphics objects would you like to have available besides Line, Circle, Point? s Triangle? Rectangle? Curve? Gollum? s What member functions would you like to add to the graphics objects? s changeColor? fillObject? setFontSize? s For business and banking, it might be useful to have a Database object to store numbers and make calculations. You can think of an Xcel spreadsheet as one of Microsoft’s objects. Sec 5.2 : Interfaces s Declaring a class is a lot like declaring a function. class Class_name { public: constructor declarations member function declarations private: data fields }; s Public fields are accessible outside the class. s
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Lec14 - Lecture 14: Classes Todd Wittman PIC 10A Sec 5.1:...

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

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