Document Details

TranquilInfinity6076

Uploaded by TranquilInfinity6076

SRM Institute of Science & Technology

CINTEL Team

Tags

object-oriented programming OOP concepts C++ programming programming paradigms

Summary

This document introduces Object-Oriented Programming (OOP) concepts, covering procedural programming, its aspects, and advantages and disadvantages of procedural programming versus object-oriented programming. It also discusses object-oriented concepts and their importance in constructing models based on real-world scenarios.

Full Transcript

18CSC202J Object Oriented Design and Programming UNIT-1 Prepared by , CINTEL Team 8/24/2022 1 18CSC202J - OBJECT ORIENTED DESIGN AND PROGRAMM...

18CSC202J Object Oriented Design and Programming UNIT-1 Prepared by , CINTEL Team 8/24/2022 1 18CSC202J - OBJECT ORIENTED DESIGN AND PROGRAMMING Session 1 Topic : PROCEDURAL AND OBJECT ORIENTED PROGRAMMING 8/24/2022 C ,C++ and UML Basics 2 The main program coordinates calls to procedures and hands over appropriate data as parameters. 8/24/2022 C ,C++ and UML Basics 3 Procedure Oriented Programming Language 8/24/2022 C ,C++ and UML Basics 4 C function aspects Syntax Function declaration Return-type function-name(argument list); Eg : int add(int a, int b); Function definition Return-type function-name(argument list) { body of function;) Eg : int add(int a, int b) {int c; c=a+b; Return c; } Function call Function-name(argument list); Eg : add(5,10); 8/24/2022 C ,C++ and UML Basics 5 Features of Procedure Oriented Programming Language Smaller programs - A program in a procedural language is a list of instructions. Larger programs are divided in to smaller programs known as functions. Each function has a clearly defined purpose and a clearly defined interface to the other functions in the program. Data is Global and shared by almost all the functions. Employs Top Down approach in Program Design. 8/24/2022 C ,C++ and UML Basics 6 Examples of Procedure Oriented Programming Language COBOL FORTRAN C 8/24/2022 C ,C++ and UML Basics 7 Sample COBOL Program(Procedure Oriented) IDENTIFICATION DIVISION. PROGRAM-ID. ENVIRONMENT DIVISION. * procedure will be followed by using few Division DATA DIVISION. WORKING-STORAGE SECTION. 77 A PIC 9999. 77 B PIC 9999. 77 ANS PIC 999V99. PROCEDURE DIVISION. MAIN-PARA. DISPLAY \”--------------------------------\”. DISPLAY \” ENTER A\” ACCEPT A. * command line argument DISPLAY \”ENTER B\”. ACCEPT B. DISPLAY \”----------------------------------\”. ADD-PARA. ADD A B GIVING ANS. DISPLAY \”-------------------------------------\”. DISP-PARA. DISPLAY \”A IS \” A. DISPLAY \”B IS \” B. DISPLAY \”ADDITION -\” ANS. 8/24/2022 STOP RUN. C ,C++* and to stop UMLthe program Basics 8 Disadvantages of Procedural Programming Language Unrestricted access functions have unrestricted access to global data. Real-world modeling unrelated (separated) functions and data, the basis of the procedural paradigm, provide a poor model of the real world. Complex real-world objects have both attributes (data) and behavior (function). 8/24/2022 C ,C++ and UML Basics 9 Object-Oriented Concept Objects of the program interact by sending messages to each other, hence it increases the data security (data can be accessed only through its instances) 8/24/2022 C ,C++ and UML Basics 10 Object Oriented Programming Object-oriented programming is a programming paradigm that uses abstraction in the form of classes and objects to create models based on the real world environment. An object-oriented application uses a collection of objects, which communicate by passing messages to request services. The aim of object-oriented programming is to try to increase the flexibility and maintainability of programs. Because programs created using an OO language are modular, they can be easier to develop, and simpler to understand after development 8/24/2022 C ,C++ and UML Basics 11 Object-Oriented Concepts Everything is an object and each object has its own memory Computation is performed by objects communicating with each other Every object is an instance of a class. A class simply represents a grouping of similar objects, such as Integers or lists. The class is the repository for behavior associated with an object. That is, that all objects that are instances of the same class can perform the same actions. Classes are organized into a singly rooted tree structure, called the inheritance hierarchy. Memory and behavior associated with instances of a class are automatically available to any class associatedC with 8/24/2022 ,C++ andaUML descendant Basics in this tree structure. 12 Object-Oriented Programming vs. Procedural Programming Programs are made up of modules, which are parts of a program that can be coded and tested separately, and then assembled to form a complete program. In procedural languages (i.e. C) these modules are procedures, where a procedure is a sequence of statements. The design method used in procedural programming is called Top Down Design. This is where you start with a problem (procedure) and then systematically break the problem down into sub problems (sub procedures). 8/24/2022 C ,C++ and UML Basics 13 Object-Oriented Programming vs. Procedural Programming The difficulties with Procedural Programming, is that software maintenance can be difficult and time consuming. When changes are made to the main procedure (top), those changes can cascade to the sub procedures of main, and the sub-sub procedures and so on, where the change may impact all procedures in the pyramid. Object oriented programming is meant to address the difficulties with procedural programming. 8/24/2022 C ,C++ and UML Basics 14 The main difference 8/24/2022 C ,C++ and UML Basics 15 Comparison Procedural Oriented Object Oriented Program is divided into small parts Program is divided into small parts called ‘Functions’ called ‘Objects’ Global and Local data Has access specifiers : Public, Private, Protected Doesn’t have any proper way for Provides data hiding and security hiding data Eg: C, VB, FORTAN Eg: C++, JAVA, VB.NET 8/24/2022 C ,C++ and UML Basics Comparison 8/24/2022 C ,C++ and UML Basics 17 Session-2 8/24/2022 C ,C++ and UML Basics 18 Topics covered I/O Operation Data types Variable Static Constant Pointer Type conversion 8/24/2022 C ,C++ and UML Basics 19 I/O Operation C++ I/O operation occurs in streams, which involve transfer of information into byte It’s a sequences of bytes Stream involved in two ways It is the source as well as the destination of data C++ programs input data and output data from a stream. Streams are related with a physical device such as the monitor or with a file stored on the secondary memory. In a text stream, the sequence of characters is divided into lines, with each line being terminated. With a new-line character (\n). On the other hand, a binary stream contains data values using their memory representation. 8/24/2022 C ,C++ and UML Basics 20 Stream in C Text Stream Binary Stream 8/24/2022 C ,C++ and UML Basics 21 Cascading of Input or Output Operators >OODP; 8/24/2022 C ,C++ and UML Basics 22 Reading and Writing Characters and Strings char marks; cin.get(marks);//The value for marks is read OR marks=cin.get();//A character is read and assigned to marks string name; Cin>>name; string empname; cin.getline(empname,20); Cout

Use Quizgecko on...
Browser
Browser