1 Lab Session-2 CSIT221 Spring 2003 b Intro to Object Oriented Programming b Practice Problem b Lab Exercise (Demo Required)

Slides:



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

Spring Semester 2013 Lecture 5
Lecture 18: 4/11/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
1 Classes Object-oriented programming: Model the problem as a collection of objects that have certain attributes and interact with one another and/or the.
Wednesday, 12/4/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/4/02  Questions?  Return Test #2  General discussion of HW #05  Introduction.
1 Lab Session-1 CSIT221 Fall 2002 b Refresher slides b Practice Problem b Lab Exercise (Demo Required)
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Classes and Objects Systems Programming.
1 Lab Session-XIV CSIT121 Fall 2000 b Tips for good programming b Complete Lab Exercise 13-B for Using Classes b Work on developing an object oriented.
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-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.
1 Lab Session-2 CSIT 121 Spring 2005 Debugging Tips NiMo’s Varying Rates Lab-2 Exercise.
C++ data types. Structs vs. Classes C++ Classes.
1 Lab Session-5 CSIT221 Spring 2003 Default and Parameterized Constructors Destructors Programming Exercise for building a template based class (demo required)
1 Lab Session-XIII CSIT121 Fall 2000 b Lab Exercise13-A for Handling Files b Lab Exercise 13-B for Using Classes.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
OOP Spring 2006 – Recitation 31 Object Oriented Programming Spring 2006 Recitation 3.
Chapter 11: Classes and Data Abstraction
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
1 Lab Session-3 CSIT221 Fall 2002 b Exception Handling b Lab Exercise (Demo Required)
1 Classes and Objects. 2 Outlines Class Definitions and Objects Member Functions Data Members –Get and Set functions –Constructors.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Constructors and Other Tools Version 1.0 Topics Constructors & Destructors Composition const Parameter Modifier const objects const functions In-line.
CS212: Object Oriented Analysis and Design Lecture 4: Objects and Classes - I.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Chapter 8 Friends and Overloaded Operators. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Friend Function (8.1) Overloading.
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
Learners Support Publications Classes and Objects.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
ECE122 Feb. 22, Any question on Vehicle sample code?
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
1 Introduction to Classes and Objects Chapter 3 Introduction to Classes and Objects Chapter 3.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
C++ Classes and Data Structures Jeffrey S. Childs
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templates.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Chapter 9 Classes: A Deeper Look, Part I Part II.
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.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating 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?
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
CITA 342 Section 1 Object Oriented Programming (OOP)
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.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
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.
TK1924 Program Design & Problem Solving Session 2011/2012
EGR 2261 Unit 13 Classes Read Malik, Chapter 10.
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?
A First C++ Class – a Circle
Classes Object-oriented programming: Example: Bank transactions
Lecture 4-7 Classes and Objects
Learning Objectives Classes Constructors Principles of OOP
Introduction to Classes and Objects
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
COP 3330 Object-oriented Programming in C++
Submitted By : Veenu Saini Lecturer (IT)
Separating Interface from Implementation
C++ data types.
Classes and Objects Systems Programming.
Presentation transcript:

1 Lab Session-2 CSIT221 Spring 2003 b Intro to Object Oriented Programming b Practice Problem b Lab Exercise (Demo Required)

2 Object Oriented Programming b We start our lab today with an introductory session for object oriented programming b OOP involves following steps: Definition of class in a header file including prototypes of member functions and private dataDefinition of class in a header file including prototypes of member functions and private data Implementation of public member functionsImplementation of public member functions Testing with a driver programTesting with a driver program

3 Practice Problem b Define a class cat that includes private data members weight and color of the cat and some public member functions b Write a driver program that tests out the class by defining two objects that belong to this class

4 Building Class Definition b The class definition will consist of public and private sections. By default, everything is private. However, we should explicitly label the sections as such to avoid confusion b The function prototypes and the data items are included in the definition of a class. However, data items cannot be initialized here. Initialization takes place in a constructor

5 Constructor b Once the class definition is completed, Start building up the source code for all the member functions in the implementation file b The first one to be written is the constructor. The default constructor accepts no arguments and executes by default when an object of this class is declared

6 How Many Files? b Class definition in a header file (e.g. cat.h) b Class implementation in a C++ source code file (e.g. cat_imp.cpp) b Class driver code in a C++ source code file (e.g. cat_test.cpp) b All these files are part of your project

7 Be Careful b Use the keyword void in the implementation file before starting to implement any void member function b If parameters are being passed to a member function, specify their data types and local names b The order of inserting files may influence the number of compiling errors

8 Lab Exercise (Demo required on 2/11 for Sec-1 and 2/13 for Sec-2) b Model a vending machine as an object. Develop a class definition for a vending machine that has an initial quantity of ten bottles each for 5 different soft drinks and 95 cents change and zero dollars in bills. As the users operate the machine, they insert one dollar bills and/or coins to buy the soft drinks. The machine can display and change the number of bottles of each type and its total cash with the help of member functions. The driver program cannot alter any private data. All private data must be handled by the member functions only. Show a complete demo with the following scenario

9 User Scenario b Display total number of all types of soft drinks and cash at hand b Let the user buy two bottles b Display the balance cash and bottles b Let the user buy three bottles b Display the balance cash and bottles b Let the vendor take away the cash and fill up the machine b Display the balance cash and bottles