0% found this document useful (0 votes)
2K views203 pages

Oops Book

Uploaded by

pushpak84shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2K views203 pages

Oops Book

Uploaded by

pushpak84shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 203
Object Oriented Programming Using C++ SECOND YEAR DIPLOMA (Code : 22316) Reese SRS SN NOMA CCAM RSD SIL0LD) Semester III - Computer Engineering Group / Information Technology Engineering Group(CO/CM/IF/CW) [ smety as per new revised ‘T’ Scheme w.e.f. academic year 2018-2019 Harish G. Narula Formerly, Assistant Professor (Senior), Department of Computer Engineering D. J. Sanghvi College of Engineering, Mumbai Maharashtra, India. NDOLEA Pre t185/- | Price® Price €188/- | SIT ae TechKnowledge Sd Lane (Book Code : MDO133A (New Code : RMDOI4A)) u Object Orianted Programming using C++ (MSBTE) Table of Conten Syllabus Tople : Structure of C++ Program , Cow] See cree aed ToT TTT | 10 Structuro of C++ procrar® Chapter 1: Structured Programming with C++ qwaess6,697,W47 14110 1-29 | 1.10.1 Simple C++ Program Syllabus : Principles of Object Oriented Programming 4.102 Dynamic Inialization of Variables. ; ¢ Syllabus Tople : User dofned Data Types Unit Outcomes : Write simplo C++ program for soling the given expression using POP approach. 4.10.3 User Defined Datatype Teplos and Sub-Toples : Procedure Otnted Programming | | 1408: Enumerated Daa 99 = (POP) Verses Objoct Oriented Programming (OOP), Basic | | 1-11 letegrated Development Environment ‘Concepts of Object Oriented Programming and Object Oriented | | ¥ Syllabus Topic: Operators Languages, Applications of OOP, C verses C++, Structure of | | 1.12 Operators (W-17). Cera, Spl C+ poy, Tokers, KeywortVatates,| | 121 Unry Operas (95 S16, 17, WT) Constants, Basic data types, User defined data types, Type | | 1122 Binary Operators. casting, Operators, Expressions, ent Operator || 4423 Tomary Operator 1A Computer.. on 4.124 Assignment Operators 1.2 Programming and Programming Languages Wiae case es eee ve 13 Binary Number System... ‘ Sytabue Tope: Memory Management Operator. ont 19 14 Hoy 1 6/6n Proganmra Lanes —————-*6 | 4426 ony Manage peas 1.5 Procedure Oriented Programming (wes, 16, 517), (W-14, WA5,W-16, 5-17)... 1.10 Preedence and Associaiyof Operator. ¥ Syllabus Topic : Basic’ Cconcpt of Objet Oren 7 Sylabus Tople : Expressions. Programming and Object Oriented Languages... aliconeces 1.8 Basics of Object Orionted Programming (OOP) 4.18 Formatted and Unformatted 10 Functions 22 ‘and OOP Languages ($-14, We14.W-16) mom 18 | 4's 4 poymatted 10 Functions ¥ —_Syabus Topio : Proveckwe Oteried 1.18.2. Unformatted 10 Functions. Programming (POP) Verses Object Oriented 16 C++ 10 Techniques (W-15, S-16, S-17) Programming (OOF), C verses: ore wow TD 147 Manipulators 1.6.1 Procedure Oriented Versus Object Oriented 1.18 Basic Program Examples (W-15, S-17) Programming Language or ‘C’ Language ' . tie mee pormeny versie ¥ Syllabus Topic : Type Casting 4-7 | 1.181 Type Casting... 1-7 | 1.19. Exam Pack (Univesty and Reviow Questions). (6-14, We14, 8-15, $6, 5:17, WHT) nn ¥ Syllabus Tople : Applications of OOP. 1.82 Applications of Object Oriented Programming Chapter 2 : Control Statements 2-4 to 2-26 Language ($-14, $15, 8-16, WA8) _.g | Shaper 2: Control Statements ___2-1 0.2.26, 1.7 Features of C Programming Language 1.8 C++as.a Superset of C Programming Language ¥ Syllabus Topic : Tokens... 19 Tokens of C/C++... 1.9.1 Character Set of C/ C++. 1-7 | | Sytabus : Principles of object Oriented Programming Unit Outcomes : Write POP based C++ program using decision making andloop structure forthe givensiuation. Topics end Sub-Topics : Control Stucturés: Decision making Statements and Loops 7 Syllabus Topie : Control Sructures : Decision ‘making Statements and Loops... 2.1 contol Stuturs : Dacian raking Statements ¢sylabun opie: Base Ola Types 194 Data Typos. Syllabus Topic : Constants and Variables... 195 Constants and Variables. 1.96 Escape Sequences . 197 Operators. 22 se 22.1 Programs Based on for Loop. tr | 222 Nested or Loop... 141 | 23° white and dowhite Loops “41 | 23,1 Programs Based on wtile and do-whle Loop. Qblect Oriontod Programmi 2a aaa a Chapter 5: Classes and Objects 5-1 to 5-30 ‘Syllabus : Classes and Objects: 20 Unit Outcomes 27. Some More Practes Programs. Develop relevant fiond functions to solve the given problem. 2.8 _ Exam Pack (MSBTE and Review Questions) Write C++ program to use array of given objects. ver sl Hee: Function, Arrays and Strings _3-1t03-27 | | Wrte C++ program 10 create the glen object using 5 constructor. Catone en nn eta oes ‘Write program to delete the given object using destructor in va C++ program. ‘Wste POP based C++ program using aay to solve tho gen ‘Toples and Sub-Toples ae (Class and Object: Introduction,“Spectying a Class, Accoss pa nd teenie ‘Spector, Defining Member Functions, Creating Objects and cera Memory Allocation for Objects. oa Static Data Members, ‘Static Member Function, Friend ‘Scop Resolution Oporatr, : 31 Functions. 9:2 Programs Based on Function. 33 - Recursive Functions... ¥ Syllabus Tope : Arrays in C4. 34 Amays(s-17). 3.5 Mutti-dimensional Arrays. ’ 31 | | Array of Objects, Objects as Function Arguments. 3 | | Concepts of Constructors, Types of Constructors. Multiple Constructors in a Class, Constructors with Default Arguments, ‘Object Oriented Programming (W-14, 8-16, W-17), Y Syllabus Topte : Ciass and Object: Introduction. 38 5.1.1 Class and Object: introduction a7 (S14, W-14, Wet6, w.17), 374 Y Syllabus Topic : Access Spec 372 51.2 Access Spectiors . ‘ 373 v 374 513 38 oa ‘Syllabus Topie : Creating Objects. ‘and Memory Y Syllabus Tople : Scope Resolution Operator... location of Objects (W-14, 8-15, W-16, -17). 3.8 Storage Classes and use of Scope Resolution 51.4 Creating Objects and Memory Operator. : S10 Exam Pack (MSBTE and Reviow Questions)... 327 |.” Chapter 4: Structures and Unions 4110 412 fat Syllabus : Principles of Object Oriented Programming 8214 et Outcomes: Usa te stuctre in C++ program for sching 522 the given problem Toples and Sub-Topics : Structures in C++ 523 Y Syllabus Tople : Structures in Cay. a 41 Stuctures (8-14, W-14, W.16,5-17, W-17, 42 Amays of Structure Variable. sa 43° Nested Structures. 531 $4 URINE : Sa2 45 Exam Pack (MSBTE and Review Questions) i 33 a Object Orlentod Programming using C++ (MSBTE Table of Contents 7 Syllabus Tople: Constructor with Default Arguments. we 518 34 Constructors with DolauitArgumonts (6-16, w.17, 8:17, 518 4% Syflabus Tope: Destructors 519 5.4 Destructor (S-14, W-16, W-17) 519 % Syllabus Tope : Friend Function. 520 55 Frond Function (14, W-14, S16, We16, WT) ann 5:20 ¥ Syllabus Topic : Static Data Members, Static ‘Momber Function om ¥ Syllabus Tople : Aray of Objects. Static Mombors (W-14, W-16, W-17) 57 Array of Objects (8-14, W-14, W-16, §-17).. 7 Syllabus Tople : Objects as Function ArguMants.. 5-28 Objects as Function Arguments (W-14, S-1¢ 526 9 Exam Pack (MSBTE and Review Question)... 6-1 to 6-22 Unit Outcomes Explain given type of inheritance based on ts characteristic. Implement given type of inhertance in C++ program. Wilte C++ program using vitual baso class. ‘Use constructor in the given derived class. Topics and Sub-Toples Introduction to Inhertance, dofining a dered cass, Visbity Modes and Etfects ‘Types of inherttance ~ Single, muitlvel, mutiple, hierarchical, yb. Constructors In derived ass v cs “ 61 a1 a1 Syllabus Tople : Introduction to Inherttance, Defining Derived Ciass.. 1 Inrttance ($-14, $-16, W-16) . Syllabus Tople : Visibilty Modes and Etfocts Visibility Modes and Etfects (5-14, W-14, $15, W-15, W-16, $16, 17). Syllabus Topic: Single Type of Inhertance. a4 1.2 Single inheritance (W-15, W-16, S17) ‘Syllabus Tople : Constructor In Derived Ciass. 1.2.1 Constructor in Derived Class (S-15, W-15, S-16, W-17). ‘Syllabus Tople : Mult Lovel Type of Inhertance... ‘Mut Level Inhettance (8-14, W-14, 6-15, $16, W-16) Syllabus Tople : Multiple Type of Inherttance... ‘Mutiple Innerttance (6-14, 5-15, $-16, W-16, $17, W-17). 13 14 ————— Syllabus Tople : Hybrid Type of hortane nnn 48 81.5 Hybrid Inhorttance (8-15, 8-16)... 13 6.1.6 Problem In Muliplo and Hybrid Inhertance (W-15)....6-15 ¢ Syllabus Topic : Hierarchical Inhortance o18 6.1.7 Hlorarchicl Innertance (S-14, $15, 8-17) 16 62 Exam Pack (MSBTE and Review Question) nnn 20 ‘Chapter 7 : Pointers & Polymorphism In C++ 7-1 to 7-37 Compile time Polymorphi operator overloading, overtoading of unary and binary ‘operators, Rules for operator overloading. ‘Run time polymorphism : Virtual functions, rules for virtual functions, pure virtual function. Syllabus; Pointers and Polymorphiem In C++ Unit Outcomes: Create C++ programs to perform the ‘operations using pointers. Use function overloading to solve the given problem. Use operator overloading to solve the given problem. Implement run time polymorphism using virtual functions in the given C+ program. Topics and Sub-topics Concepts of Pointer : Pointer dectaration, Pointer ‘operator, address operator, Pointer arithmetic. Pointer to Object : Pointer to Object, this pointer, Pointer to derived class. Virtual Base Class and Abstract Class Introduction of Polymorphism, Types of Polymorphism, : Function overloading, given arithmetic ‘Syllabus Tople : Concept of Pointer: Pointer Dectaration... Points ($-14, $-15, W-15, W-17) ‘Syllabus Topic : Pointer Operator, Address 7A4 7.2 Programs Related to Pointers... 7.2.1 Simple Referencing and De-referencing using 72 722 73 ¥ Syllabus Topic : Pointer Asthmatic. 74 72.3 Pointer Asthmatic: Increment and Decrement Operators Operation on Pointer Variables (W-14, $15, S-16)....7-4 724 — Pointorto Array (W-15, W-17).. ns 7.2.5 Passing Pointers to Functions... 72.6 Cally Value and Call by Reference (W-14, 8-18, WAS, S16, $-17, W-17). ¥ Syllabus Tople : Function Overloading... ve TAO 7.3 Function Overloading or Function Polymorphism 1. Ing C++ (MSBTE) _4 Table of Contents Fo Cog Ne OTE) ener aeraenn esse ote Of Contents, Constructor Ovortoading UNIT V ] (S18, W4, 8-18, was, S16, 5-17) se TAS er neny TOPE Operator Overeating, Cveroedng | og, Overload = Filo Operatio 81t06-13 t Unary and Binary operators, les Operator Chapter: Filo Operations__ at to 13 oa me Serrrernnnnnns 4 | TS a oup 2 File Operation Say epatasea(Ovetadng of Una and Unit Outcomes : Identily relevant class for performing tea Paras) tho given file operation, Write statement to open and eS IRMAG W816, 557, HEAP onsite || Me OER siven fio in Ces, Develop Grr progem to $yabus Topic: nreductono Plymapiem, Perform readiwrite operation front the given fl. Pei caeere pene vr Toples and Sub-Toples : C++ Stream Classes , . Wine Classes for Filo Stream Operations, Opening Files, Sete tte 18 wets, wets, 18,47, wa7)..729 | | Gaston et Fle oa erator Writing to Files, ¥ —Sylabus Tople : VitualFunctons, Puls for Detection of End of File, Filo Modes Virtual Functions, Pure Vitual Functions ~Ta4 | 7 ytabunTople:Cx+ Brees Geveo a 7541 yam Binding using Vital uncon 81 Concaptot Steams and C++ steam Casses.. 4 anaen tine Polgmaism ¥ sylabus Tople Casses for Fie Steam (8-44, WIS, $16, WB, WAT) on 724 Tan : Pa 752 Rus for vita Functons 44, WB) summa? 24 | 14 prromenone a Jaz CiabusTople: PotertoDetWed Cnn 728 | 81.2 Advantages of Steam Cassese 782.1 Polnterto Derived Cass Y —_Sytabus Tople: Fie Modes, Opening Fle, (6-14, w-t5, 8:16, 8-17, 17)... 728 Ciosing Fis sc ¥ syllabus Top 82 File Management Functions and Fe Modes Glass a (©pening end Cosing Fes) 753 Vital Baso Class and Abevacs Oc _ | %_ Siltabus Topic: Reading trom and Witting to Fle, (14, 8:10, 17). 729 | 821 Reading tom and Witingo Fle... ¥—— Sylabus Tople: this Pointr.. 730 | ¥ Syllabus Tople: Detection ot and of Fo 7.6 this Pointer (S-14, W-14, W-15, $-16, $-17,W-17)....7-20 | 822 Detecting End of File Y Syllabus Tople : Pointer to Object. 7.31 | 83 Random and Binary File Handling. 77 Pomerwoed 84 cepongand or Handing Dung Fo (W815, WAS, S16, S47, WT) ocrrnnin HH | gg Examen aaa 78 Bram Pack (MSBTE and Review Questions) 794 | ge Exam pack gute anderen v0 81018 nnn BAZ Lab Index F Statement, ‘Name of the Program Page Nos. ‘Statement 1 Develop minimum 2 programs. using constants, variables, arithmetic expression, Lt operators, exhibiting data type conversion. * Program 1: Write a © / C++ program to accept a number and display its ut square. * Program 2.: Write a program to accept basic salary from the keyboard. | L-t Calculate the gross salary that includes basic salary, 50% DA and 40% HRA. * Program 3: Write @ program to accept a number and display ts equivalent | U2 ASCIl using type casting. ‘Statement 2 Develop a program toimplement decision making statements (if-else, switch). Le * Program 4 : Writo a program to check i the entered number prime number or | L.2 not. * Program 5 : Write a program to check if the entered number Armstrong or Le not. * Program 6: Write @ program to daplay the class according tothe marks scored | Lg by a stu Put and the class is dis rr Objoct Oriontod Programmirig using C++ (MSBTE) 5 Statement Name of the Program ‘according to the following range : Marks Class: 70-100__| Distinction 60-69 - | First Closs 50-59 | Second Class 40-49 | Pass Class 039 Fail | a + __ Program 7 : Write a program to display a user entered number in words. Statement 3 | Develop a program to demonstrate control structures (for, while, do-while). La ‘+ Program 8 : Write a program to display first n elements of Fibonacci series. La ‘* Program 9 : Write a program to calculate the value of the following series. Ls Ve eget end ‘* Program 10 : Write a program to count the number of digits in a user entered | LG number. © Program 11 : Write @ program to find the sum and product of all the digits ofa Lg user entered number using the do-while loop. Statement | Develop a program to Implement t-dimension array. 6 © Program 12:: Write a program to sort numbers in ascending order. L6 OR Write a program to implement bubble sorting algorithm for sorting numbers in ascending order. Statement | Develop a program to perform matrix operations using rhulti-dimensional array. Le Program 13 : Write a program to multiply two matrices using a function. Le Statement 6 | Develop programs that implements a class and use it with objects. Lo * Program 14 : Write a program to find area of circle using Object Oriented} L190 Programming such that the class circle must have three member functions namely : (a) read() to accept the radius from the user. (0) computed for calculating the area. (c)_display() for displaying the result, Statement7 | Develop programs that implements a class and create array of objects. ut * Program 15 : Write a program to declare a class ‘staif having data members as | L-t ‘name and department. Accept this data for 10 staffs and display names of staff that are in cm department. Statement 8 | Write a program to implement friend function, Lie * Program 16 : Write 2 program to add two complex numbers using a friend | L-12 function, Statement 9 | Write a program to implement inline function. Lis * Program 17 : Write @ program to find area of circle using Object Oriented | L-13 Programming such thatthe class circle must have three inline functions namely : (2) read{) to accept the radius from the user. (©) compute() for calculating the area, (c)__display() for displaying the result, Statement 10 | Write @ program to implement all types of constructors Lis (constructor overloading) with destructor. * Program 18 : Write a program to find area of circle using Object Oriented Lag Programming, The value of the radius must be accepted from tho user in the ‘main program and pa: sed to the parameterized constructor and the class circle er Object Oriented Programming using C++ (MSBTE) _6 Table of Contents, Statement Page Nos. must have two (2) compute() for calculating the area. (b) display() for displaying the result. * Program 19 : Write a program to find area of circle using Object Oriented La Programming. The value of the radius must be accepted from the user in the ‘main program and passed to the copy constructor and the class circle must have two inline functions namely : (2) compute() for caloulating the area. (©) display() for displaying the resu. + Program 20 : Write a program to demonstrate the destructor. Lis Statement 11 | Write a program for Implementing single inheritance. Las + Program 21 : Write @ program to add two numbers using single inheritance | L-15 ‘such that the base class function must accept the two numbers from the user and the derived class function must add these numbers and display the sum. Statement 12 | Write a program for implementing mull level Inheritance. lar * Program 22 : Write a program to calculate percentage of a student using multi} — L-17 level inheritance. The base class function will accept the marks in three subjects from user. A class will be derived from the above mentioned class that will have 8 function to find the total marks obtained and another class derived from this will have functions to calculate and display the percentage scored. Statement 13 | Write a program for Implementing multiple inheritance. LB * Program 23 : Write a program to define the following relationship using multiple | L-18 inheritance. Statement 14 | Develop minimum | program to demonstrate Pointer to object. L19 * Program 24 : Write a program to declare a class birthday having data members | L-19 day, month and year. Accept this information for § objects using pointer to the array of object ‘Statement 15 | Develop minimum | program to demonstrate Pointer to derived class. L-20 *__ Program 25 : Write a program to demonstrate use of pointer to object. L20 ‘Statement 16 | Write a program to demonstrate operator overloading for Unary operator. Lar ‘* Program 26 : Write a program to negate the values of two variables contained | L.2t inan object. * Program 27 : Write a program to negate the values of two variables contained | t.o4 in an object by overloading the operator unary negate Le. Statement 17 Write a program to demonstrate operator overloading for Binary operator, Lee * Program 28 : Write a program to overload binary operator “+=" to add two| 1-22 complex numbers. ‘Statement 18 | Write a program to demonstrate function overloading, L23 * Program 29 : Write a program to add two numbers using function overtoading | L-23 such that one function adds two integers, second function adds two float humbers and the thid function adds a float number with an integer. ‘Statement 19 | Write a program to read and write data to and from a file. Lea * Program 30 : Write a program to wite and read string, integer and foat fromto | L.24 a [aleTs} Structured Programming with C++ | Syllabus . Principles of Object Oriented Programming > Unit Outcomes Write simple C++ program for solving the given expression using POP approach. > Topics and Sub-Topics = Procedure Oriented Programming (POP) Verses Object Oriented Programming (OOP) | = Basic Concepts of Object Oriented Programming and Object Oriented Languages, Applications of OOP — Cverses C++ , Structure of C++program, Simple C++ program =” Tokens, Keyword, Variables, Constants, Basic data types, User defined data types, Type castin Operators, Expressions = Memory Management Operator. 1 Computer — A computer can be visualized as a system with Inpu/Output (UO) devices, Central Processing Unit (CPU) and the memory = The computer as seen by you can be as illstated in the | interconnected as shown inthe Fig. 1.1.2. This isthe hardware Fig. 1.1 view of a computer. Fig. 1.1.2 : Hardware structure of compoter programmable system. It is a system that can be programmed — As a programmer, the computer can be seen. as a | by the t Koyboard ae Fig. 1.1.1 : Computer 1.2. Programming and Programming Languages = Besides other units, it is made of 2 monitor | (standard display uni), CPU (Central Processing Unit) and | — Programming isto give the machine alist of steps to perform | keyboard (standard input device). ipenarS ae (MSBTE) _ the system to which the programming is done is a com ‘han itis called as Computer Programming The program of any system has to be done in the language understood by tht system, ~ A digital system ike computer understands only binary language (which consists only of Os and 1s), also called as ‘machine Language, Bu, programming in machine language is almost impossible for a human being. Hence, the ‘manufacturers of the processor develop a language called as assembly Language. Assembly language is simpler than the machine language, but imaking huge software using this is again very difficuh. Jt includes the fol ‘Ap English language word that specifies the operation to be performed and ‘The Operands, which are the data on which the peration isto be performed. Which was there namely ‘0° and‘, ~All numbers and characters ae tobe Presented using *Q° op “V'only. Structured Programming with C++ SOT Ce ‘The conversion from binary to decimal and decimal to binary ‘can be done as shown below with examples. Decimal to binary : ‘The steps to be followed for converting a decimal number to a binary number are : © Divide the decimal number by 2. © Note down the quotient and remainder as shown in the example below. © Repeat the above procedure till the quotient is zero, © The last remainder is the MSB (Most Significant Bit i.e. the bit with highest weight) and the first remainder is the LSB (Least Significant Bit). Eg Oro = (Pz ‘means the number 5 in decimal (base 10) number ‘System. Base 10 means 10 different representations 0 10 9, Or (hr means the number in binary (base 2) number system, Base 2 means 2 different representations O and 1, 2|s Quotient 2/2 1+-Remainder’ 2h1 0 0 1) =G0n, Fig-131 ~ Binary to decimal: The steps to be followed for converting a nary number to a decimal number are Ee.11100), = POM soy ony ~ 1648444040208, ~ This is how your decimal data comp data in Sore 5, butt stores 1 teem You Peal operations that are perform ovject ovoniod Programming using C++ (MSBTE) 1-3 Structured Programming with C++ 1. AND: The outputs 1 if and only if A AND B (A & B being als the inputs are 1. alia A(INPUT) BUNPUT) YOUTPUT) 1 o 0 oO ° ° 1 0 Note: We can prefix 0's to a number in binary as in 1 A 5 decimal. Here, (014), Is written to make it 3 digit 1 Now,5&3 2 OR: The output is 1 if and only if A OR B (A & B being the inputs) 1 aon, AGNPUT, boneur | _yourrun cor o 0 ° 000), “ z z Note: Wis bitwise AND operator i. it works on each bit z o 1 as shown in the above example. u 1 1 (OOD, = 0x2+0x2' 41x? 3. NOT : The output is NOT A ( A being the input) ie. = Do eee OS Oo = Ow AQINPUT) ‘Y(QUTPUT) 2 BAND 10; 0 1 i 5 2}13 4, EXOR : The output is 1 if and only if EXCLUSIVELY A 2le 4 ORB( A&B being the inputs) are 1. 2{3 0 | a3 =«10n, ACNPUT) B(INPUT) Y(OUTPUT) 2ii 4 o 0 ec oi. o 1 1 1 o 1 1 1 o zoe) ‘Some examples of performing these operations on the binary 215 0 data are given below 2}2 1 | (0 =C010), 1, SAND3: 2)1 0 In‘C’ programming this is written as $ & 3. 04 2\s Now; 13 and 10 2/2 1 f @po=(on, (100, 2{1 0 &(1010),. o1 (1000, Joct Oriontod Programming using C++ (MSBTE) (1000), = 12940 27+0%2' +02" = (B)ip (D&M = By 2 70R6: 1n°C* programming, this is written as 716. 2]7 2)a4 2/1 1 | Mp=ain, on 2/6 2/3 0 2/1 1 | ©p=d10, O41 Now: 7 OR 6 an, 110, arp, (UD, = xP et xaterae = Mp Mol Oe = My 4. SOR2: =o, Oey | @o= (010), 14 Structured Progr Now, 5OR 2 aon, 110, ain, (MD, = 1x2 41x2'41%2° Ow Mo Go! Dio 5. 6EXOR3: In, this is written as 6 63 2/6 2/13 0 n=(110), vos 1 + @p= Om, o1 | Now: 6EXOR 3 aon, *@1y, Gon, (on, = 1x240x2' 4159" = Oy Ow Oy = Sy © Nors: In, this is writen as ~3 2]3 241 | 1 T pee, 0011 11100 Now; ~3ig Cbject Oviontod Progiamming using C++ (MSBTE) 15 vustured Programming with C++ The data may be of more than 2 bits and hence you will get the output depending on the size of data, [wow 1) 2) In computer binary language you will get this value as (~ 4)4o. 3) Hence if you say ~(10);o, you will get ~ (14) and s0 on. 14 History of C/C++ Programming Languages = C programming language was developed by Dennis Ritchie at the Bell Laboratories of AT & T. He developed a complier that can convert the HLL namely C to the machine language that Can be understood by the processor or the computer. But his compiler could understand only if certain rules were followed while writing the program. ~ We need to understand and know these rues to program our computers,using this programming language. C was the most popular programming language. Some other languages had become popular after some time of evolution of C. This was because these other programming languages were object oriented i.e. more significance was siven to object. . ~ While ‘C’ was a procedure oriented language i.e. more significance was given to the procedure to perform a task. = CH which is an object oriented programming language was then developed again at Bell Laboratories by Bjame Stroustrup. Eater, this language was called as C with classes, but was later renamed as C+ in 1983. = Object oriented and procedure oriented concepts of a programming language will be gradually seen in this book. Some of these concepts will be cleared in this chapter itself while some will come as you reach towards the end of this book. 5 Procedure Oriented Programming D> (W-14, W-15,W-16, -17) 0.15.1 Write any two characteristics of procedure oriented programming. (Ret. Sec. 1.5) (We14, 2 Marks) Q.1.5.2 List any four features of POP. (Ret. Seo. 1.5) (W-15, 4 Marks)| 0.1.53 In procedure orlentod programming all data are shated by all functions, Is this statement TRUE? Justify your answer, (Ref, See. 1.6) (W-16, 4 Marks) What are the features of procedure oriented programming? (Ref. Sec. 1.5) (S-17, 4 Marks) 0.15.4 = A procedure oriented programming language is one in which procedure ie. method or functions are given more significance. Here, one function calls another. — There can be global variables and local variables to cach function Fig 1.5.1 shows how a procedure oriented programming operation. — In this type of languages the task is divided into smaller tasks fr sub tasks called as procedures or functions or methods. ‘Any function can be called at any instant. = There are global and local variables as seen in the Fig. 1.5.1 ‘The global variables can be accessed by all the functions, while the local variables are local to the corresponding function, =A procedure oriented programming language follows top bottom approach, ~ Top bottom approach refers to approaching to a problem as a big task or as a whole. Then dividing this task into small instructions or operations. Hence, intially the task is broken into small tasks and then these smaller tasks are written in detail, Global data | + taaintaneton | toca data Fundton Fig. 1.5.1 : Structure of a procedure orienied Programming language = The disadvantage of such type of programming is that i is difficult to trace which functions are. using a data and also error correction is difficult G — C programming language is an example of procedure oriented language. =— SS Syllabus Topic : Basic Concepts of Object Oriented Programming and Object Oriented Languages 1.6 Basics of Object Oriented Programming (OOP) and OOP Languages D> ($-14, w-14, w-16) @.1.6.1 Describe any four basic concepts of OOP. (Ret. Sec. 1.6) (8-14, 4 Marks) Q.1.6.2 List any four object oriented languages. (Ret. Sec. 1.6) (W-14, W-16, 2 Marks)| ~ Object oriented programming as the name says gives more significance to the objects which has data and functions builf around it. — The data of the object can be accessed by the functions associated with it. The functions of one object can access the data of another object through the functions ofthat object. Object oriented programming uses bottom vp approach Wherein the smaller tasks are first dealt in detail and gradually creating the entire huge system. Object A Object B [a] Fig. 1.6.1 : Structure of an Object Oriented Programming (ZF ovject oriented Programming using C++ (MSBTE) 1-6 Structured Programming with Cr+ Fig. 1.6.1 shows the structure of a object oriented programming language. CH, Python, Ruby, C# and Java are examples of object oriented programming languages. ‘There are few important terms related to Object Oriented Programming that we need to understand. First the concept of, ‘objects and classes and then the specialties of OOP viz. Data Abstraction, Encapsulation, Inheritance, Polymorphism, etc. Let us understand them one by one. Class. 2. Object Data abstraction 4, Data encapsulation Inheritance 6. Potyntorphism Its a type or a category of things. It is similar toa structure ‘with the difference that it can also have functions besides data items. A structure, we have seen, can have only data variables but a class can have data members as well as function members. 2 Object It is an instance or example of a class. You can imagine it to be similar to a variable of class like we havé a variable of a structure, 3. Data abstraction Data abstraction is ike defining or abstracting the object according to the required parameters. For example; if there is 8 class for circle we need to just define the radius of the object of ths class. We néed not bother about anything else of that object. 4. Data encapsulation ‘The data of an object is hidden from other objects. This is called as encapsulation. Encapsulation is achieved by putting data and functions associated with it into a class. 5. Inheritance ° ‘The mechanism of deriving the properties of one class into ‘nother class is known as inheritance. We will see in detail about this concept in a special chapter dedicated on Inheritance. Structured Programming with Cr+ Foviect Orionted Programming using C++ (MSBTE) 1-7 > 6 Polymorphism Poly refers to multiple and morph refers to different forms. Hence, polymorphism means multiple forms of the same thing. This topic will also be covered in detail in the later chapters ‘Syllabus Topic : Procedure Oriented Programming (POP) Verses Object Oriented Programming (OOP), Cverses Cr+ ES Procedure Oriented Versus Object Oriented Programming Language or ‘C’ Language versus ‘C++’ Language D (S-14, W-14, $-15, S-16, S-17, W-17) 1.6.1 @.4.6.3. Differentiate between POP and OOP (any four points) (Ref.sec.1.6.1) (S-14, W-14, $-15, S-16, S-17, W-17, 4 Marks) Sr.| Procedure Oriented Object Oriented No| Programming (POP) | Programming (OOP) like like

You might also like