data structures

¡Supera tus tareas y exámenes ahora con Quizwiz!

module

.cpp file. sometimes module consists of two files: header (.h) and .cpp file main never needs or has a header

abstract data type operator categories

1) constructors 2) transformers (mutators) 3) observers 4) iterators

data types needed in a program but not provided by the programming language.

1. class type 2. client

parameter passing

C++ supports two types of formal parameters: 1) value parameters 2) reference parameters a value parameter is a formal parameter that receives a copy of the contents of the corresponding actual parameter (argument) -- because it is a copy of the actual parameter, the actual parameter CANNOT be changed by the function to which it is a parameter. a reference parameter is a formal parameter that receives the location (memory address) of the corresponding actual parameter. the function CAN change the contents of the actual parameter. By default in C++, arrays are passed by reference (can change), and nonarray parameters are passed by value (can't change).

class parts

Classes are written in two parts 1. the specification 2. the implementation the specification describes the resources that the class can supply to the program. RESOURCES: might include the value of the current time and operations to set the current time. in a class, the resources include data and operations on the data. separation of specifications from implementation gives opportunity to concentrate efforts on the design of a class without worrying about implementation.

one-dimensional array (implementation level)

In C++, array deceleration statement includes characteristics: 1. number of elements (Number) 2. base address, location in memory (Base) 3. number of memory locations needed for each element (SizeOfElement) ARRAY DESCRIPTOR or DOPE VECTOR: table where array characteristics information are stored. C++ accessing function that gives position of element in one-dimensional array: ADDRESS(Index)=Base+Offset of the element at position Index Array is a structured data type, unlike record which is unstructured but whose implementation view is structured.

unstructured composite type

a collection of components that are not organized with respect to one another

data structure

a collection of data elements whose organization is characterized by accessing operations that are used to store and retrieve the individual data elements; the implementation of the composite data members in an abstract data type.

record - logical level

a composite data type made up of a finite collection of not necessarily homogeneous elements called members or fields. access through a a set of named member or field selectors.

composite data types

a data type that allows a collection of values to be associated with an object of that type. come in two forms: 1) structured and 2) unstructured

abstract data type (ADT)

a data type whose properties (domain and operations) are specified independently of any particular implementation.

one-dimensional array (application level)

a one-dimensional array is the natural structure for the storage of lists of like data elements. e.g. grocery lists, price lists,

function

a single group of code lines that perform a particular task. 1. heading at the top. 1.b function name as second word 2. body starts with opening brace { 3. closing brace } has optional ;

implementation level

