Institute of Business & Technology (BIZTEK)

Slides:



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

CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
1 Chapter 11 Introducing the Class Pages ( )
INHERITANCE BASICS Reusability is achieved by INHERITANCE
C++ Classes & Data Abstraction
1 Writing a Good Program 5. Objects and Classes in C++
Introduction to Programming with Java, for Beginners Scope.
C++ fundamentals.
 By Wayne Cheng.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes.
February 11, 2005 More Pointers Dynamic Memory Allocation.
1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming.
Learners Support Publications Classes and Objects.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 25P. 1Winter Quarter C++: I/O and Classes Lecture 25.
1 CSC241: Object Oriented Programming Lecture No 16.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
CS1201: Programming Language 2 Classes and objects By: Nouf Aljaffan Edited by : Nouf Almunyif.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
CS212: Object Oriented Analysis and Design Lecture 14: Reusing classes in C++
C++ Programming Basic Learning Prepared By The Smartpath Information systems
11 Introduction to Object Oriented Programming (Continued) Cats.
Object Oriented Programming (OOP) Lecture No. 11.
1 What is the purpose of Inheritance? zSpecialisation Extending the functionality of an existing class zGeneralisation sharing commonality between two.
Structures, Classes and Objects Handling data and objects Unit - 03.
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.
SNPL1 Woochang Lim C+OOP = C++ C (non OOP)  C++ (non OOP+OOP)  Java (OOP) Object-Oriented Design  Object-Oriented Programming Programming with C++
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 07 classes 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Classes.  A collection of variables combined with a set of related functions MemberFunctions (methods) (methods) MemberVariables (data members) (data.
Programming 2. Arrays & structure Arrays : allow you to define variables that combine several data items of the same kind. Structure : is another user.
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
1 Inheritance and Polymorphism Chapter Getting Started Continue the Cat Management example from previous presentation.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Inheritance w Why Inheritance? Reuse w Historical Review of Reuse (1) Rewrite Existing Codes (2) Function Libraries (3) Class Libraries.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Lecture 3 (UNIT -1) SUNIL KUMAR CIT-UPES.
2 Chapter Classes & Objects.
CSC241: Object Oriented Programming
Review: Two Programming Paradigms
Concepts and Basics of C++ Programming
Chapter 5 Classes.
CS1201: Programming Language 2
Programming Fundamentals
C++ Arrays.
Concepts and Basics of C++ Programming
Object Oriented Analysis and Design
Lecture 8 – 9 Arrays with in a class
CS5253 Workshop I Lecturer: Dr. Lusheng Wang
Programming -2 برمجة -2 المحاضرة-7 Lecture-7.
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
Classes and Objects.
Static in Classes CSCE 121 J. Michael Moore.
5th Chapter Pointers in C++.
CLASSES AND OBJECTS.
CPS120: Introduction to Computer Science
Inheritance:Concept of Re-usability
By Rajanikanth B OOP Concepts By Rajanikanth B
Institute of Petroloeum Technology, Gandhinagar
CS1201: Programming Language 2
Object Oriented Programming (OOP) Lecture No. 11
Chapter 12: Classes and Data Abstraction
OOP objects and Classes Dr. Ahmed Hashim Mohammed A Simple Class
Presentation transcript:

Institute of Business & Technology (BIZTEK) OBJECT-ORIENTED PROGRAMMING CLASSES & OBJECTS

CLASS A class is just a collection of variables--often of different types--combined with a set of related functions. The variables in the class are referred to as the member variables or data members. The functions in the class typically manipulate the member variables. They are referred to as member functions or methods of the class.

Member variables , also known as data members , are the variables in your class. Member variables are part of your class. Member functions , also known as methods , are the functions in your class. Member functions are as much a part of your class as the member variables. They determine what the objects of your class can do.

To declare a class, use the class keyword followed by an opening brace, and then list the data members and methods of that class. End the declaration with a closing brace and a semicolon. Here's the declaration of a class called Cat: class Cat { unsigned int itsAge; unsigned int itsWeight; abc(); };

OBJECT An object is an individual instance of a class. You define an object of your new type just as you define an integer variable: unsigned int GrossWeight; // define an unsigned integer Cat Frisky; // define a Cat This code defines a variable called Gross Weight whose type is an unsigned integer. It also defines Frisky, which is an object whose class (or type) is Cat. Object are sometimes called instance variables.

Accessing Class Members Once you define an actual Cat object--for example, Frisky--you use the dot operator (.) to access the members of that object. Therefore, to assign 50 to Frisky's Weight member variable, you would write Frisky.Weight = 50;

The body of the class contains two unfamiliar keywords: private and public The key feature of the object-oriented programming is data hiding. It means that data is concealed within a class, so that It cannot be accessed mistakenly by functions outside the class. The primary mechanism for hiding data is to put it in a class and make it private. Private data or functions can only be accessed from within the class. Public data or functions are accessible from outside the class

Output: Frisky is a cat who is 5 years old. #include <iostream.h> class Cat { public: int itsAge; 10: int itsWeight; }; void main() Cat Frisky; Frisky.itsAge = 5; cout << "Frisky is a cat who is " ; cout << Frisky.itsAge << " years old.\n"; } Output: Frisky is a cat who is 5 years old.

INHERITANCE Inheritance is the process of creating new classes, called derived classes from existing or base classes. The derived class inherits all the capabilities of the base class. class Cat { unsigned int itsAge; unsigned int itsWeight; abc(); }; class scat : public cat

class employee class manager class scientist class laborer NAME ID TITLE CLUB DUES PUBLICATIONS

Class employee { Private: char name[20]; int number; Public: void getdata() cout<<“\n ENTER NAME”; cin>>name; cout<<“ENTER NUMBER”; cin>>number; } void putdata() cout << “\n Name: “ <<name cout << “\n Number: “ << number; };

Class manager : public employee { Private: char title[20]; int dues; Public: void getdata() employee::getdata(); cout<<“\n ENTER TITLE”; cin>>title; cout<<“ENTER CLUB DUES”; cin>>dues; } void putdata() employee::pudata(); cout << “\n TITLE: “ << title cout << “\n CLUB DUES: “ << dues; };

Class scientist : public employee { Private: int pubs; Public: void getdata() employee::getdata(); cout<<“\n ENTER NUMBER OF PUBLICATIONS”; cin>>pubs; } void putdata() employee::pudata(); cout << “\n NUMBER OF PUBLICATIONS : “ << pubs };

Class laborer : public employee { };

main( ) { manager m1,m2; scientist s1; laborer l1; Count << endl; cout << “ENTER DATA FOR MANAGER 1 “; m1.getdata(); cout << “ENTER DATA FOR MANAGER 2 “; m2.getdata(); }

cout << “ENTER DATA FOR SCIENTIST “; s1.getdata(); cout << “ENTER DATA FOR LABORER “; l1.getdata(); cout << “DATA OF MANAGER 1 “; m1.putdata(); cout << “DATA OF MANAGER 2 “; m2.putdata(); }