Chapter8 - An Introduction To Classes Engineering Problem...

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

View Full Document Right Arrow Icon
10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 8 An Introduction to Classes An Introduction To Classes ± Programmer Defined Types ± Design and Implementation of Classes ± Class Composition ± Constructors ± The vector class ± private M ethods 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 2 PROGRAMMER DEFINED TYPES 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 3 Data Types ± A data type is a concrete implementation of a concept. ± Built in types include: int, double, char ± Pre-defined class types include: string, istream, ostream ± Real world applications work with concepts that are not available as built-in or pre-defined types. 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 4
Background image of page 1

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

View Full DocumentRight Arrow Icon
Programmer Defined Types ± Consider the concept of a point in a plane, defined as a: xCoordinate yCoordinate ± Subtraction between points can be defined as a binary operation that returns the distance between two points in a plane. Point p1, p2; double dist; dist = p2-p1; ± As a programmer, we can define a new type named Point by defining a C++ class named Point. 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 5 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 6 Programmer Defined Types ± A well-designed class type provides: a good public interface. encapsulation of the implementation. ± A good public interface provides a complete yet minimal set of public operations. ± Encapsulation hides the implementation from the user. ± A good public interface and encapsulation allow for efficient maintenance and expandability of the class type. DESIGN AND IMPLEMENTATION OF CLASSES class declaration class implementation 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 7 10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 8 Defining C++ Classes ± The definition of a class consists of two parts: The class declaration saved in a file with a .h extension The class implementation saved in a file with a .cpp extension the .cpp file should #include the .h file
Background image of page 2
10/27/2009 Engineering Problem Solving with C++, second edition, J. Ingber 9 The class Declaration ± A class declaration begins with the key word class followed by an identifier that specifies the name of the new class . ± The body of the class declaration is a statement block that includes: declaration statements for the data members (attributes) prototypes for the member functions (methods) ± Keywords public, protected and private control the accessibility of the attributes and methods. 10/27/2009
Background image of page 3

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

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

This note was uploaded on 10/23/2011 for the course ECE 224 taught by Professor Wangxin during the Spring '09 term at SUNY Stony Brook.

Page1 / 12

Chapter8 - An Introduction To Classes Engineering Problem...

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

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