Classes. What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide.

Slides:



Advertisements
Similar presentations
Lesson 13 Introduction to Classes CS1 Lesson Introduction to Classes1.
Advertisements

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.
Structure.
C++ Classes & Data Abstraction
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Object Oriented Design and Classes
Function Overloading Having more than one function with the same name. list of argument of a function are called signature of a function. We can have more.
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Functions Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Classes. What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide.
C++ data types. Structs vs. Classes C++ Classes.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Rossella Lau Lecture 5, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 5: Class construction  Encapsulation 
1 Classes Separating interface from implementation Place the class declaration in a header file (.h) to be included (via #include) in each file that uses.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Object Oriented Design and Classes. What is a class? Programming mechanism to support OOD Data and the methods that operate on that data – collectively.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Introduction to Object-Oriented Programming
Objects Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Classes CS 21a: Introduction to Computing I First Semester,
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
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.
Programming Languages and Paradigms Programming C++ Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
J. P. Cohoon and J. W. Davidson © 1997 McGraw-Hill, Inc. Templates Generic functions and classes.
1 Warm-Up Problem Just like with primitive data types (int, double, etc.), we can create arrays of objects. ex: bankAccount employees[100]; Problem: It’s.
Classes: Member Functions and Implementation November 22, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
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.
 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.
CS 106X Classes and Objects
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
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.
Programming Languages and Paradigms C++. C++ program structure  C++ Program: collection of files Header files CPP source files  Files contain class,
93 4/11/98 CSE 143 Class Constructors [Sections ]
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 13: Introduction to Classes.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
OOP in C# - part 1 OOP in C#: –Object Interaction. –Inheritance and Polymorphism (next module). FEN 20121UCN Technology: Computer Science.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Programming Abstractions
Pointer to an Object Can define a pointer to an object:
10.2 Classes Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.
Table of Contents Class Objects.
Introduction to Classes
Introduction to Classes
JAVA CLASSES.
NAME 436.
Classes CS 21a: Introduction to Computing I
Introduction to Object-Oriented Programming
C++ data types.
Classes.
Introduction to Classes and Objects
Presentation transcript:

Classes

What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide structure for organizing programs –Almost like an advanced struct

Syntax class classname { private: … public: … } private only accessible within the class public accessible from anywhere (like with a struct)

Member Functions Typically, data (variables) declared private Functions operate on data –accessor functions – read data, provide access to data but do not change it –update functions – change data –examples from bank account, zoo??? –constructor – builds a new object

Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, coffee machine, grade book The behavior of each kind of object is defined in a class

Writing Classes Typically, two files header and source Header declares member variables, provides function prototypes and bodies of short functions Source provides code for rest of functions When specifying function bodies outside of class definition :: must be used –void BankAccount::withdraw(double amount)

Creating and Using Objects BankAccount b(“Sami Rollins”); //Type Name(constructor parameters); //how would you withdraw funds?

Creating and Using Objects BankAccount b(“Sami Rollins”); Type Name(constructor parameters); //how would you withdraw funds? b.withdraw(300); object_name.method_name(param list);

Constructor BankAccount::BankAccount(double init_balance) class_name(parameter list) Special-case function called when a new object is created Used to initialize member variables –Examples?

Alternative Initialization BankAccount::BankAccount(double init_balance) { balance = init_balance; } BankAccount::BankAccount(double init_balance) : balance(init_balance) { }

Destructor BankAccount::~BankAccount() ~class_name Used if class allocates memory dynamically (uses new) Delete all dynamically declared objects

friend Allow a class to access the private members of another class Operator overloading Closely related classes

STL and Templates STL – Standard Template Library –collection of classes useful for many programs Templates –a class which can hold objects of any kind vector scores(100); vector bank_records(500); Vector – resizable array