Object Oriented Programming in C++ - UNIT 1 PDF

Summary

This document provides an overview of object-oriented programming principles, focusing on the differences between procedural and object-oriented programming paradigms. It introduces core concepts such as classes, objects, and inheritance. The document is suitable for undergraduate-level computer science students.

Full Transcript

**Kalinga University** **Faculty of Computer Science & IT** **Course- Diploma (CSE) Sem- IV\ Subject- Object Oriented Programming in C++** **Subject Code: DICS401** UNIT - I Differences between Procedural and Object Oriented Programming **Procedural Programming:**\ [Procedural Programming](htt...

**Kalinga University** **Faculty of Computer Science & IT** **Course- Diploma (CSE) Sem- IV\ Subject- Object Oriented Programming in C++** **Subject Code: DICS401** UNIT - I Differences between Procedural and Object Oriented Programming **Procedural Programming:**\ [Procedural Programming](https://www.geeksforgeeks.org/introduction-of-programming-paradigms/) can be defined as a programming model which is derived from structured programming, based upon the concept of calling procedure. Procedures, also known as routines, subroutines or functions, simply consist of a series of computational steps to be carried out. During a program's execution, any given procedure might be called at any point, including by other procedures or itself. **Languages used in Procedural Programming:** FORTRAN, ALGOL, COBOL, BASIC, Pascal and C. **Object Oriented Programming:**\ [Object oriented programming](https://www.geeksforgeeks.org/basic-concepts-of-object-oriented-programming-using-c/) can be defined as a programming model which is based upon the concept of objects. Objects contain data in the form of attributes and code in the form of methods. In object oriented programming, computer programs are designed using the concept of objects that interact with real world. Object oriented programming languages are various but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their types. **PROCEDURAL ORIENTED PROGRAMMING** **OBJECT ORIENTED PROGRAMMING** ------------------------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------------------- In procedural programming, program is divided into small parts called ***functions***. In object oriented programming, program is divided into small parts called ***objects***. Procedural programming follows ***top down approach***. Object oriented programming follows ***bottom up approach***. There is no access specifier in procedural programming. Object oriented programming have access specifiers like private, public, protected etc. Adding new data and function is not easy. Adding new data and function is easy. Procedural programming does not have any proper way for hiding data so it is ***less secure***. Object oriented programming provides data hiding so it is ***more secure***. In procedural programming, overloading is not possible. Overloading is possible in object oriented programming. In procedural programming, function is more important than data. In object oriented programming, data is more important than function. Procedural programming is based on ***unreal world***. Object oriented programming is based on ***real world***. Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C\# etc. C++ OOPs Concepts ================= The major purpose of C++ programming is to introduce the concept of object orientation to the C programming language. Object Oriented Programming is a paradigm that provides many concepts such as **inheritance, data binding, polymorphism etc.** The programming paradigm where everything is represented as an object is known as truly object-oriented programming language. **Smalltalk** is considered as the first truly object-oriented programming language. OOPs (Object Oriented Programming System) ----------------------------------------- **Object** means a real word entity such as pen, chair, table etc. **Object-Oriented Programming** is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts: Cpp Oops concept 1 - Object - Class - Inheritance - Polymorphism - Abstraction - Encapsulation ### ### ### Object Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical. ### Class **Collection of objects** is called class. It is a logical entity. ### Inheritance **When one object acquires all the properties and behaviors of parent object** i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. ### Polymorphism When **one task is performed by different ways** i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle etc. In C++, we use Function overloading and Function overriding to achieve polymorphism. ### Abstraction **Hiding internal details and showing functionality** is known as abstraction. For example: phone call, we don\'t know the internal processing. In C++, we use abstract class and interface to achieve abstraction. ### Encapsulation **Binding (or wrapping) code and data together into a single unit is known as encapsulation.** For example: capsule, it is wrapped with different medicines. Variables in C++ ================ A variable is a name which is associated with a value that can be changed. For example when I write int num=20; here variable name is num which is associated with value 20, int is a data type that represents that this variable can hold integer values.  Built in data types ------------------- **char**: For characters. Size 1 byte. char ch = \'A\'; **int**: For integers. Size 2 bytes. int num = 100; **float**: For single precision floating point. Size 4 bytes. float num = 123.78987; **double**: For double precision floating point. Size 8 bytes. double num = 10098.98899; User-defined data types ----------------------- We have three types of user-defined data types in C++\ 1. struct\ 2. union\ 3. enum C++ Increment and Decrement Operators x = x+1; is the same as x++; x = x-1; is the same as x\--; x = x+1; can be written as ++x; // prefix form x++; // postfix form Example ------- \#include \ using namespace std; main() { int a = 21; int c ; // Value of a will not be increased before assignment. c = a++; cout \

Use Quizgecko on...
Browser
Browser