Introduction To Classes Chapter 13. 2 Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Lesson 13 Introduction to Classes CS1 Lesson Introduction to Classes1.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
C++ Classes & Data Abstraction
Classes and Objects Systems Programming.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Starting Out with C++: Early Objects 5th Edition
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 16: Classes and Data Abstraction Outline 16.1Introduction.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 7: Introduction to Classes and Objects
Inheritance, Polymorphism, and Virtual Functions
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Classes and Class Members Chapter 3. 3 Public Interface Contract between class and its clients to fulfill certain responsibilities The client is an object.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Procedural and Object-Oriented Programming 13.1.
1 Chapter 13 Introduction to Classes. 2 Topics 12.1 Procedural and Object-Oriented Programming 12.2 Introduction to Classes 12.3 Defining an Instance.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13: Introduction to Classes.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
C++ Lecture 4 Tuesday, 15 July Struct & Classes l Structure in C++ l Classes and data abstraction l Class scope l Constructors and destructors l.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 7: Introduction.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Modified.
Structured Data and Classes Chapter 7. Combining Data into Structures Structure: C++ construct that allows multiple variables to be grouped together Structure.
Inheritance, Polymorphism, And Virtual Functions Chapter 15.
What Is Inheritance? Provides a way to create a new class from an existing class New class can replace or extend functionality of existing class Can be.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 12 Introduction to Classes.
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?
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.
1 Classes and Data Abstraction Chapter What a Class ! ! Specification and implementation Private and public elements Declaring classes data and.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Procedural and Object-Oriented Programming
Chapter 7: Introduction to Classes and Objects
Examples of Classes & Objects
Chapter 7: Introduction to Classes and Objects
Abstract Data Types Programmer-created data types that specify
Inheritance, Polymorphism, and Virtual Functions
Introduction to Classes
Chapter 7: Introduction to Classes and Objects
Chapter 7: Introduction to Classes and Objects
Chapter 7: Introduction to Classes and Objects
Introduction to Object-oriented Programming
Introduction to Classes
Corresponds with Chapter 7
Classes and Data Abstraction
Inheritance, Polymorphism, and Virtual Functions
Classes & Objects: Examples
NAME 436.
Lecture 8 Object Oriented Programming (OOP)
Classes and Objects Systems Programming.
Presentation transcript:

Introduction To Classes Chapter 13

2 Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-oriented programming is based on the data and the functions that operate on it. Objects are instances of ADTs that represent the data and its functions

3 Object-oriented Programming Terminology class: like a struct (allows bundling of related variables), but variables and functions in the class can have different properties than in a struct object: an instance of a class, in the same way that a variable can be an instance of a struct

4 Object-oriented Programming Terminology attributes: members of a class methods or behaviors: member functions of a class

5 Object-oriented Programming Terminology data hiding: restricting access to certain members of an object public interface: members of an object that are available outside of the object. This allows the object to provide access to some data and functions without sharing its internal details and design, and provides some protection from data corruption objects can be general-purpose or application-specific

6 Introduction To Classes Objects are created from a class Format: class { declaration; };

7 Class Example class Square { private: int side; public: void setSide(int s) { side = s; } int getSide() { return side; } };

8 Access Specifiers Used to control access to members of the class public: can be accessed by functions outside of the class private: can only be called by or accessed by functions that are members of the class

9 Defining An Instance Of A Class An object is an instance of a class Defined like structure variables: Square sq1, sq2; Access members using dot operator: sq1.setSide(5); cout << sq2.getSide(); Compiler error if attempt to access private member using dot operator

10 Why Have Private Members? Making data members private provides data protection Data can be accessed only through public functions Public functions define the class’s public interface

11 Defining A Member Function When defining a member function: –Put prototype in class declaration –Define function using class name and scope resolution operator (::) int Square::getSide() { return side; }

12 Constructors Member function that is called when an object is created Called automatically Constructor function name is class name Has no return type

13 Constructor Example class Square { public: Square(); // prototype... }; Square::Square() // heading { side = 1; }

14 Constructors That Accept Arguments Default constructor: constructor that takes no arguments To create an object using the default constructor, use no argument list and no () : Square square1; To create a constructor that takes arguments: –indicate parameters in prototype, definition –provide arguments when object is created: Square square2(12);

15 Constructors That Accept Arguments Constructor may have default arguments: Square(int = 1); // prototype Square::Square(int s) // heading { side = s; }

16 Arrays Of Objects Objects can be the elements of an array: Square lottaSquares[10]; Default constructor for object is used when array is defined Must use initializer list to invoke constructor that takes arguments: Square triSqu[3] = {5,7,11}; More complex initialization if constructor takes > 1 argument

17 Accessing Objects In An Array Objects in an array are referenced using subscripts Member functions are referenced using dot notation: lottaSquares[3].setSide(6); cout << triSqu[i].getSide;