Chp6 - C PROGRAMMING Chapter 6 Basic Classes Creating New...

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

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 6 Basic Classes Creating New Types Why Create a New Type? Classes and Members Declaring a Class A Word on Naming Conventions Defining an Object Classes Versus Objects Accessing Class Members Assign to Objects, Not to Classes If You Dont Declare It, Your Class Wont Have It Private Versus Public Listing 6.1. Accessing the public members of a simple class. Make Member Data Private Listing 6.2. A class with accessor methods . Privacy Versus Security The class keyword Implementing Class Methods Listing 6.3. Implementing the methods of a simple class. Constructors and Destructors Default Constructors and Destructors Listing 6.4. Using constructors and destructors . const Member Functions Interface Versus Implementation Listing 6.5. A demonstration of violations of the interface . Why Use the Compiler to Catch Errors? Where to Put Class Declarations and Method Definitions Inline Implementation Listing 6.6. Cat class declaration in CAT.HPP . Listing 6.7. Cat implementation in CAT.CPP. Classes with Other Classes as Member Data Listing 6.8. Declaring a complete class . Listing 6.9. RECT.CPP . Structures Why Two Keywords Do the Same Thing Summary Quiz , Exercises
Background image of page 1

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

View Full Document Right Arrow Icon
Chapter 6 Basic Classes Classes extend the built-in capabilities of C++ to assist you in representing and solving complex, real-world problems. ToChapter you will learn What classes and objects are. How to define a new class and create objects of that class. What member functions and member data are. What constructors are and how to use them. Creating New Types You've already learned about a number of variable types, including unsigned integers and characters. The type of a variable tells you quite a bit about it. For example, if you declare Height and Width to be unsigned integers, you know that each one can hold a number between 0 and 65,535, assuming an integer is two bytes. That is the meaning of saying they are unsigned integers; trying to hold anything else in these variables causes an error. You can't store your name in an unsigned short integer, and you shouldn't try. Just by declaring these variables to be unsigned short integers, you know that it is possible to add Height to Width and to assign that number to another number. The type of these variables tells you: Their size in memory. What information they can hold. What actions can be performed on them. More generally, a type is a category. Familiar types include car, house, person, fruit, and shape. In C++, the programmer can create any type needed, and each of these new types can have all the functionality and power of the built-in types. Why Create a New Type?
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.

{[ snackBarMessage ]}

Page1 / 31

Chp6 - C PROGRAMMING Chapter 6 Basic Classes Creating New...

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