Definition Class In C++, the class is the construct primarily used to create objects.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

PHP functions What are Functions? A function structure:
Operator overloading redefine the operations of operators
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
C++ Classes & Data Abstraction
C/c++ 4 Yeting Ge.
Written by: Dr. JJ Shepherd
CS-240 Operator Overloading Dick Steflik. Operator Overloading What is it? –assigning a new meaning to a specific operator when used in the context of.
1 Objects and Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in Objects Reading for this Lecture:
C++ data types. Structs vs. Classes C++ Classes.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Operator Overloading CS 308 – Data Structures What is operator overloading? Changing the definition of an operator so it can be applied on the objects.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Review of C++ Programming Part II Sheng-Fang Huang.
More About Classes Chapter Instance And Static Members instance variable: a member variable in a class. Each object has its own copy. static variable:
Case Study - Fractions Timothy Budd Oregon State University.
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.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Chapter 10 Introduction to Classes
Overview of Previous Lesson(s) Over View .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows.  It.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
CMSC 202 Lesson 7 Classes I. Warmup  Add the correct parameter list and return type to the following function: (hint: all the information you need is.
 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.
Classes Definition A class is a data type whose variables are objects Object – a variable that has member functions as well the ability to hold.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Chapter 11 Friends and Overloaded Operators. Introduction to function equal // Date.h #ifndef _DATE_H_ #define _DATE_H_ class CDate { public: CDate();
CSC 143F 1 CSC 143 Constructors Revisited. CSC 143F 2 Constructors In C++, the constructor is a special function automatically called when a class instance.
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?
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
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 © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
CS Class 19 Today  Practice with classes Announcements  Turn in algorithm for Project 5 in class today  Project 5 due 11/11 by midnight – .
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Destructors The destructor fulfills the opposite functionality. It is automatically called when an object.
CIS162AD Constructors Part 2 08_constructors.ppt.
Individual Testing, Big-O, C++ Bryce Boe 2013/07/16 CS24, Summer 2013 C.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 14: More About Classes.
1 Introduction to Object Oriented Programming Chapter 10.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
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 Class 19 Chapter 13 – Creating a class definition.
C++ Features Function Overloading Default Functions arguments Thinking about objects – relationship to classes Types of member functions Constructor and.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
OOP Details Constructors, copies, access. Initialize Fields are not initialized by default:
CMSC 202 Lesson 9 Classes III. Warmup Using the following part of a class, implement the Sharpen() method, it removes 1 from the length: class Pencil.
Chapter 2 Objects and Classes
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?
Overloading Operator MySting Example
Abstract Data Types Programmer-created data types that specify
Chapter 5 Classes.
This technique is Called “Divide and Conquer”.
group work #hifiTeam
Function Overloading C++ allows us to define functions that have the same name but different sets of parameters This capability can be used to define similar.
Classes & Objects: Examples
CMSC 202 Lesson 7 Classes I.
Learning Objectives Classes Constructors Principles of OOP
Introduction to Programming
CS31 Discussion 1D Winter18: week 6
Class: Special Topics Overloading (methods) Copy Constructors
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
C++ data types.
Constructors & Destructors
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
Presentation transcript:

Definition Class In C++, the class is the construct primarily used to create objects.

Definition OBJECT Objects are instances of a class.

Definition Encapsulation

Definition Constructor A constructor is a member function that is automatically called when a class object is created. Default constructor A constructor that has no parameters.

Definition Friend of classes A friend is a function that is not a member of a class, but has access to the private members of the class.

Definition Memberwise Assignment The = operator may be used to assign one object to another or to initialize the object with another object’s data. By default, each member of one object is copied to its counterpart in the other object.

Definition Copy Constructor A copy constructor is a special constructor that is called whenever a new object is created and initialized with the data of another object of the same class Ex: Car (Car a) { myYear = a.getYear(); myMake = a.getMake(); }

Which of the following shows the correct use of the scope resolution operator in a member function definition? InvItem:: void setOnHand (int units) Void InvItem:: setOnHand (int units)

Assuming that soap is an instance of an Inventory class, which of the following is a valid call to the setOnHand member function Inventory soap; setOnHand(20); soap::setOnHand(20); soap.setOnHand(20); Inventory.setOnHand(20);

A private class member function can be called by Any other function Only public functions in the same class Only private functions the same class Any function in the same class

Assume a map class has a member variable named position that is an instance of the Location class. The Location class has a private member variable named latitude and a public member function called getLatitude. How would you return the value stored in latitude return Location.latitude(); return Location.getLatitude(); return position.latitude();

Assume there is a class named Pet Assume there is a class named Pet. Write the prototype for a member of Pet that overloads the = operator. Pet Pet :: operator= (Pet);

What is the output for the following: try { …. throw (99); … } catch (int e) { cout << “The exception caught is : “ << e << endl; } cout << “ The code ran without exception “ << endl;

What is the output for the following: try { …. throw “ Bad input”; … } catch (int e) { cout << “The exception caught is : “ << e << endl; } cout << “ The code ran without exception “ << endl;

What is the output for the following: try { …. throw “ Bad input”; … } catch (int e) { cout << “The exception caught is : “ << e << endl; } catch (string se) { cout << The exception caught is “ << se << endl;} cout << “ The code ran without exception “ << endl;

What is the output for the following: try { …. throw (99); throw “ Bad input”; … } catch (int e) { cout << “The exception caught is : “ << e << endl; } catch (string se) { cout << The exception caught is “ << se << endl;} cout << “ The code ran without exception “ << endl;

Complete the following code skeleton to declare a class called DATE Complete the following code skeleton to declare a class called DATE. The class should contain member variables and functions to store and retrieve the month, day, and year components of a date Class Date {private: public: }