Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
to Classes
Private Members
Public Members
int Rectangle::setWidth(double w)
{
width = w;
}
"Abstract"
Programmers don’t know the details of the code
Abbreviated "ADT"
Collection of data values together with a set
of basic operations defined for the values
ADT is often "language-independent"
We implement ADT’s in C++ with classes
Other languages implement ADT’s as well
Information Hiding
Details of how operations work are not known to the
"user" of a class
Data Abstraction
Details of how data is manipulated within the
ADT/class are not known to the user
Encapsulation
Bring together data and operations
An object is the encapsulation of data values and
methods
Dr. Khalil Challita 27
Code outside the class must use the class's
public member functions to interact with the
object.
Rectangle(double, double);
Rectangle r;
InventoryItem inventory[40];
InventoryItem inventory[3] =
{ "Hammer", "Wrench", "Pliers" };
inventory[2].setUnits(30);
cout << inventory[2].getUnits();