1 Lab Session-5 CSIT221 Spring 2003 Default and Parameterized Constructors Destructors Programming Exercise for building a template based class (demo required)

Slides:



Advertisements
Similar presentations
Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Advertisements

Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
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.
Web Application Development Slides Credit Umair Javed LUMS.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
1 Lab Session-1 CSIT221 Fall 2002 b Refresher slides b Practice Problem b Lab Exercise (Demo Required)
Chapter 14: Overloading and Templates
1 Session-16 CSIT 121 Spring 2006 Demo for switch-case due now Demo for switch-case due now String comparison String comparison Slide 23; sample case.
1 Lab Session-2 CSIT221 Spring 2003 b Intro to Object Oriented Programming b Practice Problem b Lab Exercise (Demo Required)
1 Lab Session-9 CSIT221 Fall 2002 Lab Exercise Based on operator overloading (Demo Required)
1 Lab Session-1 CSIT221 Spring 2003 b Group Programming Challenge b Individual Lab Exercise (Demo Required)
1 Lab Session-XII CSIT121 Fall 2000 b Namespaces b Will This Program Compile ? b Master of Deceit b Lab Exercise 12-A b First Taste of Classes b Lab Exercise.
1 Lab Session-6 CSIT221 Fall 2002 A Note About Destructors Using Pointers Implementing Stacks.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Chapter 11: Classes and Data Abstraction
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
Abstract Data Types and Encapsulation Concepts
 2006 Pearson Education, Inc. All rights reserved Generics.
1 Class Constructors a class constructor is a member function whose purpose is to initialize the private data members of a class object the name of a constructor.
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Review of C++ Programming Part II Sheng-Fang Huang.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Chapter 8 More Object Concepts
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved. Note: C How to Program, Chapter 22 is a copy of C++ How to Program Chapter.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
OOP IN PHP `Object Oriented Programming in any language is the use of objects to represent functional parts of an application and real life entities. For.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Exam 3 Preview.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templates.
CLASSES : A DEEPER LOOK Chapter 9 Part I 1. 2 OBJECTIVES In this chapter you will learn: How to use a preprocessor wrapper to prevent multiple definition.
Chapter 9 Classes: A Deeper Look, Part I Part II.
1 Using Templates COSC 1567 C++ Programming Lecture 10.
Programming Fundamentals1 Chapter 8 OBJECT MANIPULATION - INHERITANCE.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CONSTRUCTOR AND DESTRUCTORS
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 12: Classes and Data Abstraction.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
1 Introduction to Object Oriented Programming Chapter 10.
CONSTRUCTOR AND DESTRUCTOR. Topics to be discussed……………….. 1. Introduction Introduction 2. FeaturesFeatures 3. Types of ConstructorTypes of Constructor.
ECE 264 Object-Oriented Software Development
Java Generics. Lecture Objectives To understand the objective of generic programming To be able to implement generic classes and methods To know the limitations.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
TK1924 Program Design & Problem Solving Session 2011/2012
Copy Constructor / Destructors Stacks and Queues
Class: Special Topics Copy Constructors Static members Friends this
group work #hifiTeam
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
CS148 Introduction to Programming II
Classes and Objects Systems Programming.
Introduction to Classes and Objects
Presentation transcript:

1 Lab Session-5 CSIT221 Spring 2003 Default and Parameterized Constructors Destructors Programming Exercise for building a template based class (demo required)

2 Constructors Please do not attempt anything within the constructor except for initializing the private data There are two types of constructors: Default (Takes no arguments) Parameterized(Accepts the user data through actual parameters passed)

3 Parameterized The parameterized constructor would initialize the private data with the actual parameters passed at the time an object is defined in the client code As an example, we modify the stack class to introduce a parameterized constructor Code Walk-Through

4 Destructors Destructors perform the opposite function of constructors A destructor is a member functions of a class and it has the same name as the class Destructor runs automatically when an object belonging to its class is destroyed. It ensures “clean up” operations Code Walk-Through

5 Programming Exercise (Demo Required Sec1 3/11 Sec2 3/13 ) Implement the HW2 class as a template based generic class. Define an object in the client code that builds a list of customer names and another object that builds a corresponding list of amounts stored as floating point numbers. Display the names and amounts sorted in descending order by the amounts. Following is an example display from your program:

6 Example Display PayGo Mart: Following is the list of our customers, sorted by amounts spent in last one year: NameAmount Dave4500 Nell3501 Chris3500 Jacob2800 Alice2100

7 Hints for using templates Make sure that you use the line template Above the class definition and the header of every member function Declare the array with the data type template_name Initialize the actual data types “string” and “double” when defining objects for the demo