A.A. 2006/2007 Laurea di Ingegneria Informatica. Fondamenti di C++ Horstmann Capitolo 3: Oggetti Revisione Prof. M. Angelaccio

Documenti analoghi
Corso di Algoritmi e Strutture Dati con Laboratorio. The JCF(continua): L interfaccia Map

Question 1: introduction to computer programming

Exam of ELECTRONIC SYSTEMS June 17 th, 2014 Prof. Marco Sampietro

A.S. 2011/2012. Circuito semaforico da incrocio. Corso di Elettronica. Dipartimento di Elettrotecnica

Downloading and Installing Software Socio TIS

Introduction. The Structure of a Compiler

SRT064 BTH SRT051 BTH SRT052 BTH

Canti Popolari delle Isole Eolie e di Altri Luoghi di Sicilia (Italian Edition)

Fiori di campo. Conoscere, riconoscere e osservare tutte le specie di fiori selvatici più note

Capitolo 6 - Array. Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

Capitolo 5 - Funzioni

I membri e le restrizioni di accesso

Copyright 2012 Binary System srl Piacenza ITALIA Via Coppalati, 6 P.IVA info@binarysystem.eu

Capitolo 7 I puntatori in C

A review of some Java basics. Java pass-by-value and List<> references

100 consigli per vivere bene (Italian Edition)

Gocce d'anima (Italian Edition)

Introduzione alle classi 2

Famiglia Spirituale nel XXI secolo (La) (Italian Edition)

Ammissibilità di co.co.co. e AdR in H2020. Laura Fulci Dirigente Area Ricerca Politecnico di Torino

Linguaggi Corso M-Z - Laurea in Ingegneria Informatica A.A I/O, thread, socket in Java

Guida utente User Manual made in Italy Rev0

SAP UniEmens 2.3. Rollout

L'università in Italia (Farsi un'idea) (Italian Edition)

Resources and Tools for Bibliographic Research. Search & Find Using Library Catalogues

Const, friend, static,this

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

Quando mi collego ad alcuni servizi hosting ricevo un messaggio relativo al certificato di protezione del sito SSL, come mai?

WELCOME. Go to the link of the official University of Palermo web site Click on the box on the right side Login unico

Write Event 10 in Metrology Event Log

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

Stringhe. Prof. Lorenzo Porcelli

Stored Procedures. Massimo Mecella Dipartimento di Ingegneria informatica automatica e gestionale Antonio Ruberti Sapienza Università di Roma

Marketing non Convenzionale: Viral, Guerrilla e prospettive future (Italian Edition)

Introduzione alla storia dell intelligenza artificiale e della robotica

Il paradigma OO e le Classi

NON VENTILATED DC MOTORS

I CAMBIAMENTI PROTOTESTO-METATESTO, UN MODELLO CON ESEMPI BASATI SULLA TRADUZIONE DELLA BIBBIA (ITALIAN EDITION) BY BRUNO OSIMO

GstarCAD 2010 Features

Risvolti patologici e allocazione rischio. Avv. Gennaro Mazzuoccolo Partner Banking Norton Rose Fulbright Studio Legale Roma 14 novembre 2013

ALLATTARE Un gesto d'amore (Educazione pre e perinatale) (Italian Edition)

Technical Guidelines GON % Italian production. sports car oriented

ENGINE COMPONENT DESIGN Cap. 7 AIAA AIRCRAFT ENGINE DESIGN R03-23/10/2013

EML-16 EML-16. Pulses concentrator. Concentratore impulsi MODBUS COMMUNICATION PROTOCOL PROTOCOLLO DI COMUNICAZIONE MODBUS

Zeroshell come client OpenVPN

NATIONAL SPORT SCHOOL

Scheda Allarmi Alarm Board MiniHi

Allocazione dinamica della memoria

Stereomicroscopi zoom da laboratorio

LOG CARD ISTRUZIONI DI COMPILAZIONE - FILLING INSTRUCTION. Campo Box SEZIONE 1 SECTION 1. Denominazione del Part Number 1 Part number nomenclature

Corso di Laurea in INFORMATICA

Il Futuro. The Future Tense

CUSCINETTI A RULLINI NEEDLE ROLLER BEARINGS

INSTALLAZIONE INSTALLATION

1. Domanda di certificazione da riportare su carta intestata del fabbricante che richiede la certificazione / Certification request To report on

Omeopatia: Guida medica ai rimedi omeopatici (Italian Edition)

7 dolci favole della buona notte per un'intera settimana (Italian Edition)

LA SACRA BIBBIA: OSSIA L'ANTICO E IL NUOVO TESTAMENTO VERSIONE RIVEDUTA BY GIOVANNI LUZZI

Introduzione a Matlab

Estratto dal Cap. 8 di: Statistics for Marketing and Consumer Research, M. Mazzocchi, ed. SAGE, 2008.

Ingegneria del Software. Business Object Technology

Lezione 4. Costruttori

07/02/2011. Elementi di Biomeccanica Statica, Cinetica, Esercizi sull analisi delle forze. Mechanics. Statics constant state of motion

RenderCAD S.r.l. Formazione

Definizione e principi. Venezia, 20 febbraio 2014


Radio Frequency Identification Systems

Progetto E-CLIL. Anno scolastico

SEMINARIO ASSIOM FOREX US ELECTIONS

Il sistema dei tipi in ML. cenni

SVITOL. brand identity guidelines. Indice. Il logo The logo. Interazione con altri elementi grafici Use with other graphic elements


6.5 RNA Secondary Structure. 18 novembre 2014

UNIVERSITÀ DI PISA FACOLTÀ DI INGEGNERIA

Analisi spazio-temporale di social media per l identicazione di eventi

