🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Notes_CSE2001_OOP_with_C++_Unit I (1).pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

PatriChlorine

Uploaded by PatriChlorine

Tags

computer programming object oriented programming c++

Full Transcript

Class Notes UNIT – I Syllabus: Introduction to Object Oriented approach: Why object oriented programming? - Characteristics of object oriented language: classes and objects - encapsulation-data abstraction- inheritance - polymorphism - Merits and Demerits of object...

Class Notes UNIT – I Syllabus: Introduction to Object Oriented approach: Why object oriented programming? - Characteristics of object oriented language: classes and objects - encapsulation-data abstraction- inheritance - polymorphism - Merits and Demerits of object oriented programming. UML- class diagram of OOP - Inline function – default argument function- Exception handling (Standard) - reference: independent reference – function returning reference – pass by reference Learning Objectives: To understand the relative merits of C++ as an Object Oriented Programming (OOP) language To understand the features / characteristics of C++ that supports OOP approach To demonstrate the concepts of UML and class diagram in OOP To demonstrate the concept of functions (inline, returning reference) 1. Introduction to Object Oriented approach An Object Oriented Programming (OOP) is a way of programming which enables programmers to think like they are working with real-life entities (a thing with distinct and independent existence) or objects. In real-life, people have knowledge and can do various works. In OOP, objects have fields to store knowledge/state/data and can do various works — methods. Object Oriented programming is a programming style that is associated with the concept of Class, Objects and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation etc. Fig. 1. OOP Features Prepared by: Prof. Anand Motwani, Faculty, SCSE, VIT Bhopal University Why OOP? Characteristics / Features (Definitions of OOPS Concepts) Objects Objects are the basic unit of OOP. They are instances of class, and have data members and various member functions to perform tasks. Class It is similar to structures in C language. Class can also be defined as user defined data type but it also contains functions in it. So, class is basically a blueprint for object. It declare & defines what data variables the object will have and what operations can be performed on the class's object. Abstraction Abstraction refers to showing only the essential features of the application and hiding the details. In C++, classes provide methods to the outside world to access & use the data variables, but the variables are hidden from direct access. This can be done access specifiers. Encapsulation It can also be said data binding. Encapsulation is all about binding the data variables and functions together in class. Inheritance Inheritance is a way to reuse once written code again and again. The class which is inherited is called base calls & the class which inherits is called derived class. So when, a derived class inherits a base class, the derived class can use all the functions which are defined in base class, hence making code reusable. Polymorphism It is a feature, which lets us create functions with same name but different arguments, which will perform differently. That is function with same name, functioning in different way. Or, it also allows us to redefine a function to provide its new definition. You will learn how to do this in details soon in coming lessons. Exception Handling Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at runtime. Prepared by: Prof. Anand Motwani, Faculty, SCSE, VIT Bhopal University Instances A blueprint for a house design is like a class description. All the houses built from that blueprint are objects of that class. A given house is an instance. Merits of C++ (OOP) over C Language (Procedural) The major difference being OOPS concept, C++ is an object oriented language whereas C language is a procedural language. There are many other features of C++ which gives this language an upper hand on C language. Following features of C++ makes it a stronger language than C, 1. There is Stronger Type Checking in C++. 2. All the OOPS features in C++ like Abstraction, Encapsulation, Inheritance etc makes it more worthy and useful for programmers. 3. C++ supports and allows user defined operators (i.e Operator Overloading) and function overloading is also supported in it. 4. Exception Handling is there in C++. 5. The Concept of Virtual functions and also Constructors and Destructors for Objects. 6. Inline Functions in C++ instead of Macros in C language. Inline functions make complete function body act like Macro, safely. Variables can be declared anywhere in the program in C++, but must be declared before they are used. Unified Modeling Language (UML) Prepared by: Prof. Anand Motwani, Faculty, SCSE, VIT Bhopal University UML, short for Unified Modeling Language, is a standardized Modeling language consisting of an integrated set of diagrams, developed to help system and software developers for specifying, visualizing, constructing, and documenting the artifacts of software systems, as well as for business Modeling and other non-software systems. The UML represents a collection of best engineering practices that have proven successful in the modeling of large and complex systems. The UML is a very important part of developing object oriented software and the software development process. The UML uses mostly graphical notations to express the design of software projects. Using the UML helps project teams communicate, explore potential designs, and validate the architectural design of the software. In this article, we will give you detailed ideas about what is UML, the history of UML and a description of each UML diagram type, along with UML examples. The primary goals in the design of the UML in Fundamental Object-Oriented Design in UML as follows: o Provide users with a ready-to-use, expressive visual modeling language so they can develop and exchange meaningful models. o Provide extensibility and specialization mechanisms to extend the core concepts. o Be independent of particular programming languages and development processes. o Provide a formal basis for understanding the modeling language. o Encourage the growth of the OO tools market. o Support higher-level development concepts such as collaborations, frameworks, patterns and components. o Integrate best practices. What is a Class Diagram? The class diagram is a central modeling technique that runs through nearly all object-oriented methods. This diagram describes the types of objects in the system and various kinds of static relationships which exist between them. Prepared by: Prof. Anand Motwani, Faculty, SCSE, VIT Bhopal University Relationships There are three principal kinds of relationships which are important: Association - represent relationships between instances of types (a person works for a company, a company has a number of offices. Inheritance - the most obvious addition to ER diagrams for use in OO. It has an immediate correspondence to inheritance in OO design. Aggregation - Aggregation, a form of object composition in object-oriented design. Class Diagram Example Fig. 2. Class Diagram How to draw Class diagram using Visual Paradigm software? https://www.visual- paradigm.com/support/documents/vpuserguide/94/2576/7190_drawingclass.html Prepared by: Prof. Anand Motwani, Faculty, SCSE, VIT Bhopal University Class Diagram for proposed program for Toy store reception Fig. 3. Class diagram for Toy store software Functions: Parameters and Arguments C++ supports two styles of passing arguments: “pass by value” and “pass by reference”. They are also called as “call by value” and “call by reference” respectively. Argument is the value or reference passed from a program to the function. The calling program gives arguments to the function. On the contrary the local variables used within the function to hold the argument values are called parameters. Sometimes these two terms are used interchangeably. If the argument is passed as value to the function, the parameter receives a copy of argument value. Any changes made by function to parameter value will not affect the argument (shown by Program 1). Example Program 1 is showing the example of Pass / Call by value. Prepared by: Prof. Anand Motwani, Faculty, SCSE, VIT Bhopal University Program 1: args.cpp // Program to demonstrate the parameters and arguments. # include < iostream.h > # include < conio.h > void demo ( int ) ; //Function declaration or prototype int main ( ) { int x =101; demo ( x ) ; // x is passed as argument to function cout

Use Quizgecko on...
Browser
Browser