#include <iostream.h>

Slides:



Advertisements
Similar presentations
2000 Prentice Hall, Inc. All rights reserved Oggetti const e funzioni membro const 2. Composizione: oggetti come membri di classi 3. Funzioni friend.
Advertisements

 2003 Prentice Hall, Inc. All rights reserved. ECE 2552 Dr. S. Kozaitis Summer Summary of Topics Related to Classes Class definition Defining member.
1 CMSC 202 More C++ Classes. 2 Announcements Project 1 due midnight Sunday 2/25/01 Quiz #2 this week Exam 1 Wednesday/Thursday Project 2 out Monday March.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 17 - C++ Classes: Part II Outline 17.1Introduction 17.2 const (Constant) Objects and const Member.
Object-Based Programming Outline Introduction Implementing a Time Abstract Data Type with a Class Class Scope Controlling Access to Members Creating Packages.
Outline 1 Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü ++ Bilişim Enstitüsü.
More on Objects CS 102 More, more, more on Objects.
 2002 Prentice Hall. All rights reserved. 1 Object Oriented Programming Revisited Object Orientation –Classes Encapsulate data –Attributes Encapsulate.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 6: Classes and Data Abstraction Outline 6.1 Introduction 6.2 Structure Definitions 6.3 Accessing.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 16: Classes and Data Abstraction Outline 16.1Introduction 16.2Implementing a Time Abstract Data.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
Classes and Objects. const (Constant) Objects and const Member Functions Principle of least privilege –Only give objects permissions they need, no more.
1 Review (Week2) - Control Structures C++ has only seven control structures: –Sequence structure Programs executed sequentially by default –Selection structures.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 7: Classes Part II Outline 7.1 Introduction 7.2 const (Constant) Objects and const Member Functions.
 2002 Prentice Hall. All rights reserved. Chapter 8 – Object-Based Programming Outline 8.1 Introduction 8.2 Implementing a Time Abstract Data Type with.
 2003 Prentice Hall, Inc. All rights reserved Introduction Object-oriented programming (OOP) –Encapsulates data (attributes) and functions (behavior)
Classi - Esempi1 // SalesPerson class definition // Member functions defined in salesp.cpp #ifndef SALESP_H #define SALESP_H class SalesPerson { public:
1 Classes and Data Abstraction Andrew Davison Noppadon Kamolvilassatian Department of Computer Engineering Prince of Songkla University.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 4 - Classes Jan 27,
The Clock Example. 1. The Clock Example 2 3 public class Clock { // instance variables private int hr; private int min; private int sec; // constructors:
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 8: Operator Overloading Outline 8.1Introduction 8.2Const (Constant) Objects and const Member.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python Xiang Lian The University of Texas – Pan.
1 Classes and Data Abstraction Part II Initializing Class Objects: Constructors Constructors  Initialize data members  Same name as class 
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 6: Classes and Data Abstraction Outline 6.1Introduction 6.2Structure Definitions 6.3Accessing.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 – Object-Based Programming Outline 8.1 Introduction 8.2 Implementing a Time Abstract Data Type.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 7: Classes Part II Outline 7.1 Introduction 7.2 const (Constant) Objects and const Member Functions.
1 const and this Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
 2000 Prentice Hall, Inc. All rights reserved const (Constant) Objects and const Member Functions Principle of least privilege –Only give objects.
 2000 Prentice Hall, Inc. All rights reserved. 1 Outline 7.1Introduction 7.2 const (Constant) Objects and const Member Functions 7.3Composition: Objects.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 3: Classes May 24,
Class 4 (L34) u Constructors u Default Constructor u Example of Default Constructors u Destructors u Constructors Are Called in Global Scope u Constructors.
Classes and Data Abstraction Andrew Davison Noppadon Kamolvilassatian Department of Computer Engineering Prince of Songkla University 1
C++ Lecture 5 Monday, 18 July Chapter 7 Classes, continued l const objects and const member functions l Composition: objects as members of classes.
 2000 Prentice Hall, Inc. All rights reserved. 1 Outline 7.1Introduction 7.2 const (Constant) Objects and const Member Functions 7.3Composition: Objects.
1 2/21/05CS250 Introduction to Computer Science II Destructors, Get and Set, and Default Memberwise Assignment.
1 CMSC 202 ADTs and C++ Classes. 2 Announcements Project 1 due Sunday February 25 th at midnight – don’t be late! Notes and clarifications for Project.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 20 November 10, 2009.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 7.1Introduction 7.2const (Constant) Objects and const Member Functions 7.3Composition: Objects.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 7: Classes Part II Outline 7.1 Introduction 7.2 const (Constant) Objects and const Member Functions.
 2000 Prentice Hall, Inc. All rights reserved. NHTI CP 107 Fall 2001 M. Saleem Yusuf Introduction Object-oriented programming (OOP) –Objects Encapsulates.
 2003 Prentice Hall, Inc. All rights reserved. ECE 2552 Dr. Këpuska Summer 2004 from Dr. S. Kozaitis Spring 2003 slides 1 Summary of Chapter 6: Classes.
 2000 Prentice Hall, Inc. All rights reserved. 1 Outline 7.1Introduction 7.2 const (Constant) Objects and const Member Functions 7.3Composition: Objects.
Object Access m1.write(44); m2.write(m2.read() +1); std::cout
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 3 Jan 20, 2004.
CompSci 230 S Programming Techniques
Chapter 16: Classes and Data Abstraction
Lecture 5: Classes (continued) Feb 1, 2005
Chapter 7 – Object-Based Programming
Chapter 17 - C++ Classes: Part II
Chapter 7: Classes Part II
Chapter 7: Classes Part II
Lecture 4: Classes (continued) June 14, 2004
Object Oriented Programming using c++ Submitted by :- MADHU MADHAN Lecturer in Computer Engg. G .P. MEHAM (ROHTAK)
בניית מחלקות.
Classes: A Deeper Look Outline
Chapter 6: Classes and Data Abstraction
Classes and Data Abstraction
Chapter 6: Classes and Data Abstraction
Chapter 7: Classes Part II
Capitolo 7: Classes Part II
Default Arguments.
7.4 friend Functions and friend Classes
Object-oriented programming (OOP)
Chapter 6: Classes and Data Abstraction
CISC181 Introduction to Computer Science Dr
Chapter 7: Classes Part II
Chapter 6: Classes and Data Abstraction
Chapter 7: Classes (Part II)
Chapter 7: Classes Part II
Presentation transcript:

#include <iostream.h> class Time { public: Time( int=0, int=0, int=0 ); Time& setTime( int, int, int ); Time& setHour( int ); Time& setMinute( int ); Time& setSecond( int ); int getHour() const; int getMinute() const; int getSecond() const; void printMilitary() const; void printStandard() const; private: int hour; int minute; int second; };

Time::Time( int hr, int min, int sec ) { setTime( hr, min, sec ); } Time& Time::setTime( int h, int m, int s ) { setHour( h ); setMinute( m ); setSecond( s ); return *this; Time& Time::setHour( int h ) { hour = ( h>=0 && h<24 ) ? h : 0; Time& Time::setMinute( int m ) { minute = ( m>=0 && m<60 )? m : 0;

Time& Time::setSecond( int s ) { second = ( s>=0 && s<60 ) ? s : 0; return *this; } int Time::getHour() const { return hour; int Time::getMinute() const { return minute; int Time::getSecond() const { return second; void Time::printMilitary() const { // defined as before } void Time::printStandard() const { // defined as before }

int main() { Time t; t.setHour( 18 ).setMinute( 30 ).setSecond( 22 ); cout<<“Military time: “; t.printMilitary(); cout<<“\nStandard time: “; t.printStandard(); cout<<“\n\nNew standard time: “; t.setTime( 20, 20, 20 ).printStandard(); cout<<endl; return 0; } Output: Military time: 18:30 Standard time: 6:30:22 PM New standard time: 8:20:20 PM