Unit 2 Object-Oriented Programming PDF
Document Details
Uploaded by VirtuousOstrich
Medi-Caps University
Tags
Related
- Object-Oriented Programming, Lecture 06 PDF
- Object Oriented Programming With C++ (Fifth Edition) PDF
- 22316 Object-Oriented Programming using C++ Sample Question Paper PDF
- Object-Oriented Programming in C++ (Level 2) PDF
- C++ Object-Oriented Programming Concepts PDF
- CSC 1061 Week 02 ADT Classes and OOP PDF
Summary
This document discusses object-oriented programming concepts in C++. It explains abstract data types, classes, and objects, illustrated with a C++ example demonstrating a Room class. It covers the basics of creating objects and their usage.
Full Transcript
Abstract Data Types An abstract data type (or ADT) is a class that has a defined set of operations and values. Objects and Classes C++ Class A class is a blueprint for the object. We can think of a class as a sketch (prototype) of a house. It contains all the details about the floors, doors, w...
Abstract Data Types An abstract data type (or ADT) is a class that has a defined set of operations and values. Objects and Classes C++ Class A class is a blueprint for the object. We can think of a class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows, etc - we build the house based on these descriptions. C++ Objects 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, we need to create objects. Example: Object and Class in C++ Programming // Program to illustrate the working of // objects and class in C++ Programming #include using namespace std; // create a class class Room { public: double length; double breadth; double height; double calculate_area() { return length * breadth; } double calculate_volume() { return length * breadth * height; } }; int main() { // create object of Room class Room room1; // assign values to data members room1.length = 42.5; room1.breadth = 30.8; room1.height = 19.2; // calculate and display the area and volume of the room cout