a specific representation of the structure to hold the data items, and the coding of the operations in a programming language (if the operations are not already provided by the language) (how are books catalogued, things the patron doesn't see or need to know)

one-dimensional array (logical level)

a structured composite data type made up of a finite, fixed-size collection of ordered homogeneous elements to which direct access is available. FINITE: the last element is identifiable. FIXED: size of array known in advance, doesn't mean values are meaningful. ORDERED: first element, second element, so on. relative positions are ordered, not necessarily the values stored. HOMOGENEOUS stored values must all be same type DIRECT ACCESS: can access any element directly, without first accessing the preceding elements. If language did not have predefined arrays, we would have to specify at least three operations: CreateArray, Store, Retrieve in C++ array has syntax to provide a primitive constructor for creating arrays: 1. type of element 2. name of the array 3. number of elements, array size in C++, arrays can only be reference parameters: - not possible to pass an array by value.

application (or user) level

a way of modeling real-life data in a specific context; also called the problem domain. (e.g. library of congress, austin city library)

class specification

although class specification and implementation can reside in same file, the two parts of a class are usually separated into two files. specification goes into a header (h. extension) implementation goes into a file with the same name but .cpp extension PRIVATE: data members are marked private, which means that although they are visible. cannot be accessed by client code. can only be access by code in the implementation file. PUBLIC: member functions of the class are public.

logical (or abstract) level

an abstract view of the data values (the domain) and the set of operations to manipulate them (e.g. what is a library, what services?)

ADT - iterator

an operation that allows us to process all components in a data structure sequentially. operations that print items in a list, only defined on structured data types

ADT - constructor

an operation that creates a new instance (object) of an abstract data type

structured composite type

an organized collection of components in which the organization determines the method used to access individual data components

class type

an unstructured type that encapsulates a fixed number of data components with the functions that manipulate them; the predefined operations on an instance of a class are whole assignment and component access. the data members and the code that manipulate them are bound together. the class forces encapsulation.

block or compound statement

any set of lines with a brace before and after

nonarray parameter as a reference parameter

append an ampersand (&) to the right of the type name on the formal parameter list. EXAMPLE #1 void AdjustForInflation(CarType$ car, float perCent) { car.price = car.price*perCent+car.price; } EXAMPLE #2 bool LateModel(CarType car, int date) { return car.year >= date; } 1. The function AdjustForInflation changes the price data member of the formal parameter car, so car must be a reference parameter. 2. The function LateModel examines car without changing it, so car should be a value parameter.

syntax of a record

declare the struct ---------------------- struct CarType { int year; char maker[10]; float price; ]; ........................................ declare specific record variable ---------------------- CarType myCar; /* mycar is the struct variable . is a period price is the member selector /* an array variable myCar.maker[2] indicates the third character in the array

scope rules in C++

govern who knows what, where, and when. Three main categories of scope exist for an identifier 1. class scope: identifiers declared within a class declaration. all identifiers declared within a class are local to the class 2. local scope: identifier declared within a block (statements enclosed within {}. the scope of a formal parameter is the same as the scope of a local variable declared in the outermost block of the function body (local scope). scope of local identifier includes all statements following the declaration of the identifier. the scope of an identifier does not include any nested block that contains a locally declared identifier with the same name (local identifiers have precedence) 3. global scope: identifier declared outside all functions and classes. name of a function that is not a member of a class has global scope. once a global function called, and subsequent function can call it (global scope). when a function declares a local identifier with the same name as a global identifier, local identifier takes precedence (local scope)

an accessing function

is a rule that tells the compiler and run-time system where an individual element is located within the data structure.

main

main is a function that is required in all C++ programs.

two-dimensional array (implementation level)

mapping of two indexes to a particular memory cell.

records in C++

not all languages have records (FORTRAN). In C++, both structs and classes behave as records.

class implementation

only member functions of a class can access the data members. need to associate class name with the function definitions. - insert class name before the function name, separated by the scope resolution operator (::).

ADT - observer

operation that allows us to observe the state of one or more of the data values without changing them. Examples 1) predicates (ask if a certain property is true) - boolean function 2) accessor or selector (returns a copy of an item in the object) - function that returns a copy of last item into the structure is an example 3) summary (returns information about object as a whole) - a function that returns the number of items in a structure

ADT - transformer

operations that change the state of one or more of the data values (inserting, deleting, or making an object empty)

composite types in C++

records (structs), classes, and arrays. classes and structs are logically unstructured; arrays are structured.

two-dimensional array (logical level)

similar to one-dimensional logical level. a composite data type made up of a finite, fixed-size collection of homogeneous elements ordered in two dimensions. a natural way to represent data that is logically viewed as a table with columns and rows. abstract picture of this structure is a grid with rows and columns. its component selector is direct access: a pair of indexes specifies the desired element by giving its relative position in each dimension.

two-dimensional array (application level)

table with rows and columns

characteristics of a record

the declaration statements in a program tell the compiler how many cells are needed to represent the record. the name of the record then is associated with the characteristics of the record: 1) location in memory of the first cell in the record, called the base address of the record 2) a table containing the number of memory locations needed for each member of the record. a record occupies a block of consecutive cells in memory. the base address of the record is the address of the first member in the record. a reference to a record member causes the compiler to examine the characteristics table to determine the member's offset from the beginning of the record. compiler generates the member's address by adding the offset to the base. the record is a nonstructured data type, yet the component selector depends on the relative positions of the members of the record. a record is a structured data type if viewed from the implementation perspective, however, from the use's view it is unstructured. the user accesses the members by name, not position. So if CarType is defined as follows: struct CarType { char make[10]; float price; int year; }; the code that manipulates instances of CarType would not actually change.

data abstraction

the separation of a data type's logical properties from its implementation

data encapsulation

the separation of the representation of data from the applications that use the data at a logical level; a programming language feature that enforces information hiding

memory assigned by accessing function

the unit of memory that is assigned to hold a value is machine dependent. memory configuration is a consideration for the compiler writer. to be as general as possible, we will use the generic term cell to represent a location in memory rather than "word" or "byte". ------------------------------- IBM 370 Architecture byte | byte | byte | byte | byte | byte half word | half word | half word word | double word CDC word ------------------------------- location in memory of the first cell in the record, called the base address of the record a table containing the number of memory locations needed for each member of the record a record occupies a block of consecutive cells in memory.

record - implementation level

two things must be done to implement a built-in composite data type: 1. memory cells must be reserved for the data 2. the accessing function must be determined.

record - application level

useful for modeling objects that have a number of characteristics. allows us to collect various types of data about an object and to refer to the whole object by a single name.


Conjuntos de estudio relacionados

PSY 207: Chapter 15- Physical and Cognitive Development Middle Adulthood

View Set

Class 2 - Thermoregulation, Perfusion, Oxygenation, & Comfort

View Set

Blood Transfussions and Lab Values

View Set

Nutrition 251 Exam 4 Study Guide

View Set

Topic 3 Review: Challenges in the Late 1800s

View Set

FFM - Week 7 (Market Efficiency)

View Set

Maternity- Obstetrical Assessment

View Set

Chapter 2: Financial Statements, Taxes, and Cash Flow

View Set