Lecture 14 Object Oriented Programming Department of Computer

Lecture 14 Object Oriented Programming Department of Computer Engineering 1 Sharif University of Technology

Input and Output – Lecture 4 Introduction What is object oriented programming? Object Abstraction Encapsulation Inheritance Example: Think about an object in real world Mobile Department of Computer Engineering 2 Sharif University of Technology

Input and Output – Lecture 4 Structure • We define struct in previous lecture. • You can encapsulate data about an object in a new data type. • Example: Department of Computer Engineering 3 Sharif University of Technology

Input and Output – Lecture 4 Class • Classes are an expanded concept of data structures – they can contain data members. – they can also contain functions as members. • Function show behavior of an object. Department of Computer Engineering 4 Sharif University of Technology

Input and Output – Lecture 4 Example Department of Computer Engineering 5 Sharif University of Technology

Input and Output – Lecture 4 Example Department of Computer Engineering 6 Sharif University of Technology

Input and Output – Lecture 4 Public and Private attribute/Function • Object can have attribute with private access and public access from outside of view. • Think about mobile. – What is public? – What is private? • So we can have several type of access in OOP. Department of Computer Engineering 7 Sharif University of Technology

Input and Output – Lecture 4 Syntax Department of Computer Engineering 8 Sharif University of Technology

Input and Output – Lecture 4 Define and usage • To define an object from class: <class name> <object name>; • Example • Usage: like structs: –. Operator for normal object. – -> operator for pointer object. Department of Computer Engineering 9 Sharif University of Technology

Input and Output – Lecture 4 Initialization and destroy • We can define two special function: – First: when execute, initialize object. – Second: when execute, destroy object. • Syntax: • Initializer: – A function without data type and same name of class. • Destroyer: – A function without data type, ~same name of class Department of Computer Engineering 10 Sharif University of Technology

Input and Output – Lecture 4 Example Department of Computer Engineering 11 Sharif University of Technology

Input and Output – Lecture 4 Example Department of Computer Engineering 12 Sharif University of Technology

Input and Output – Lecture 4 Department of Computer Engineering 13 Sharif University of Technology

Input and Output – Lecture 4 Input Output in C++ • We can use cin and cout for input/output in c++. • Syntax: – For input: • cin>> variable_name; – For output • Cout<< variable_name; Department of Computer Engineering 14 Sharif University of Technology

Input and Output – Lecture 4 Overloading • Can we define two function with same name? – Yes, but parameter must be different. Department of Computer Engineering 15 Sharif University of Technology

Input and Output – Lecture 4 What is wrong? Department of Computer Engineering 16 Sharif University of Technology
- Slides: 16