×
Stop thinking about WHAT WILL HAPPEN and start thinking about WHAT YOU CAN DO.
--Your friends at LectureNotes
Close

Advanced Data Structure

by Dr. D. Jagadeesan
Type: NoteInstitute: Sreenivasa Institute of Technology and Management Studies Course: B.Tech Specialization: Computer Science EngineeringViews: 55Uploaded: 1 month agoAdd to Favourite

Touch here to read
Page-1

Advanced Data Structure by Dr. D. Jagadeesan

Topic:
Dr. D. Jagadeesan
Dr. D. Jagadeesan

/ 135

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

SITAMS – B.Tech – II Year - I Sem CSE 13CSE 211 - ADVANCED DATA STRUCTURES through C++ Dr. D. Jagadeesan, B.E., M.Tech., Ph.D., Professor in CSE, Unit – I Class Overview Class – Objects - Class members - Access control - Class scope - Static class members Inline functions - Friend functions - This pointer - Dynamic memory allocation and deallocation (New and Delete) - Constructors and destructors - Function overloading Operator overloading - Inheritance basics - Base class access control - Inheritance types Runtime polymorphism using virtual functions - Generic programming - Function and class templates. CLASS & OBJECTS CLASS:  A Class is a user defined data type to implement an abstract object. Abstract means to hide the details. A Class is a combination of data and functions.  Data is called as data members and functions are called as member functions.  Class member functions can be defined inside the class definition or outside the class definition.  Class in C++ are similar to structures in C, the only difference being, class defaults to private access control, where as structure defaults to public.  Data member or member functions may be public, private or protected which is called access specifiers.  Public means data members or member functions defining inside the class can be used at outside the class.( in different class and in main function)  Private means data members and member functions can’t be used outside the class.  Protected means data member and member functions can be used in the same class and its derived class (at one level) (not in main function). Class Data 1 Data 2 ----Data n Function1 Function2 ----Function n 1 / 51
SITAMS – B.Tech – II Year - I Sem CSE 13CSE 211 - ADVANCED DATA STRUCTURES through C++ Dr. D. Jagadeesan, B.E., M.Tech., Ph.D., Professor in CSE, Unit – I Defining the Class:  Class is defined in C++ programming using keyword class followed by identifier (name of class). Body of class is defined inside curly brackets and terminated by semicolon at the end. Syntax: class class_name { access_specifier: // some data member; // some functions; }; // public, private or protected. Example: class Circle { private: int radius; float area; public: void calculate_area() { cout<< “Area :”<<3.14*r*r; } }; // access specifier // data members //member function // function body OBJECTS  Class is mere a blueprint or a template. Class is a logical appearance where as the object is physical appearance.  No storage is assigned when we define a class.  Objects are instances of class, which holds the data variables declared in class and the member functions work on these class objects. Syntax: class_name variable_name; Example: Circle c; // in main function 2 / 51
SITAMS – B.Tech – II Year - I Sem CSE 13CSE 211 - ADVANCED DATA STRUCTURES through C++ Dr. D. Jagadeesan, B.E., M.Tech., Ph.D., Professor in CSE, Unit – I Example Program: // Program to illustrate working of Objects and Class in C++ Programming #include <iostream.h> #include<stdio.h> class student { private: int rollno; char name[20]; public: void getdata() { cout<<“enter the rollno.:”; cin>>rollno; cout<<“enter the name:”; gets(name); } void putdata(); }; void student :: putdata() // Member Function defining inside the Class // Member Function defining outside the Class { cout<<“rollno:”<<rollno; cout<<“\nname:”; puts(name); } void main() { student s; s.getdata(); s.putdata(); } Class Members : Data member and Member functions     The data within the class is known as data member. The function defined within the class is known as member function. The function defined Outside the Class using scope resolution operator ::. From the above example: student is class, rollno and name are data members and getdata() and putdata() are member functions.  The member of a class can be accessed by using the object of that class & dor (.) operator. 3 / 51
SITAMS – B.Tech – II Year - I Sem CSE 13CSE 211 - ADVANCED DATA STRUCTURES through C++ Dr. D. Jagadeesan, B.E., M.Tech., Ph.D., Professor in CSE, Unit – I Accessing Data Members and Member functions  Data members and member functions can be accessed in similar way the member of structure is accessed using member operator(.). For the class and object defined above, func1() for object obj2 can be called using code:  For example:  Object_name.funtion-name(); //access member function  Object_name.data_member=value; //access data member and assign value Access control in Classes:  Access specifiers in class has three new keywords introduced, namely,  public  private  protected  These access specifiers are used to set boundaries for availability of members of class be it data members or member functions.  Access specifiers in the program, are followed by a colon. You can use one, two or all three specifiers in the same class to set different boundaries for different class members. Public specifier:  Public means all the class members declared under public will be available to everyone.  The data members and member functions declared public can be accessed by other classes also. class PublicAccess { public: // public access specifier int x; // Data Member declaration void display(); // Member Function declaration }; Private specifier:  Private means that no one can access the class members declared private outside that class.  If someone tries to access the private member, they will get a compile time error.  By default class variables and member functions are private. class PrivateAccess { private: // private access specifier int x; // Data Member declaration void display(); // Member Function declaration }; 4 / 51

Lecture Notes