×
IT'S TIME TO WORK A LITTLE HARDER.
--Your friends at LectureNotes
Close

Object Oriented Programming Using Cpp

by Durga PrasadDurga Prasad
Type: NoteCourse: B.Tech Specialization: Computer Science EngineeringOffline Downloads: 435Views: 4768Uploaded: 8 months ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Durga Prasad
Durga Prasad
C++ and Object Oriented Programming Basic Introduction: C++ is derived from C Language. It is a Superset of C. Earlier C++ was known as C with classes. In C++, the major change was the addition of classes and a mechanism for inheriting class objects into other classes. Most C Programs can be compiled in C++ compiler. C++ expressions are the same as C expressions. All C operators are valid in C++. Different between c and c++ C C++ 1. C is Procedural Language. 1. C++ is non Procedural i.e Object oriented Language. 2. No virtual Functions are present in C 2. The concept of virtual Functions are used in C++. 3. In C, Polymorphism is not possible. 3. The concept of polymorphism is used in C++. Polymorphism is the most Important Feature of OOPS. 4. Operator overloading is not possible in C. 4. Operator overloading is one of the greatest Feature of C++. 5. Top down approach is used in Program Design. 5. Bottom up approach adopted in Program Design. 6. No namespace Feature is present in C Language. 6. Namespace Feature is present in C++ for avoiding Name collision.
7. Multiple Declaration of global variables are allowed. 7. Multiple Declaration of global variables are not allowed. 8. In C 8. In C++ scanf() Function used for Input. Cin>> Function used for Input. printf() Function used for output Cout<< Function used for output. 9. Mapping between Data and Function is difficult and complicated. 9. Mapping between Data and Function can be used using "Objects" 10. In C, we can call main() Function through other Functions 10. In C++, we cannot call main() Function through other functions. 11. C requires all the variables to be defined at the starting of a scope. 11. C++ allows the declaration of variable anywhere in the scope i.e at time of its First use. 12. No inheritance is possible in C. 12. Inheritance is possible in C++ 13. In C, malloc() and calloc() Functions are used 13.In C++, new and delete operators are used for Memory Allocation and free() function for for Memory Allocating and Deallocating. memory Deallocating. 14. It supports built-in and primitive data types. 14. It support both built-in and user define data types. 15. In C, Exception Handling is not present. 15. In C++, Exception Handling is done with Try and Catch block. Object Oriented programming is a programming style that is associated with the concept of Class, Objects and various other concepts revovling around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation etc.
Let us try to understand a little about all these, through a simple example. Human Beings are living forms, broadly categ categorized orized into two types, Male and Female. Right? Its true. Every Human being(Male or Female) has two legs, two hands, two eyes, one nose, one heart etc. There are body parts that are common for Male and Female, but then there are some specific body parts, present esent in a Male which are not present in a Female, and some body parts present in Female but not in Males. All Human Beings walk, eat, see, talk, hear etc. Now again, both Male and Female, performs some common functions, but there are some specifics to both, which is not valid for the other. For example : A Female can give birth, while a Male cannot, so this is only for the Female. Human Anatomy is interesting, isn't it? But let's see how all this is related to C++ and OOPS. Here we will try to explain all all the OOPS concepts through this example and later we will have the technical definitons for all this. Class
Here we can take Human Being as a class. A class is a blueprint for any functional entity which defines its properties and its functions. Like Human Being, having body parts, and performing various actions. Inheritance Considering HumanBeing a class, which has properties like hands, legs, eyes etc, and functions like walk, talk, eat, see etc. Male and Female are also classes, but most of the properties and functions are included inHumanBeing, hence they can inherit everything from class HumanBeing using the concept of Inheritance. Objects My name is Abhishek, and I am an instance/object of class Male. When we say, Human Being, Male or Female, we just mean a kind, you, your friend, me we are the forms of these classes. We have a physical existence while a class is just a logical definition. We are the objects. Abstraction Abstraction means, showcasing only the required things to the outside workd while hiding the details. Continuing our example, Human Being's can talk, walk, hear, eat, but the details are hidden from the outside world. We can take our skin as the Abstraction factor in our case, hiding the inside mechanism. Encapsulation

Lecture Notes