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.

Презентация:



Advertisements
Похожие презентации
Object Oriented Programming Ashraf Zia Lecturer Abdul Wali Khan University, Mardan. Lecture - 1.
Advertisements

1 © Luxoft Training 2012 Inner and anonymous classes.
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Interface.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
Operator Overloading Customised behaviour of operators Chapter: 08 Lecture: 26 & 27 Date:
Data Types in C. A Data Type A data type is –A set of values AND –A set of operations on those values A data type is used to –Identify the type of a variable.
1/30 Chapter 8: Dynamic Binding And Abstract classes.
Unit II Constructor Cont… Destructor Default constructor.
1/27 Chapter 9: Template Functions And Template Classes.
Object Oriented Programming Ashraf Zia Lecturer Abdul Wali Khan University, Mardan. Lecture - 2.
1 C++ Structures Starting to think about objects...
Michael Marchenko. In mathematics, a sequence is an ordered list of objects (or events). Like a set, it contains members (also called elements, or terms),
© 2009 Avaya Inc. All rights reserved.1 Chapter Two, Voic Pro Components Module Two – Actions, Variables & Conditions.
How can we measure distances in open space. Distances in open space.
Object-Oriented Programming Dr. Ramzi Saifan Slides adapted from Prof. Steven Roehrig.
Arrays Dr. Ramzi Saifan Slides adapted from Prof. Steven Roehrig.
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Polymorphism.
11 BASIC DRESS-UP FEATURES. LESSON II : DRESS UP FEATURES 12.
Reference Feature Power Copy Destination CATPart Copied Feature Reference CATPart PowerCopy Reference Feature Copied Feature Instantiate Link to.
© Luxoft Training 2013 Annotations. © Luxoft Training 2013 Java reflection / RTTI // given the name of a class, get a "Class" object that // has all info.
Транксрипт:

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(); };

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.

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

#include 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 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

NAME ID TITLE CLUB DUES PUBLICATIONS class employee class managerclass scientistclass laborer

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(); }