L15_classes - Classes and Objects Classes and Objects...

Info iconThis preview shows pages 1–11. 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

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: Classes and Objects Classes and Objects Encapsulation Value of classes and objects Defining classes Data encapsulation Procedural encapsulation EECS 183 University of Michigan Classes Mary Lou Dorf Declaring and using objects C++ string C++ string What would you like to do with string s declare string str = abc def abc; string str2 = Maroon5 rocks; read cin >> str; write EECS 183 University of Michigan Classes Mary Lou Dorf cout << str; assignment str = str2; find the size int i = str2.size(); i = str2.length(); compare different strings if (str < str2) Only a few of the many options Encapsulation Encapsulation objects + functions objects + functions Combining a number of items, such as variables and functions, into a single package, such as an object of some class llows us to create new tatypes EECS 183 University of Michigan Classes Mary Lou Dorf Allows us to create new datatypes What is a datatype? What is a datatype? What is a datatype? Data values 1, 2, 65536, 2147483648, 4294967296 Data storage (an encoding scheme) int num; Operations on the data um = 0; EECS 183 University of Michigan Classes Mary Lou Dorf num = 0; num = num + 6; A familiar interface that gives us access to data and allows operations on data string is a class string is a class a datatype string str = testing; but it also has functions that can act upon the data/variable str.length(); cin >> str; EECS 183 University of Michigan Classes Mary Lou Dorf cout << str; str += one; getline(cin,str); That makes string a class How to create user defined How to create user defined DataTypes DataTypes just data struct if you want functionality class EECS 183 University of Michigan Classes Mary Lou Dorf Example: program with Time Example: program with Time Data needed: Hour (integer in range 0 to 23) Minute (integer in range 0 to 59) Second (integer in range 0 to 59) EECS 183 University of Michigan Classes Mary Lou Dorf Functionality needed Create a time (assembled from parts) Input a time from file or keyboard Output a time to file or monitor Date arithmetic (how many hours/minutes/seconds between two times? What time do you get if you add x minutes to an existing time? Etc.) Ex: program with Time, contd Ex: program with Time, contd EECS 183 University of Michigan Classes Mary Lou Dorf Encapsulation is the answer Encapsulation is the answer C++ provides ways for you to create your own datatypes struct TimeType { int hour; EECS 183 University of Michigan Classes Mary Lou Dorf int minute; int second; }; Member variables How do you???? How do you????...
View Full Document

This note was uploaded on 02/12/2010 for the course EECS 183 taught by Professor Dorf during the Fall '08 term at University of Michigan.

Page1 / 61

L15_classes - Classes and Objects Classes and Objects...

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

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