1 / 24

Welcome to Classes and Objects

Welcome to Classes and Objects. Prepared By : Nishant Tiwari PGT(CS) JNV, Padmi,Mandla. Classes and Objects. Introduction Classes Data hiding and Encapsulation Functions in a class Using objects Static Class Members. Introduction.

arlais
Download Presentation

Welcome to Classes and Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome to Classes and Objects Prepared By : NishantTiwari PGT(CS) JNV, Padmi,Mandla

  2. Classes and Objects Introduction Classes Data hiding and Encapsulation Functions in a class Using objects Static Class Members

  3. Introduction • The most important features of C++ are the classes and objects. C++ is a bunch of small additions to C, with a few major additions. As the name object-oriented programming suggests this approach deals with objects. Classes are collections of related to a single object type. Classes not include information regarding the real world object but also function to access the data and classes possess the ability to inherit from other classes

  4. Classes • Class represents a group of similar objects • A class is a way to bind the data describing an entity and its associated functions together • A class is user-defined data type used to implement an abstract object giving you the capability to use object oriented programming with c++. • A class includes members • A member can be either data, know as a data member or a function known as a member function

  5. Classes Declaration • Class class_name { Private: data_members member_functions [public: data_members member_functions] [protected: data_members member_functions] }

  6. Classes Declaration • The contents of each instance of class_name : data_members and data_functions • The members are of private, protected or public specifier

  7. Classes Declaration • The declaration of a class involves declaration of its four associated attributes • Data members are the data-type properties that describe the characteristics of a class. There may be zero or more data members of any type in a class • Member functions are set of operations that may be applied to object of that class. There may be zero or more member functions of a class. They are referred to as the class interface • Program Access Levels that control access to members from within the program. These access levels are private, protected or public .Depending upon the access level of a class member, access to it allowed or denied • Class Tag name that serves as a type specifier for the class using which objects of this class type can be created.

  8. Classes Declaration • The class specification takes place in two parts Class definition: which describe the component members (data member and functions members) of the class Class method: which describe how certain class member function are implemented.

  9. The class methods definition • Outside the class definition • Inside the class definition

  10. Outside the class definition Class salesman { Int salesman_no: Int product_no; Public: Void readdata( ); Void displaydata( ); }; Void salesman::readdata( ) { Cout<<“enter salesman_no”; Cin>>salesman_no; } Void salesman::displaydata( ) { Cout<<“the salesman_no”<<salesman_no; }

  11. Outside the class definition • A member function definition outside the class definition is much same as that of function definitions . The only difference is that the name of the function is the full name of the function. the full name (also called qualified-name) of the function is written as: • Class-name::function-name

  12. Outside the class definition • Class-name:indicate that the function specified by function_name is a member of the class specified by class-name. • The symbol :: called the scope resolution operator specifies that the scope of the function is restricted to the class class-name.

  13. Outside the class definition • The general form of a member function definition outside the class definition is Return-type class-name :: function_name (parameter list) { Function body }

  14. Membership label • The membership label (classname ::) will resolve their identity and scope Void student : : add ( )

  15. inside the class definition A function define inside a class is automatically inline function. Class student { Int a; Public: Void readdata () { Cout<<“enter the value of a”; Cin>>a; }

  16. Referencing class members • A class specification does not define any objects of its type rather it just define the properties of a class example • Student s1,s2,s3;

  17. Referencing class members • Class abc { Int x,y // private by default Public: Int z; Int add (int a,int b) { Int c=a+b; Return c; } }; Abc a1,a2;

  18. Referencing class members • The private data of a class can be accessed only through the member function of that class • The public data can be accessed by the non-member function through the objects of the class

  19. Referencing class members • The general format for calling a member function is Object-name.function-name(actual-arugment); A1.abc(2,3); A2.abc(4,6);

  20. Referencing class members • To access the public data member,the format used is: a1.z or a2.z But if we give A1.x or a2.y An error since x and y are private data member of class abc

  21. Array with in class • An array in a class can be private or public data member of the class • A class can have an array as its member variable • If an array happen to be private data member of the class then only the member functions of the class can access it. • If an array is a public data member of the class it can be accessed directly using object of this class type.

  22. Array with in class Class exarray { Int arr[10]; //private data member Public: Int largest(void); Int sum(void); }; The data member of class exarray accessed only through the member function largest() and sum(); not directly by objects.

  23. Question classes and objects • Q1 what is the significance of scope resolution operator (::) ? • Q2 what is difference between private and public member of a class ? • Q3 Define abstract data type and encapsulation ? • Q4 Declare a class employee having following members: Data member: employee number Employee name Employee address Employee department Member function To read data member To display

  24. Thank You !!!

More Related