Download presentation
Presentation is loading. Please wait.
Published byErik Tolley Modified over 9 years ago
1
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS
2
Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data are stored inside the computer or how the data operations are performed inside the computer. This is referred to as data abstraction.
3
Chapter 3 Abstract Data Type, or ADT An abstract data type, or ADT, describes the data attributes and behavior of its objects. –The term behavior has to do with how the ADT will act and react for a given operation.
4
Chapter 3 Data Hierarchy in C++
5
Chapter 3 Class A class in C++ is a programming unit, or construct, that allows you to build your own ADTs. Classes contain data to provide the ADT attributes and functions to provide the ADT behavior.
6
Chapter 3 The Integer Types –short int, or short –int –unsigned int –long int, or long –unsigned long
7
Chapter 3 The Floating-Point Types –float –double –long double
8
Chapter 3 The Character Types –char – unsigned char The Boolean Type –bool
9
Chapter 3 Defining Constants c onst data type constant identifier = constant value; Defining Variables data type variable identifier = optional initializing value;
10
Chapter 3 Constant Identifiers Use all caps for constant identifiers, separating words with an underscore, _, symbol. Variable and Object Identifiers Begin with lowercase, then begin each additional word with uppercase, running the words together in multiword identifiers.
11
Chapter 3 Strings A string is simply a collection of characters. Examples of strings include your name, address, and phone number, as well as the sentence you are now reading. –String Object Definition Using the String Class String object name = “initializing string value”;
12
Chapter 3 String Operations s.empty()Returns true if the string s has no characters. s.length()Returns the length of s. s1 == s2 Returns true if s1 equals s2, else returns false. s1 != s2 Returns true if s1 does not equal s2, else returns false. s1 < s2 Returns true if s1 is less than s2, else returns false. s1 > s2 Returns true if s1 is greater than s2, else returns false. s1 = s2Copies, or assigns, s2 to s1. s = s1 + s2Concatenates s2 to s1 to form s. s1 += s2 Appends s2 to s1.
13
Chapter 3 Tip Remember that C++ is case-sensitive. Thus, using the string “Hello World” is not equivalent to the string “hello world”. And, because of the ASCII ordering of characters, the string “Hello World” is less than the string “hello world”.
14
Chapter 3 Enumerated Data Enumerated data type consists of a set of data values that you, the programmer, define for a particular application as follows: enum type identifier {value #1, value #2, ···, value #n}; type identifier variable identifier;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.