OOPS (ACCS-16302) Lecture Notes PDF
Document Details
Uploaded by DiligentMusicalSaw
Amritsar College of Engineering and Technology
Neha Chadha
Tags
Related
- Object Oriented Programming GLS University PDF
- OOPs 2022 Lecture Notes PDF
- Object Oriented Programming Course Plan (Chitkara University) PDF
- MCADD-501 Object Oriented Programming in C++ May 2022 Past Paper PDF
- MCAD-501 Object Oriented Programming in C++ May 2023 Exam PDF
- MCADD-501 Object Oriented Programming in C++ PDF November 2023 Past Paper
Summary
These lecture notes cover fundamental concepts in object-oriented programming using C++. Topics include classes, objects, data members, member functions, access specifiers (public, protected, private), empty classes, arrays of objects, pointers to objects, and friend functions. The notes are accompanied by example programs to illustrate the practical application of these concepts.
Full Transcript
Amritsar College of Engineering & Technology, Amritsar, Punjab, INDIA NAAC - A grade, NBA accredited courses(2009-12, 2016-18), UGC Autonomous College SUBJECT: OOPS (ACCS-16302) Er. Neha Chadha Associate Professor...
Amritsar College of Engineering & Technology, Amritsar, Punjab, INDIA NAAC - A grade, NBA accredited courses(2009-12, 2016-18), UGC Autonomous College SUBJECT: OOPS (ACCS-16302) Er. Neha Chadha Associate Professor Department of Computer Science and Engineering 1 Er. Neha Chadha [email protected] CSE 3rd Sem. OOPS Class A class in C++ is the building block, that leads to Object- Oriented programming. It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class Data members Member Functions Data members are the data variables Member functions are the functions used to manipulate these variables and together these data members and member functions defines the properties and behavior of the objects in a Class. Member Functions can be defined inside the class as well as outside the class Syntax of Class Object When a class is defined, only the specification for the object is defined; no memory or storage is allocated. To use the data and access functions defined in the class, you need to create objects Syntax ClassName ObjectName; Accessing data members and member functions: The data members and member functions of class can be accessed using the dot(‘.’) operator with the object. For example ✓ name of object is obj ✓ member function Showname() obj.Showname() Accessing a data member depends solely on the access control of that data member. Access Specifier Specifier Within Same In Derived Outside the Class Class Class Private Yes No No Protected Yes Yes No Public Yes Yes Yes Empty Class Empty class means, a class that does not contain any data members minimum memory available at object address location is 1 byte Why actually an empty class in C++ takes one byte? Simply a class without an object requires no space allocated to it. The space is allocated when the class is instantiated, so 1 byte is allocated by the compiler to an object of an empty class for its unique address identification Array of object Like array of other user-defined data types, an array of type class can also be created. The array of type class contains the objects of the class as its individual elements. Thus, an array of a class type is also known as an array of objects. An array of objects is declared in the same way as an array of any built-in data type. Array of Objects Program #include void main () #include { class stu clrscr(); { stu s; int rn; int i; public: for(i=0;i>rn;} s[i].getdata(); void showdata(); } }; for(i=0;i>mon; } s.print(); void showinner() { getch(); cout