Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.

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

Week 8 Arrays Part 2 String & Pointer
Notes Over 10.3 r is the radius radius is 4 units
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
Const Parameters & In Line Functions 04/15/11. Next Time  Quiz, Monday, 04/18/11  Over 5.2 and 5.3 void functions pass-by-reference  Read 7.1 about.
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 3 More About Classes Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
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.
Духовні символи Голосіївського району
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 8: Advanced Method Concepts. Understanding Parameter Types Mandatory parameter – An argument for it is required in every method call Four types.
Programming II Array of objects. this Using the this Pointer this Objects use the this pointer implicitly or explicitly. – this is – this is used implicitly.
Section 6.2 – The Circle. Write the standard form of each equation. Then graph the equation. center (0, 3) and radius 2 h = 0, k = 3, r = 2.
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.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
CSCI 62 Data Structures Dr. Joshua Stough December 2, 2008.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
CHAPTER 07 Arrays and Vectors (part II). OBJECTIVES In this part you will learn:  To pass arrays to functions.  Basic searching techniques.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Equation of a Circle. Equation Where the center of the circle is (h, k) and r is the radius.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Pointers Call-by-Reference.
  Where the center of the circle is (h, k) and r is the radius. Equation.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
Sadegh Aliakbary Sharif University of Technology Fall 2010.
C++ Classes C++ Interlude 1
Heterogeneous aggregate datatypes
Pass by Reference, const, readonly, struct
Vectors.
Arrays And Functions.
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Objects with Functions and Arrays
Reference Parameters.
Copy Assignment CSCE 121 J. Michael Moore.
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
Andy Wang Object Oriented Programming in C++ COP 3330
Essential Class Operations
Copy Assignment CSCE 121.
Class Circle { Float xc, yc, radius;
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: – 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: c1 radius: 5 c

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

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

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

Copies Generally Bad Copies – 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: c1 radius: 5 c

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

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 0 radius:

Arrays Reference individual objects by index CircleList 0 radius: 4 1 radius:

Arrays Arrays initialized with default constructor CircleList 0 radius:

Arrays This makes 10 circles:

Arrays This makes 10 circles: CircleList 0 radius:

Arrays This makes 10 circles: CircleList 0 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 0 radius: 1 1 radius: 2 2 radius: 3 3 radius: 4 4 radius: 5 Call 1-arg constructor to make anonymous object