Introduction of Programming

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Operator overloading redefine the operations of operators
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
1 CSC241: Object Oriented Programming Lecture No 21.
Introduction to Programming Lecture 39. Copy Constructor.
F UNCTION O VERLOADING Chapter 5 Department of CSE, BUET 1.
Introduction to Programming Lecture 31. Operator Overloading.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
A C LOSER L OOK AT C LASSES 1. A SSIGNING O BJECTS One object can be assigned to another provided that both objects are of the same type. It is not sufficient.
C++ Classes & Data Abstraction
Introduction to Programming Lecture 34. In Today’s Lecture Arrays of objects Arrays of objects Interaction of Arrays with Free Store Interaction of Arrays.
Introduction of Programming Lecture 28. Today’s Lecture How memory allocation is done in How memory allocation is done in C++ C++ How is it different.
Wrap Up and Misc Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Copy Constructors Shallow Copy: –The data members of one object are copied into the data members of another object without taking any dynamic memory pointed.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
Introduction to C++. Overview C++? What are references Object orientation Classes Access specifiers Constructor/destructor Interface-implementation separation.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Chapter 10 Introduction to Classes
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Introduction to Programming Lecture 40. Class Class is a user defined data type.
CIS162AD Constructors Part 2 08_constructors.ppt.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
1 Introduction to Object Oriented Programming Chapter 10.
Classes Sujana Jyothi C++ Workshop Day 2. A class in C++ is an encapsulation of data members and functions that manipulate the data. A class is a mechanism.
Introduction to Programming
Procedural and Object-Oriented Programming
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Object-Oriented Programming Part 1 07_classes.ppt
Default Constructors A default constructor is a constructor that takes no arguments. If you write a class with no constructor at all, C++ will write a.
CMPE 135: Object-Oriented Analysis and Design September 14 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
Class A { public : Int x; A()
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Constructor & Destructor
CS Computer Science IB: Object Oriented Programming
HKCT Java OOP Unit 02 Object Oriented Programming in Java Unit 02 Methods, Classes, and Objects 1.
group work #hifiTeam
Classes and Objects: Encapsulation
Classes and Objects Encapsulation
Contents Introduction to Constructor Characteristics of Constructor
Classes Short Review of Topics already covered Constructor
Department of Computer and Information Science, School of Science, IUPUI CSCI 265 Classes Dale Roberts, Lecturer Computer Science, IUPUI
How Dynamic Memory Works with Memory Diagram
How Classes Work with Memory Diagram
Object Oriented Programming (OOP) Lecture No. 13
Lecture 16 Oct 30, 02.
Object-Oriented Programming (OOP) Lecture No. 22
CS148 Introduction to Programming II
Introduction to Programming
CMSC202 Computer Science II for Majors Lecture 07 – Classes and Objects (Continued) Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
NAME 436.
Object oriented programming (OOP) Lecture No. 6
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
CS 201(Introduction To Programming)
How Dynamic Memory Works with Memory Diagram
CMSC 202 Encapsulation Version 9/10.
CS148 Introduction to Programming II
How Classes Work with Memory Diagram
Constructors & Destructors
Object Oriented Programming (OOP) Lecture No. 12
C++ support for Object-Oriented Programming
Object Oriented Programming
Presentation transcript:

Introduction of Programming Lecture 27

Today’s Lecture Classes and objects Constructors Destructors Member functions Member data

Function Oriented

Object Oriented

Multiple Media

Classes Objects Constructors

Data Hiding Encapsulation

Constructor

Bugs

The majority of programming problems occur because of the use of un-initialized data.

Constructor Name of the constructor is same as the name of the class It does not return any thing, not even void

Example class Date { int month ; int day ; int year ; public: Date ( int day = 1 , int month = 1 , int year = 1 ) } ;

Function Overloading

Rules of function overloading When ever we overload a function, the name of the function remain the same but argument list changes. The argument list can: Either vary in the number of arguments Or vary in the type

Example class Date { public : Date ( int month = 1 , int day = 1 , int year = 1 ) ; private : int month , day , year ; } ;

Example main ( ) { Date mydate ( ) ; }

Example main ( ) { Date mydate ( “01-Jan-2002” ) ; }

Memory Allocation Inside a Constructor

Utility Functions

Friend Functions

Destructor

~

Rules of Destructor Destructors cannot be overloaded Destructors take no arguments They don’t return a value

Example 1 public : class Date { Date ( ) ; Date ( int month , int day , int year ) ; ~Date ( ) ; setMonth ( int month ) ; setDay ( int day ) ; setYear ( int year ) ; int getDay ( ) ; int getMonth ( ) ; int getYear ( ) ; setDate (int day, int month, int year ) ; private: int month , day , year ; } ;

Example 1 main ( ) { Date mydate ( 35 , 13 , 2000 ) ; }

Example 1 main ( ) { Date mydate ; mydate.setDate ( 21 , 01 , 1979 ) ; }

Example 1 main ( ) { Date mydate ( 21 , 01 , 1979 ) ; }

What Happens in Memory Functions setMonth ( int month ) ; setDay ( int day ) ; setYear ( int year ) ; int getMonth ( ) ; int getDay ( ) ; int getYear ( ) ; int month ; int day ; int year ; int month ; int day ; int year ; int month ; int day ; int year ;

Example 2 main ( ) { Date date1 , date2 , date3 ; date1.setMonth ( 3 ) ; date2.setDay ( 23 ) ; }

Destructors ~className ( ) ;

Destructors ~Date :: Date ( ) { cout<< “Object Destroyed” ; }

Constructors Date :: Date ( ) { cout << “Date Object Created” ; }

Constructors without Arguments Date :: Date ( ) { cout<< “Default constructor without arguments called ” ; }

Constructors with Arguments Date :: Date ( int month , int day , int year ) { cout<< “A constructor with paramerters ” ; }