Classes and Objects. Types and Classes. Example. Object Oriented Programming
|
|
- Hilary Poole
- 6 years ago
- Views:
Transcription
1 Classes and Objects Types and Classes Chapter 6 Object Oriented program development. Read this Chapter 7 Classes Read this Chapter 8 More About Classes Some sections will be assigned later Chapter 9 Inheritance. Not covered in this course Standard Types Classes, Objects Object Oriented Programming Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring Example Object Oriented Programming class Time int hour; int minute; int second; ; int main() Time t1; t1.hour = 10; t1.minute = 30; t1.second = 25; Object-oriented Programming (OOP) encapsulates data (attributes) and functions (behavior) into packages called classes; the data and functions of a class are intimitely tied together. A class is like a blueprint. Out of a blueprint, a builder can build a house. Out of a class, a programmer can create an object. One blueprint can be reused many times to make many houses. One class can be reused many times to make many objects of the same class. return 0; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring
2 Object Oriented Programming Example I Information Hiding Interfaces Classes User/Programmer defined types Data Members Functions class Temperature void set(double newdegrees, char newscale); double degrees; char scale; ; Temperature t1; Temperature t2; t1.set(53.2, F ); t2.set(57.4, F ); cout << "Today it is: " << t1.degrees << t1.scale; cout << "Tomorrow will be: " << t2.degrees << t2.scale; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring Example I (continued) Example II void Temperature::set(double newdegrees, char newscale) class Bicycle char getcolor(); int numberofspeeds(); void set(int thespeeds, char thecolor); int speeds; char color; ; Bicycle mybike; Bicycle yourbike; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring
3 Example II: Methods Example III char Bicycle::getColor() char Bicycle::numberOfSpeeds() void Bicycle::set(int thespeeds, char thecolor) #include <iostream> using std::cout; using std::endl; class Time Time(); void settime( int, int, int ); void printmilitary(); void printstandard(); int hour; // 0-23 int minute; // 0-59 int second; // 0-59 ; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring Example: Constructor Example: Methods Time::Time() hour = 0; minute = 0; second = 0; void Time::setTime( int h, int m, int s ) if ( h >= 0 && h < 24 ) hour = h; hour = 0; if ( m >= 0 && m < 24 ) minute = m; minute = 0; if ( h >= 0 && h < 24 ) second = s; second = 0; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring
4 Example: Methods Example: Methods void Time::printMilitary() if (hour < 10) cout << "0" << hour << ":" cout << hour << ":"; if (minute < 10) cout << "0" << minute << ":" cout << minute; void Time::printStandard() if ( hour == 0 hour == 12 ) cout << 12; cout << hour % 12; cout << ":"; if ( minute < 10? "0" : "" ) cout "0"; cout << minute; cout << ":"; if ( second < 10 ) cout "0"; cout : << second; if ( hour < 12 ) cout << " AM"; cout << " PM"; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring Driver int main() Time t; cout << "The initial military time is "; cout << "\nthe initial std time is "; t.settime( 13, 27, 6 ); cout << "\n\nmilitary time now is "; cout << "\nstandard time now is is "; t.settime( 99, 99, 99 ); cout << "\n\nafter invalid settings:" << "\nmilitary time: "; cout << "\nstandard time: "; cout << endl; return 0; Program Devel/Intro Alg Lang CS501b/275 Spring Exercise class Automobile void setprice(double newprice); void setprofit(double newprofit); double getprice(); double price: double profit; double getprofit();; Automobile hyundai, jaguar; hyundai.price = ; jaguar.setprice( ); double aprice, aprofit; aprice = jaguar.getprice(); aprofit = jaguar.getprofit(); aprofit = hyundai.getprofit(); hyundai = jaguar; Program Devel/Intro Alg Lang CS501b/275 Spring
5 Separating Inferface from Implementation Separating Interface from Implementation (cont) One of the fundamental principles of good software engineering is to separate interface from implementation. this makes it easier to modify programs. As far as clients of a class are concerned, changes in the class implementation do not affect the client as long as the class interface priginally provided to the client is unchanged (the class functionality could be expanded beyond the original interface). myclass.h file #include "myclass.h" Put method definitions in source file myclass.cpp Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring time.h time.cpp #include <iostream> using std::cout; using std::endl; class Time Time(); void settime( int, int, int ); void printmilitary(); void printstandard(); int hour; // 0-23 int minute; // 0-59 int second; // 0-59 ; Time::Time() hour = 0; minute = 0; second = 0; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring
6 time.cpp (cont) time.cpp void Time::setTime( int h, int m, int s ) if ( h >= 0 && h < 24 ) hour = h; hour = 0; if ( m >= 0 && m < 24 ) minute = m; minute = 0; if ( h >= 0 && h < 24 ) second = s; second = 0; void Time::printMilitary() if (hour < 10) cout << "0" << hour << ":" cout << hour << ":"; if (minute < 10) cout << "0" << minute << ":" cout << minute; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring time.cpp void Time::printStandard() if ( hour == 0 hour == 12 ) cout << 12; cout << hour % 12; cout << ":"; if ( minute < 10? "0" : "" ) cout "0"; cout << minute; cout << ":"; if ( second < 10 ) cout "0"; cout : << second; if ( hour < 12 ) cout << " AM"; cout << " PM"; Program Devel/Intro Alg Lang CS501b/275 Spring testtime.cpp #include <iostream> #include "time.h" int main() Time t; cout << "The initial military time is "; cout << "\nthe initial std time is "; t.settime( 13, 27, 6 ); cout << "\n\nmilitary time now is "; cout << "\nstandard time now is is "; t.settime( 99, 99, 99 ); cout << "\n\nafter invalid settings:" << "\nmilitary time: "; cout << "\nstandard time: "; cout << endl; return 0; Program Devel/Intro Alg Lang CS501b/275 Spring
7 Compiling Constructors g++ time.cpp test.cpp g++ -o test time.cpp test.cpp g++ -c time.cpp g++ -o test test.cpp time.o When a class object is created, its members can be initialized by that class constructor function. A constructor is a class member function with the same name as the class. The programmer provides the constructor, which is then invoked automatically each time an object of that class is created (instantiated). Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring Constructor Overloading Find the error Time(int, int, int); Time::Time(int h, int m, int s) settime(h, m, s); Time t1; Time t2(3, 20, 55); The following is a partial definition of class Time: class Time // function prototypes int hour = 0; int minute = 0; int second = 0; ; Program Devel/Intro Alg Lang CS501b/275 Spring Program Devel/Intro Alg Lang CS501b/275 Spring
8 Find the error Assume the following is declared in class Employee: int Employee(int, char[]); Program Devel/Intro Alg Lang CS501b/275 Spring
Classes and Data Abstraction. Topic 5
Classes and Data Abstraction Topic 5 Classes Class User Defined Data Type Object Variable Data Value Operations Member Functions Object Variable Data Value Operations Member Functions Object Variable Data
More informationClasses: A Deeper Look
Classes: A Deeper Look 1 Introduction Implementing a Time Abstract Data Type with a class Class Scope and Accessing Class Members Separating Interface from Implementation Controlling Access to Members
More informationClasses and Data Abstraction
6 Classes and Data Abstraction Objectives To understand the software engineering concepts of encapsulation and data hiding. To understand the notions of data abstraction and abstract data types (ADTs).
More information57:017, Computers in Engineering C++ Classes
57:017, Computers in Engineering C++ Classes Copyright 1992 2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Introduction Object-oriented programming (OOP) Encapsulates
More informationIntroduction to Programming session 24
Introduction to Programming session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel sslides Sharif Universityof Technology Outlines Introduction
More informationChapter 16: Classes and Data Abstraction
Chapter 16: Classes and Data Abstraction 16.1 Introduction 16.2 Implementing a Time Abstract Data Type with a Class 16.3 Class Scope and Accessing Class Members 16.4 Separating Interface from Implementation
More informationW8.1 Continuing Classes friend Functions and friend Classes Using the this Pointer Cascading Function Calls
1 W8.1 Continuing Classes friend Functions and friend Classes Using the this Pointer Cascading Function Calls 2 7.4 friend Functions and friend Classes friend function and friend classes Can access private
More informationclarity. In the first form, the access specifier public : is needed to {
Structure Time CSC 211 Intermediate Programming Classes in C++ // Create a structure, set its members, and print it. struct Time // structure definition int hour; // 0-23 int minute; // 0-59 int second;
More informationCOMPUTER PROGRAMMING (ECE 431) TUTORIAL 9
COMPUTER PROGRAMMING (ECE 431) TUTORIAL 9 1. What is object oriented programming (OOP)? How is it differs from the traditional programming? 2. What is a class? How a class is different from a structure?
More informationPreview 9/20/2017. Object Oriented Programing with C++ Object Oriented Programing with C++ Object Oriented Programing with C++
Preview Object Oriented Programming with C++ Class Members Inline Functions vs. Regular Functions Constructors & Destructors Initializing class Objects with Constructors C++ Programming Language C Programming
More informationComputer Programming with C++ (21)
Computer Programming with C++ (21) Zhang, Xinyu Department of Computer Science and Engineering, Ewha Womans University, Seoul, Korea zhangxy@ewha.ac.kr Classes (III) Chapter 9.7 Chapter 10 Outline Destructors
More informationMore C++ Classes. Systems Programming
More C++ Classes Systems Programming C++ Classes Preprocessor Wrapper Time Class Case Study Class Scope and Assessing Class Members Using handles to access class members Access and Utility Functions Destructors
More informationClasses and Data Abstraction. Topic 5
Classes and Data Abstraction Topic 5 Introduction Object-oriented programming (OOP) Encapsulates data (attributes) and functions (behavior) into packages called classes The data and functions of a class
More informationCSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.
Name: Print legibly! Section: COMPUTER SCIENCE 261 PROGRAMMING CONCEPTS EXAM 2 VERSION 1 Fall 2014 150 Points Absolutely no electronic devices may be used during this exam. 1. No cell phones, computers,
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 5: Classes September 14, 2004 Structure Definitions 2 Structures Aggregate data types built using elements of other types
More informationChapter 6: Classes and Data Abstraction
Chapter 6: Classes and Data Abstraction 1 6.1 Introduction 6.2 Structure Definitions 6.3 Accessing Structure Members 6.4 Implementing a User-Defined Type Time with a struct 6.5 Implementing a Time Abstract
More informationA Deeper Look at Classes
A Deeper Look at Classes Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by
More informationPointer Assignments. CISC181 Introduction to Computer Science. Dr. McCoy. Lecture 18 October 29, The new Operator
CISC11 Introduction to Computer Science Dr. McCoy Lecture 1 October 29, 2009 Pointer Assignments Pointer variables can be "assigned": int *p1, *p2; p2 = p1; Assigns one pointer to another "Make p2 point
More informationCSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.
Name: Print legibly! Section: COMPUTER SCIENCE 261 PROGRAMMING CONCEPTS EXAM 2 VERSION 1 Fall 2014 150 Points Absolutely no electronic devices may be used during this exam. 1. No cell phones, computers,
More informationDeitel Dive-Into Series: Dive-Into Cygwin and GNU C++
1 Deitel Dive-Into Series: Dive-Into Cygwin and GNU C++ Objectives To be able to use Cygwin, a UNIX simulator. To be able to use a text editor to create C++ source files To be able to use GCC to compile
More informationChapter 9 Classes : A Deeper Look, Part 1
Chapter 9 Classes : A Deeper Look, Part 1 C++, How to Program Deitel & Deitel Fall 2016 CISC1600 Yanjun Li 1 Time Class Case Study Time Class Definition: private data members: int hour; int minute; int
More informationAngela Chih-Wei Tang Visual Communications Lab Department of Communication Engineering National Central University JhongLi, Taiwan.
C++ Classes: Part II Angela Chih-Wei Tang Visual Communications Lab Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 17.2 const (Constant) Objects and
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 3 Jan 20, 2004 Quiz 1 2 Average: about 3.8 More than half obtained: 4 + Highest is 8 Need more work/practice! Quiz 1
More information1 // Fig. 6.13: time2.cpp 2 // Member-function definitions for class Time. 3 #include <iostream> Outline. 4 5 using std::cout; 6 7 #include <iomanip>
CISC11 Introduction to Computer Science Dr. McCoy Lecture 20 November, 2009. Using Default Arguments with Constructors Constructors Can specify default arguments Default constructors Defaults all arguments
More informationChapter 17 - C++ Classes: Part II
Chapter 17 - C++ Classes: Part II 17.1 Introduction 17.2 const (Constant) Objects and const Member Functions 17.3 Composition: Objects as Members of Classes 17.4 friend Functions and friend Classes 17.5
More informationOBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II
KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Chapter 17 - C++ Classes: Part II 17.1 Introduction 17.2 const (Constant) Objects and const Member Functions 17.3 Composition: Objects as Members of Classes 17.4 friend
More informationFig. 7.1 Fig. 7.2 Fig. 7.3 Fig. 7.4 Fig. 7.5 Fig. 7.6 Fig. 7.7 Fig. 7.8 Fig. 7.9 Fig. 7.10
CHAPTER 7 CLASSES: PART II 1 Illustrations List (Main Page) Fig. 7.1 Fig. 7.2 Fig. 7.3 Fig. 7.4 Fig. 7.5 Fig. 7.6 Fig. 7.7 Fig. 7.8 Fig. 7.9 Fig. 7.10 Using a Time class with const objects and const member
More informationFundamentals of Programming Session 24
Fundamentals of Programming Session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 3: Classes May 24, 2004 2 Classes Structure Definitions 3 Structures Aggregate data types built using elements of other
More informationClasses: A Deeper Look. Systems Programming
Classes: A Deeper Look Systems Programming Deeper into C++ Classes const objects and const member functions Composition Friendship this pointer Dynamic memory management new and delete operators static
More information9.1 Introduction. Integrated Time class case study Preprocessor wrapper Three types of handles on an object. Class functions
1 9 Classes: A Deeper Look, Part 1 OBJECTIVES In this chapter you ll learn: How to use a preprocessor p wrapper to prevent multiple definition errors caused by including more than one copy of a header
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Spring 2013 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More informationComputer Programming Class Members 9 th Lecture
Computer Programming Class Members 9 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2015 Eom, Hyeonsang All Rights Reserved Outline Class
More informationPreview 11/1/2017. Constant Objects and Member Functions. Constant Objects and Member Functions. Constant Objects and Member Functions
Preview Constant Objects and Constant Functions Composition: Objects as Members of a Class Friend functions The use of Friend Functions Some objects need to be modifiable and some do not. A programmer
More informationl A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND
Introduction to Classes 13.2 The Class Unit 4 Chapter 13 CS 2308 Spring 2017 Jill Seaman 1 l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Spring 2015 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Fall 2012 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More informationObject-Oriented Programming (OOP) Fundamental Principles of OOP
Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming Data is stored in variables CS 2308 Spring 2014 Jill Seaman - Perhaps using arrays and structs. Program is a collection of functions that perform
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1
C How to Program, 6/e 1 Structures : Aggregate data types are built using elements of other types struct Time { int hour; int minute; Members of the same structure must have unique names. Two different
More information! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform
Ch 13: Introduction to Classes 13.1 Procedural Programming! Data is stored in variables CS 2308 Fall 2013 Jill Seaman - Perhaps using arrays and structs.! Program is a collection of functions that perform
More informationl A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND
Introduction to Classes 13.2 The Class Unit 4 Chapter 13 CS 2308 Fall 2016 Jill Seaman 1 l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains
More information(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University
(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming
More informationObject Oriented Design
Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use
More informationClasses: A Deeper Look, Part 2
10 But what, to serve our private ends, Forbids the cheating of our friends? Charles Churchill Instead of this absurd division into sexes they ought to class people as static and dynamic. Evelyn Waugh
More informationMidterm Exam 5 April 20, 2015
Midterm Exam 5 April 20, 2015 Name: Section 1: Multiple Choice Questions (24 pts total, 3 pts each) Q1: Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d.
More informationObject-Based Programming (Deitel chapter 8)
Object-Based Programming (Deitel chapter 8) 1 Plan 2 Introduction Implementing a Time Abstract Data Type with a Class Class Scope Controlling Access to Members Referring to the Current Object s Members
More information2. It is possible for a structure variable to be a member of another structure variable.
FORM 1(put name, form, and section number on scantron!!!) CS 162 Exam I True (A) / False (B) (2 pts) 1. What value will the function eof return if there are more characters to be read in the input stream?
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationl A class in C++ is similar to a structure. l A class contains members: - variables AND - public: accessible outside the class.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Spring 2018 Jill Seaman The Class l A class in C++ is similar to a structure. l A class contains members: - variables AND - functions (often called
More informationCMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am
CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103
More information! A class in C++ is similar to a structure. ! A class contains members: - variables AND. - public: accessible outside the class.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Spring 2015 Jill Seaman The Class! A class in C++ is similar to a structure.! A class contains members: - variables AND - functions (often called
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationImplementing an ADT with a Class
Implementing an ADT with a Class the header file contains the class definition the source code file normally contains the class s method definitions when using Visual C++ 2012, the source code and the
More informationEL2310 Scientific Programming
Lecture 14: Object Oriented Programming in C++ (ramviyas@kth.se) Overview Overview Lecture 14: Object Oriented Programming in C++ Classes (cont d) More on Classes and Members Group presentations Last time
More informationC++ Classes, Constructor & Object Oriented Programming
C++ Classes, Constructor & Object Oriented Programming Object Oriented Programming Programmer thinks about and defines the attributes and behavior of objects. Often the objects are modeled after real-world
More informationThe Class. Classes and Objects. Example class: Time class declaration with functions defined inline. Using Time class in a driver.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Fall 2014 Jill Seaman The Class A class in C++ is similar to a structure. A class contains members: - variables AND - functions (often called
More informationDr. Md. Humayun Kabir CSE Department, BUET
C++ Dr. Md. Humayun Kabir CSE Department, BUET History of C++ Invented by Bjarne Stroustrup at Bell Lab in 1979 Initially known as C with Classes Classes and Basic Inheritance The name was changed to C++
More information! A class in C++ is similar to a structure. ! A class contains members: - variables AND. - public: accessible outside the class.
Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Fall 2016 Jill Seaman The Class! A class in C++ is similar to a structure.! A class contains members: - variables AND - functions (often called
More informationIII. Classes (Chap. 3)
III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,
More informationECE 462 Object-Oriented Programming using C++ and Java Design Issues and Multiple Inheritance in C++
ECE 462 Object-Oriented Programming using C++ and Java Design Issues and Multiple Inheritance in C++ YHL/SPM 2016 1 A class provides interface and implementation. Code reuse is good but a class, once declared,
More informationAN OVERVIEW OF C++ 1
AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function
More informationObject-Oriented Programming
Object-Oriented Programming In C++ classes provide the functionality necessary to use object-oriented programming OOP is a particular way of organizing computer programs It doesn t allow you to do anything
More informationChapter 7: Classes Part II
1 Chapter 7: Classes Part II 7.1 Introduction 7.2 const (Constant) Objects and const Member Functions 7.3 Composition: Objects a s Members of Cla sses 7.4 friend Func tions a nd friend Cla sse s 7.5 Using
More informationMore About Classes. Gaddis Ch. 14, CS 2308 :: Fall 2015 Molly O'Neil
More About Classes Gaddis Ch. 14, 13.3 CS 2308 :: Fall 2015 Molly O'Neil Pointers to Objects Just like pointers to structures, we can define pointers to objects Time t1(12, 20, true); Time *tptr; tptr
More informationEL2310 Scientific Programming
(pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More informationFundamentals of Programming. Lecture 19 Hamed Rasifard
Fundamentals of Programming Lecture 19 Hamed Rasifard 1 Outline C++ Object-Oriented Programming Class 2 C++ C++ began as an expanded version of C. C++ improves on many of C s features and provides object-oriented-programming
More informationG205 Fundamentals of Computer Engineering. CLASS 3, Wed. Sept Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm
G205 Fundamentals of Computer Engineering CLASS 3, Wed. Sept. 15 2004 Stefano Basagni Fall 2004 M-W, 1:30pm-3:10pm Function Calls A function is called via its name Actual parameters are passed for the
More informationObject Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:
Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Section 1 Multiple Choice Questions (40 pts total, 2 pts each): Q1: Employee is a base class and HourlyWorker is a derived class, with
More informationObject Oriented Design
Object Oriented Design Chapter 6 Example Activity Diagram 1 Outline Chapter 6 Topics 6.6 C++ Standard Library Header Files 6.14 Inline Functions 6.16 Default Arguments 6.17 Unary Scope Resolution Operator
More informationLecture 5. Function Pointers
Lecture 5 Pointers to functions Complicated declarations Allocating and deallocating memory Classes const member functions Constructors and destructor this pointer static members Templates Lec 5 Programming
More informationGovernment Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING
Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++
More informationthis Pointer, Constant Functions, Static Data Members, and Static Member Functions this Pointer (11.1) Example of this pointer
this Pointer, Constant Functions, Static Data Members, and Static Member Functions 3/2/07 CS250 Introduction to Computer Science II 1 this Pointer (11.1) functions - only one copy of each function exists
More informationChapter 10 Defining Classes
Chapter 10 Defining Classes What Is a Class? A class is a data type whose variables are objects Some pre-defined data types you have used are int char You can define your own classes define your own types
More informationInheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017
OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy
CSCI 334: Principles of Programming Languages Lecture 18: C/C++ Homework help session will be tomorrow from 7-9pm in Schow 030A instead of on Thursday. Instructor: Dan Barowy HW6 and HW7 solutions We only
More informationPolymorphism. Zimmer CSCI 330
Polymorphism Polymorphism - is the property of OOP that allows the run-time binding of a function's name to the code that implements the function. (Run-time binding to the starting address of the code.)
More informationAn inline function is one in which the function code replaces the function call directly. Inline class member functions
Inline Functions An inline function is one in which the function code replaces the function call directly. Inline class member functions if they are defined as part of the class definition, implicit if
More informationLecture 7. Log into Linux New documents posted to course webpage
Lecture 7 Log into Linux New documents posted to course webpage Coding style guideline; part of project grade is following this Homework 4, due on Monday; this is a written assignment Project 1, due next
More informationC++ Programming: Functions
C++ Programming: Functions Domingos Begalli Saddleback College, Computer Science CS1B, Spring 2018 1 / Domingos Begalli CS1B Sprint 2018 C++ Introduction 1/22 22 we will cover predefined functions user-defined
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationExceptions, Case Study-Exception handling in C++.
PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case
More informationCS 1337 Computer Science II Page 1
Source File: ~/1337/65/lab65.(C CPP cpp c++ cc cxx cp) Input: Under control of main function Output: Under control of main function Value: 3 The purpose of this assignment is to add to the implementation
More informationCS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes
CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented
More informationWhat does it mean by information hiding? What are the advantages of it? {5 Marks}
SECTION ONE (COMPULSORY) Question #1 [30 Marks] a) Describe the main characteristics of object-oriented programming. {5 Marks Encapsulation the ability to define a new type and a set of operations on that
More informationClasses - 2. Data Processing Course, I. Hrivnacova, IPN Orsay
Classes - 2 Data Processing Course, I. Hrivnacova, IPN Orsay OOP, Classes Reminder Requirements for a Class Class Development Constructor Access Control Modifiers Getters, Setters Keyword this const Member
More informationHow to engineer a class to separate its interface from its implementation and encourage reuse.
1 3 Introduction to Classes and Objects 2 OBJECTIVES In this chapter you ll learn: What classes, objects, member functions and data members are. How to define a class and use it to create an object. How
More informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Multiple Inheritance July 26, 2004 22.9 Multiple Inheritance 2 Multiple inheritance Derived class has several base classes Powerful,
More informationUniversity of Swaziland Department OfComputer Science Main Examination December 2016
University of Swaziland Department OfComputer Science Main Examination December 2016 Title of paper : C under Linux Course number : CS344 Time Allowed : Three (3) hours Instructions: Answer ALL Questions
More informationLecture 7 Objects and Classes
Lecture 7 Objects and Classes An Introduction to Data Abstraction MIT AITI June 13th, 2005 1 What do we know so far? Primitives: int, double, boolean, String* Variables: Stores values of one type. Arrays:
More informationPartha Sarathi Mandal
MA 253: Data Structures Lab with OOP Tutorial 1 http://www.iitg.ernet.in/psm/indexing_ma253/y13/index.html Partha Sarathi Mandal psm@iitg.ernet.in Dept. of Mathematics, IIT Guwahati Reference Books Cormen,
More informationStarting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,
Classes Starting Savitch Chapter 10 l l A class is a data type whose variables are objects Some pre-defined classes in C++ include int, char, ifstream Of course, you can define your own classes too A class
More informationConstructor - example
Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever
More informationCSC1322 Object-Oriented Programming Concepts
CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.
More informationObject-Based Programming
Object-Based Programming 8.1 Introduction 8.2 Implementing a Time Abstract Data Type with a Class 8.3 Class Scope 8.4 Controlling Access to Members 8.5 Creating Packages 8.6 Initializing Class Objects:
More informationData Structures using OOP C++ Lecture 3
References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.
More information