1 3/2/05CS250 Introduction to Computer Science II Composition and friend Functions.

Slides:



Advertisements
Similar presentations
C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
Advertisements

CS 112 Introduction to Programming
Structure.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 102 Computer Programming II (Lab:
Introduction to Programming Lecture 31. Operator Overloading.
Using Classes to Store Data Computer Science 2 Gerb.
C++ Classes & Data Abstraction
 2003 Prentice Hall, Inc. All rights reserved. ECE 2552 Dr. S. Kozaitis Summer Summary of Topics Related to Classes Class definition Defining member.
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
CS 112 Intro to Computer Science II Sami Rollins Fall 2006.
Structures/Classes CS 308 – Data Structures. What is a structure? It is an aggregate data type built using elements of other types. Declaring a structure.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
CS 106 Introduction to Computer Science I 03 / 26 / 2008 Instructor: Michael Eckmann.
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
CS 112 Intro to Computer Science II Sami Rollins Spring 2007.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
CS150 Introduction to Computer Science 1
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
CS0007: Introduction to Computer Programming Introduction to Arrays.
Review of C++ Programming Part II Sheng-Fang Huang.
CS212: Object Oriented Analysis and Design Lecture 5: Classes and Objects - II.
Access Control Under Inheritance tMyn1 Access Control Under Inheritance The private data members of a base class are also members of the derived class,
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
CS442: ADVANCED PROGRAMMING USING JAVA Lab 6: Classes and objects Computer Science Department.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 2/21/05CS250 Introduction to Computer Science II Destructors, Get and Set, and Default Memberwise Assignment.
Building java programs, chapter 3 Parameters, Methods and Objects.
Object-Oriented Programming in C++ Lecture 4 Constants References Operator overloading.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
1 10/15/04CS150 Introduction to Computer Science 1 Reading from and Writing to Files Part 2.
Friend Function. 2 Any data which is declared private inside a class is not accessible from outside the class. A non-member function cannot have an access.
1 2/2/05CS250 Introduction to Computer Science II Pointers.
1 Introduction to Object Oriented Programming Chapter 10.
1 11/12/04CS150 Introduction to Computer Science 1 More Arrays.
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Access Functions and Friend Functions
CISC181 Introduction to Computer Science Dr
CS150 Introduction to Computer Science 1
CS212: Object Oriented Analysis and Design
CS250 Introduction to Computer Science II
Sequences 9/18/ :20 PM C201: Linked List.
CS150 Introduction to Computer Science 1
Introduction to Programming
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
Let’s all Repeat Together
CS150 Introduction to Computer Science 1
Arithmetic Operations
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS148 Introduction to Programming II
CS150 Introduction to Computer Science 1
Life is Full of Alternatives
CS150 Introduction to Computer Science 1
Separating Interface from Implementation
CS150 Introduction to Computer Science 1
Presentation transcript:

1 3/2/05CS250 Introduction to Computer Science II Composition and friend Functions

2 3/2/05CS250 Introduction to Computer Science II Composition  All the data members we have seen so far have been simple variables (int, double, etc)  It is possible to have objects of classes as data members of other classes  This is called composition

3 3/2/05CS250 Introduction to Computer Science II Example  Create a class Employee that will contain the employee name and the time the employee starts work and the time the employee finishes work  The time should be represented as objects of class Time

4 3/2/05CS250 Introduction to Computer Science II Friend Functions  Only the member functions of a class have direct access to the private data members of the class  friend functions are friends of the class that are defined outside of the class but still have access to private data members

5 3/2/05CS250 Introduction to Computer Science II friend Functions  The function prototype is placed in the class, preceded by the keyword friend  The function definition can be written anywhere without the class name (class::)  The function is able to directly access the private data members

6 3/2/05CS250 Introduction to Computer Science II Summary  Today we covered o Composition o Friend Functions  Completed pages