Objects with Functions and Arrays

Slides:



Advertisements
Similar presentations
Constructors and Destructors. Constructor Constructor—what’s this? Constructor—what’s this? method used for initializing objects (of certain class) method.
Advertisements

Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Constructors Initializing New Objects #include “fraction.h” int main() { float x; float y = 6.7; float z(7.2); Fraction.
Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.
CHAPTER 07 Arrays and Vectors (part II). OBJECTIVES In this part you will learn:  To pass arrays to functions.  Basic searching techniques.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
Request Dispatching for Cheap Energy Prices in Cloud Data Centers
SpringerLink Training Kit
Luminosity measurements at Hadron Colliders
BÖnh Parkinson PGS.TS.BS NGUYỄN TRỌNG HƯNG BỆNH VIỆN LÃO KHOA TRUNG ƯƠNG TRƯỜNG ĐẠI HỌC Y HÀ NỘI Bác Ninh 2013.
Nasal Cannula X particulate mask
HF NOISE FILTERS PERFORMANCE
Solving Rubik's Cube By: Etai Nativ.
انتقال حرارت 2 خانم خسرویار.
Summer Student Program First results
MOCLA02 Design of a Compact L-­band Transverse Deflecting Cavity with Arbitrary Polarizations for the SACLA Injector Sep. 14th, 2015 H. Maesaka, T. Asaka,
Fuel cell development program for electric vehicle
10. predavanje Novac i financijski sustav
Interpretations of the Derivative Gottfried Wilhelm Leibniz
Widow Rockfish Assessment
SiW-ECAL Beam Test 2015 Kick-Off meeting
You NEED your book!!! Frequency Distribution
Y V =0 a V =V0 x b b V =0 z
Climate-Energy-Policy Interaction
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Ch48 Statistics by Chtan FYHSKulai
Measure Twice and Cut Once: Robust Dynamic Voltage Scaling for FPGAs
FW 3.4: More Circle Practice
doc.: IEEE <doc#>
Progress on Beam Loading Studies
Solar Astronomy with LOFAR - First Steps
Topic 5: Sequences and Series
Limits on Anomalous WWγ and WWZ Couplings from DØ
Free Cooling Application for Energy Savings at Purdue
Calibration: more background
Chp9: ODE’s Numerical Solns
Gil Kalai Einstein Institute of Mathematics
CMAQv5.2 and Next Generation AQ Model
Gravitation and Cosmology I Introduction to Cosmology
2 INFN Sezione di Napoli, I-80126, Italy
On-Shell Methods in Quantum Field Theory
10.2 Circles Objective: Use and determine the standard and general forms of the equations of a circle. Graph Circles.
Chapter 8 Classes and Objects
Class Operations Pointer and References with class types
Notes Over 10.3 r is the radius radius is 4 units
This pointer, Dynamic memory allocation, Constructors and Destructor
C++ Classes C++ Interlude 1
CSE 143 Lecture 9 References and Linked Nodes reading: 3.3; 16.1
Heterogeneous aggregate datatypes
Pass by Reference, const, readonly, struct
Vectors.
Lesson: 10 – 8 Equations of Circles
Arrays And Functions.
Classes & Objects: Examples
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Constructors and Other Tools
Reference Parameters.
Indirection.
Classes and Objects Part 2 Static Class Members and Arrays of Objects
Objects and Classes Creating Objects and Object Reference Variables
JAVA An Introduction to Java OOP Basics
The Lifecycle of an Object
Object oriented programming (OOP) Lecture No. 6
Copy Assignment CSCE 121.
Class Circle { Float xc, yc, radius;
Chapter Equations of Circles.
Presentation transcript:

Objects with Functions and Arrays

Objects can be Passed Class defines type Can use as type of function or parameter

Returning an Object To return object: Use function: Make desired object Return it Use function:

Passing An Object Passing object copies the object: Main: c1 radius: 5

Passing An Object Passing object copies the object: Main: c radius: 5

Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c1 radius: 5

Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c radius: 5 c1 radius: 5

Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c radius: 10 c1 radius: 5

Copies Generally Bad Copies Main: Are inefficient Prevent functions from modifying an object Main: c1 radius: 5

Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 5

Pass By Reference Unless you need copy, pass by reference Main: c c1 radius: 5

Pass By Reference Unless you need copy, pass by reference Main: c c1 radius: 10

Pass By Reference Unless you need copy, pass by reference Main: c1 radius: 10

Const Reference To prevent function from modifying, use const reference: Link back to original object Make changing it a compile error

Arrays Can have an array of objects CircleList radius: 2 1 2 3 4

Arrays Reference individual objects by index CircleList radius: 4 radius: 4 1 radius: 2 2 3 4

Arrays Arrays initialized with default constructor CircleList radius: 2 1 2 3 4

Arrays This makes 10 circles:

Arrays This makes 10 circles: CircleList radius: 2 1 2 3 4

Arrays This makes 10 circles: CircleList radius: 1 radius: 2 1 radius: 1 1 radius: 2 2 radius: 3 3 radius: 4 4 radius: 5

Arrays Use initialization list to prevent filling with default objects: CircleList radius: 1 1 radius: 2 2 radius: 3 3 radius: 4 4 radius: 5 Call 1-arg constructor to make anonymous object