Estructura De Datos

Páginas: 6 (1402 palabras) Publicado: 25 de febrero de 2013
07GaddA2005 Page 464 Thursday, September 15, 2005 1:12 PM

464

Chapter 7 Introduction to Classes and Objects

Vehicle

Car

Truck

Jet Plane

Figure 7-9

In OOP terminology, the Vehicle class is the base class and the Car, Truck and Jet Plane
classes are derived classes. All of the attributes and behaviors of the Vehicle class are inherited by
the Car, Truck, and Jet Planeclasses. The relationship implies that a car is a vehicle, a truck is a
vehicle and a jet plane is a vehicle.
In addition to inheriting the attributes and behaviors of the base class, derived classes add
their own. For example, the Car class might have attributes and behaviors that set and indicate
the number of passengers it can carry, whether it is a sedan or a coupe, and the type of engine ithas. The truck class might have attributes and behaviors that set and indicate the maximum
amount of weight it can carry, and how many miles it can travel between refuelings. The Jet
Plane class might have attributes and behaviors that set and indicate its altitude and heading.
These added components of the derived classes make them more specialized than the base class.
These three types ofrelationships between classes, access, ownership, and inheritance, are
discussed further in Chapter 11.
Once an enterprise and its operations have been analyzed, a set of programs can be developed to automate some of these operations. For more information on the object-oriented software development process, see Appendix C, An Object-Oriented System Development Primer,
which is located on thestudent CD that accompanies this text.

7.21 Additional Case Studies
The following case study, which contains an application of material introduced in Chapter 7,
can be found on the student CD.

Serendipity Booksellers Software Development Project—Part 7:
Creating a BookData Class
In Part 7 of this ongoing project, you will create and add a class to the project to hold and
manipulateinformation on a single book.

7.22 Review Questions and Exercises
Fill-in-the-Blank and Short Answer
1. Before a structure variable can be created, the structure must be _________.
2. The _________ is the name of the structure type.
3. The variables declared inside a structure declaration are called _________.
4. A(n) _________ is required after the closing brace of a structure declaration. 07GaddA2005 Page 465 Thursday, September 15, 2005 1:12 PM

Review Questions and Exercises

5. In the definition of a structure variable, the _________ is placed before the variable name.
6. The _________ operator allows you to access structure members.
7. An Inventory structure is declared as follows:
struct Inventory
{
int itemCode;
int qtyOnHand;
};
Write a definition statement thecreates an Inventory variable named trivet and initialize it with an initialization list so that its code is 555 and its quantity is 110.
8. A Car structure is declared as follows:
struct Car
{
string make,
model;
int
year;
double cost;
Car(string mk, string md, int y, double c)
{ make = mk; model = md; year = y; cost = c; }
};

Write a definition statement that defines a Car structurevariable initialized with the following information:
Make: Ford
Model: Mustang
Year: 2004
Cost: $25,000
9. Declare a structure named TempScale, with the following members:
fahrenheit: a double
centigrade: a double

Next, declare a structure named Reading, with the following members:
windSpeed: an int
humidity: a double
temperature: a TempScale structure variable

Next, define a Readingstructure variable named today.
Now write statements that will store the following data in the Reading variable.
Wind speed: 37 mph
Humidity: 32%
Fahrenheit temperature: 32 degrees
Centigrade temperature: 0 degrees

465

07GaddA2005 Page 466 Thursday, September 15, 2005 1:12 PM

466

Chapter 7 Introduction to Classes and Objects

10. Write a function called showReading. It should...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Estructura de Datos
  • Estructura De Datos
  • Estructura de datos
  • Estructura de datos
  • Estructura de datos
  • Estructuras de datos
  • Estructura de Datos
  • estructura de datos

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS