Propedéutico de Programación



Similar documents
Propedéutico de Programación

DIPLOMADO DE JAVA - OCA

Schema XML_PGE.xsd. element GrupoInformes. attribute XML_PGE.xsd unqualified qualified

Propiedades del esquema del Documento XML de envío:

Ch 7-1. Object-Oriented Programming and Classes

Glossary of Object Oriented Terms

Sales Management Main Features

Spanish 8695/S Paper 3 Speaking Test Teacher s Booklet Time allowed Instructions one not not Information exactly as they are printed not 8695/S

Problem 1 (1.5 points)

Benedictine College Financial Aid

Dictionary (catálogo)

CISC 181 Project 3 Designing Classes for Bank Accounts

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

AV-002: Professional Web Component Development with Java

Class 16: Function Parameters and Polymorphism

Apéndice C: Código Fuente del Programa DBConnection.java

El Dorado Union High School District Educational Services

Ranking de Universidades de Grupo of Eight (Go8)

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

New Server Installation. Revisión: 13/10/2014

A. Before you read the text, answer the following question: What should a family do before starting to look for a new home?

Manejo Basico del Servidor de Aplicaciones WebSphere Application Server 6.0

Clock Commands on Cisco IOS XR Software

Classes and Pointers: Some Peculiarities (cont d.)

ATTORNEY GENERAL LAW ENFORCEMENT DIRECTIVE NO APPENDIX A

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

ATTORNEY GENERAL LAW ENFORCEMENT DIRECTIVE NO APPENDIX A POTENTIAL LIABILITY WARNING - N.J.S.A. 39: , FORM AND GUIDELINES 1

SUBCHAPTER A. AUTOMOBILE INSURANCE DIVISION 3. MISCELLANEOUS INTERPRETATIONS 28 TAC 5.204

How To Know If An Ipod Is Compatible With An Ipo Or Ipo (Sanyo)

Goals for This Lecture:

How To Write A Report On A Drug Company

Work Instruction (Instruccion de Trabajo) Wistron InfoComm (Texas) Corp.

AP SPANISH LITERATURE 2009 SCORING GUIDELINES

Stacks. Linear data structures

Visión general de la integración con asanetwork

Object Oriented Software Design II

Física Computacional Conceptos de programación.

For the next three questions, consider the class declaration: Member function implementations put inline to save space.

Introduction to Object-Oriented Programming

C++ Programming Language

OFFICE OF COMMON INTEREST COMMUNITY OMBUDSMAN CIC#: DEPARTMENT OF JUSTICE

LOS ANGELES UNIFIED SCHOOL DISTRICT REFERENCE GUIDE

Course Title: Software Development

An Incomplete C++ Primer. University of Wyoming MA 5310

SUBCHAPTER A. AUTOMOBILE INSURANCE DIVISION 3. MISCELLANEOUS INTERPRETATIONS 28 TAC 5.204

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Técnicas Avanzadas de Inteligencia Artificial Dpt. Lenguajes y Sistemas Informáticos. FISS. UPV-EHU

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Inteligencia Artificial Representación del conocimiento a través de restricciones (continuación)

SUMMER WORK AP SPANISH LANGUAGE & CULTURE Bienvenidos a la clase de Español AP!

New words to remember

INTELIGENCIA DE NEGOCIO CON SQL SERVER

LOS ANGELES UNIFIED SCHOOL DISTRICT Policy Bulletin

Q E U S E T S I T ON O S N

EE 1130 Freshman Eng. Design for Electrical and Computer Eng.

Chapter 5 Functions. Introducing Functions

FAMILY INDEPENDENCE ADMINISTRATION Matthew Brune, Executive Deputy Commissioner

ENVIRONMENT: Collaborative Learning Environment

New words to remember

Summary. Basic comparator operation. (Equality) 2009 Pearson Education, Upper Saddle River, NJ All Rights Reserved

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

OMEGA SOFT WF RISKEVAL

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Beth Troutman, Ph.D., ABPP Marta M. Shinn, Ph.D. Kami Guzman, MS, LMHC, LMHP Kelli Slagle Radermacher, MS, LMHC, LMHP Rebecca Whitlock, LMHC NCC, IADC

Chapter 10 Physical Development from One to Three

Equity and Fixed Income

C++ Support for Abstract Data Types

COSC 181 Foundations of Computer Programming. Class 6

AP SPANISH LANGUAGE 2011 PRESENTATIONAL WRITING SCORING GUIDELINES

CHALLENGE TO INSTRUCTIONAL AND LIBRARY MATERIAL

queja:

Prepárate. BT Computer ABCs for Women in Transition

The named boxes in Spanish of the form are included in italics inside parentheses. MINISTERIO DE ECONOMÍA Y COMPETITIVIDAD

Monitoreo de Bases de Datos

COSTA DE CANYAMEL - MALLORCA

N3458: Simple Database Integration in C++11

APS ELEMENTARY SCHOOL PLANNING SURVEY

Coding Standard for Java

Design Thinking Workshop. Building an Exceptional Customer Experience. Dulce Velázquez Agosto 22, 2014

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

ECCAIRS 5 Instalación

Computer Programming I

Copyright TeachMe.com 242ea 1

Spanish for Professionals Law Enforcement

The C Programming Language course syllabus associate level

COMPUTACIÓN ORIENTADA A SERVICIOS (PRÁCTICA) Dr. Mauricio Arroqui EXA-UNICEN

I M M I G R A N T WORKERS HEALTH & SAFETY

Telling and asking for the time.

7.1 Our Current Model

PATIENT INFORMATION. Patient Name/Nombre

A mysterious meeting. (Un encuentro misterioso) Spanish. List of characters. (Personajes) Khalid, the birthday boy (Khalid, el cumpleañero)

Bucle for_in. Sintaxis: Bucles for_in con listas. def assessment(grade_list): """ Computes the average of a list of grades

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

LOS ANGELES UNIFIED SCHOOL DISTRICT REFERENCE GUIDE

Visual C Tutorial

Digital Fundamentals

A Roadmap for Parents. PARENT EDUCATION SEMINAR March 26, 2014

Same Day Surgery Guide...2. New Hanover Regional Medical Center Operating Room Schedule...2. Surgery Scheduling Process...2. Pre-Admission Testing...

Financial Aid Information

Pragmatic Type Interoperability

Transcription:

Propedéutico de Programación Coordinación de Ciencias Computacionales 4/12 Material preparado por: Dra. Pilar Gómez Gil

Chapter 14 Object-Oriented Software Development (continuación) Dale/Weems

Constructor Rules for Derived Classes At run time, the base class constructor is implicitly called first, before the body of the derived class s constructor executes If the base class constructor requires parameters, they must be passed by the derived class s constructor

Implementation of ExtTime Default Constructor ExtTime::ExtTime ( ) // Default Constructor // Postcondition: // hrs == 0 && mins == 0 && secs == 0 // (via an implicit call to base class default // constructor) // && zone == EST { zone = EST; }

Implementation of Another ExtTime Class Constructor ExtTime::ExtTime ( /* in */ int inithrs, /* in */ int initmins, /* in */ int initsecs, /* in */ ZoneType initzone) : Time (inithrs, initmins, initsecs) // Constructor initializer // Pre: 0 <= inithrs <= 23 && 0 <= initmins <= 59 // 0 <= initsecs <= 59 && initzone is assigned // Post: zone == initzone && Time set by base // class constructor { zone = initzone; }

Implementation of ExtTime::Set function void ExtTime::Set ( /* in */ int inithrs, /* in */ int initmins, /* in */ int initsecs, /* in */ ZoneType initzone) // Pre: 0 <= inithrs <= 23 && 0 <= initmins <= 59 // 0 <= initsecs <= 59 && initzone is assigned // Post: zone == timezone && Time set by base // class function { Time::Set (hours, minutes, seconds); zone = timezone; }

Implementation of ExtTime::Write Function void ExtTime::Write ( ) const // Postcondition: // Time has been output in form HH:MM:SS ZZZ // where ZZZ is the time zone abbreviation { static string zonestring[8] = { EST, CST, MST, PST, EDT, CDT, MDT, PDT }; Time::Write (); cout << << zonestring[zone]; }

Ver ExtTime.h ExtTime.cpp

Responsibilities Responsibilities are operations implemented as C++ functions Action responsibilities are operations that perform an action Knowledge responsibilities are operations that return the state of private data variables

What responsibilities are Missing? The Time class needs int Hours() int Minutes() int Seconds() The ExtTime class needs ZoneType zone()

Composition (or Containment) Composition (containment) is a mechanism by which the internal data (the state) of one class includes an object of another class

Ver Time.h Name.h

Entry.cpp Ver

Example: An Entry Object #include "Time.h" #include "Name.h" #include <string> class Entry { public: string NameStr() const; // Returns a string made up of first name and last name string TimeStr() const; // Returns a string made up of hour, colon, minutes Entry(); // Default constructor Entry( ) // Parameterized constructor private: Name name; Time time; }

Inicializador de Constructores Un inicializador de constructores aparece entre la lista de parámetros y el cuerpo de un constructor, cuando se usa herencia o composición. Su misión es pasar argumentos a otro constructor de las otras clases involucradas. Si se trata de herencia, se especifica el nombre de la clase base Si se trata de composición, se especifica el nombre del objeto

Ejemplo composición: Entry::Entry( /* in */ string firstname, /* in */ string middlename, /* in */ string lastname, /* in */ int inithours, /* in */ int initminutes, /* in */ int initseconds ) // Constructor initializers : name(firstname, middlename, lastname), time(inithours, initminutes, initseconds) // Parameterized constructor // Postcondtion: // Entry object has been constructed with firstname, // middlename, and lastname as arguments to Name // parameterized constructor; inithours, initminutes, // and initseconds as arguments to Time parameterized // constructor { }

Ejemplo herencia: ExtTime::ExtTime( /* in */ int inithrs, /* in */ int initmins, /* in */ int initsecs, /* in */ ZoneType initzone ) : Time(initHrs, initmins, initsecs) // Constructor // Precondition: // 0 <= inithrs <= 23 && 0 <= initmins <= 59 // && 0 <= initsecs <= 59 && initzone is assigned // Postcondition: // Time is set according to inithrs, initmins, and initsecs // (via call to base class constructor) // && zone == initzone { zone = initzone; }

Order in Which Constructors are Executed Given a class X, if X is a derived class its base class constructor is executed first next, constructors for member objects (if any) are executed (using their own default constructors if none is specified) finally, the body of X s constructor is executed

In C++... When the type of a formal parameter is a parent class, the argument used can be the same type as the formal parameter or, any descendant class type

Static Binding Static binding is the compile-time determination of which function to call for a particular object based on the type of the formal parameter(s) When pass-by-value is used, static binding occurs

Static Binding Is Based on Formal Parameter Type void Print ( /* in */ Time sometime) { cout << Time is ; sometime.write ( ); cout << endl; } CLIENT CODE OUTPUT Tipo by-value Time starttime(8, 30, 0); ExtTime endtime(10,45,0,cst); Print ( starttime); Time is 08:30:00 Print ( endtime); Time is 10:45:00

Dynamic Binding Dynamic binding is the run-time determination of which function to call for a particular object of a descendant class based on the type of the argument Declaring a member function to be virtual instructs the compiler to generate code that guarantees dynamic binding

Virtual Member Function // Specification file ( time.h ) class Time { public:... virtual void Write () const; // Forces dynamic binding... private: int hrs; int mins; int secs; };

Dynamic binding requires pass-byreference void Print ( /* in */ Time& sometime) { cout << Time is ; sometime.write ( ); cout << endl; } CLIENT CODE OUTPUT Time starttime ( 8, 30, 0); ExtTime endtime (10,45,0,CST); Print ( starttime); Time is 08:30:00 Print ( endtime); Time is 10:45:00 CST

Using virtual functions in C++ Dynamic binding requires pass-by-reference when passing a class object to a function In the declaration for a virtual function, the word virtual appears only in the base class If a base class declares a virtual function, it must implement that function, even if the body is empty A derived class is not required to re-implement a virtual function; if it does not, the base class version is used

Operación Polimórfica Es una operación que tiene múltiples significados, dependiendo del tipo de objeto a la cual es atada en tiempo de ejecución

Object-Oriented Design Identify the Objects and Operations Determine the relationship among objects Design and Implement the driver

Implementation of the Design Choose a suitable data representation Built-in data type Existing ADT Create a new ADT Create algorithms for the abstract operations Top-down design is often the best technique to create algorithms for the function tasks