Laboratorio di Informatica Lezione 1

BJC462. Bayan BJC473. Also available. 15 Treble registers 8 Chin registers Hand made reeds Cassotto. 7 Chin registers Hand made reeds Cassotto

Calcolo efficienza energetica secondo Regolamento UE n. 327/2011 Energy efficiency calculation according to EU Regulation no.

smalto anticalcare e antibatterico Antibacterial and limestone glaze

Il Piccolo Principe siamo noi: Adattamento teatrale per la scuola primaria (ABW. Antoine de Saint- Exupery) (Volume 1) (Italian Edition)

Le avventure di Robinho (Kids) (Italian Edition)

Maps. a.k.a, associative array, map, or dictionary

FEROX. brand identity guidelines. Indice. Il logo The logo. Interazione con altri elementi grafici Use with other graphic elements

La provincia di Palermo

INTRODUZIONE AD OMNET++

Introduzione al Semantic Web Linguaggi per la rappresentazione di ontologie. L idea del Semantic Web.

Algoritmi e strutture di dati 2

Programma II B Liceo Scientifico

OOP: Object Oriented Programming

Musica e Dislessia: Aprire nuove porte (Italian Edition)

Come scrivere il CV in inglese. (Italian Edition)

#GirlBoss: Come ho creato un impero commerciale partendo dal nulla (Italian Edition)

sottobasi per valvole a spola

Lo sniffer. questo sconosciuto! Corso di Reti di Calcolatori Architetture e Servizi A.A. 2010/11. Introduzione allo sniffing TCP

INFORMAZIONE AGLI UTENTI DI APPARECCHIATURE DOMESTICHE O PROFESSIONALI

Succhi di frutta e verdura con la centrifuga (Italian Edition)

my WORLD is brand identity guidelines Indice Il logo The logo Interazione con altri elementi grafici Use with other graphic elements

100 mm - 107,5 mm PCB Width: in in (100 mm mm)

I DIRITTI DEI CONVIVENTI PDF

Fondamenti di Teoria delle Basi di Dati

Transcript:

A.A. 2006/2007 Laurea di Ingegneria Informatica Fondamenti di C++ Horstmann Capitolo 3: Oggetti Revisione Prof. M. Angelaccio

Obbiettivi Acquisire familiarità con la nozione di oggetto Apprendere le proprietà delle classi guida usate nel libro/corso Definire oggetti con valori iniziali Concetto di funzione elemento e notazione dot Modificare e interrogare lo stato di un oggetto Semplici esempi applicativi

Creazione di oggetti Un oggetto è un valore che può essere creato, manipolato e memorizzato Ogni oggetto di C++ appartiene ad una classe Una classe è un tipo di dato definito dal programmatore e non primitivo in C++ (come ad esempio int o double)

Sintassi 3.1 Object Construction Class_name(construction parameters); Example: Time(19, 0, 0); Purpose: Construct a new object for use in an expression.

Sintassi 3.2 Object Variable Definition Class_name variable_name(construction parameters); Example: Time homework_due(19, 0 0); Purpose: Define a new object variable and supply parameter values for initialization.

Oggetti vs Tipi di dato primitivi Oggetti Tipo Astratto Definizione con sintassi (..) simile a funzione Uso con notazione dot Tipi di dato primitivi Tipo primitivo Definizione con dichiarazione Uso con operatori standard

Constructing Objects (Time class) To use the Time class we must include the file that contains its definition: #include "ccc_time.cpp" We use " " instead of < > because the file is not a standard header. The name stands for Computing Concepts with C++ Essentials.

Constructing Objects Creating any object is called construction. We can construct an object just like we create any variable. Time sometime; We initialize an object by passing construction parameters when the object is created. The Time class uses military time. Time day_end(23, 59, 59); /* the last second of the day */

Constructing Objects (cont.) Creating objects without parameters is called default construction. No parameters means not parenthesis! The Time class creates an object with the current time. Time now; /* the time this object is created */ Time later(); /* NO! */ An object can be created anytime by supplying the class name with (or without) parameters. sometime = Time(12, 5, 18); /* we already declared sometime */

Using Objects A function applied to an object with the dot notation is called a member function. The Time class has several member functions used to find the state of the object: now.get_seconds(); /* returns the seconds value of now */ now.get_minutes(); /* returns the minutes value of now */ now.get_hours(); /* returns the hours value of now */

Esempi con Oggetti Time Esempio 1 (add seconds) Visualizzare l ora corrispondente alla formula 9:00:00 + 1000 sec. (il risultato atteso è 9:16:40) Esempio 2 (seconds left) Calcolare il numero dei secondi rimanenti fino alla mezzanotte

Using Objects (time1.cpp)

Using Objects The Time class does not have any member functions used to set the state of the object to avoid abuse: now.set_hours(2); /* No! Not a supported member function */ now.set_hours(9999); /* Doesn't make sense */ The Time class does provide other member functions to facilitate other actions: now.add_seconds(1000); /* Changes now to move by 1000 seconds */ now.seconds_from(day_end); /* Computes number of seconds between now and day_end */

Using Objects (time2.cpp)

Real-Life Objects Object-oriented programming allows us to easily model entities from real life. As an example, the text provides a simple Employee class:

Esempio di Classe Employee All employees have names and salaries which are set at construction. Employee harry("hacker, Harry", 45000.00); Both attributes can be queried. cout << "Name: " << harry.get_name() << "\n"; cout << "Salary: " << harry.get_salary() << "\n"; Onlysalarycan beset. harry.set_salary(new_salary);

Class Diagram of an Employee Costruttore Employee - name : string - salary : double + Employee() + get_name() : string + get_salary() : double + set_salary() : void Costanti Metodi

Using Objects (employee.cpp)