0% found this document useful (0 votes)
37 views30 pages

Call

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)
37 views30 pages

Call

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/ 30
Noble Series | 11 process is known as Enca feature of a class. Class contains both data and fun sible from the outside world and only those functions which are Sie a acces ‘each other without knowing the details of their data fl °“"<-"+ sn the class can access the data. . " i le unit (class) is encapsul Se ee eee Storing data and functions ina sing of a class. A class must be instantiated snot be accessible tothe outside world and only those functions eames : f same class canbe in existence at anyone lime, are stored in the lass can access it ‘Object is a collection of number of entities. Objects take up space 5+ snce, it is the process by which object of one class acquire ‘Objects are instances of classes. When a program is teract by sending messages to one another. Each, or features of objects of another class. The concept of \dd additional ;nipulate the data. Objects any details of each other’s data or code. features to an Instance of ‘za new class from the existing one. The new class [object = abs) .d features of both the classes. is a part of the class flying bird whic! characteristics explicitly. However, by use of inherit need only define those qualities that make it unique withi can inhertits general attributes from its parent. Anew sub-class inherits of the attributes of all ofits ancestors. 6. Polymorphism ‘A Greek term means to take more than one form. An different behaviours in different instances. The the operation. sjects belonging to member of class fruit Operator Overloading Function Overloading 7. Dynamic Binding Dynamic Refers to lit with function ion is called binding and when itis take place at run time called gr 12 | Noble Series 8. Message Passing G1 Message Passing: The process by’ th other obj Noble Series | 13 wust follows enough it may be. To follow Jet the rule because of implemen for the data/information n whi to create an object at comy ‘ented say's Always Object must ime. Due to this reason and run time be exist at ru C+ is unable to produce performance base output. |. In C+ it is a programmer's responsibility to take care about MF nemory management, So itself it is one of the ‘complex work of be treated as is object oriented approach of solving a problem? How iffer from procedure programming approa eee (DBRAU-2013) nodular structure for programs ff Y it good for de! abstraee datengnel riented pears ing sprees ry simi ioe sare hidden and the uri RaSh uman solves daily problems. It consists o! s objects and how to use these objects in the correct sequence problem, In other words, object-oriented problem solving ‘of designing objects whose behavior solves a specific be created with P provides a good framework for code librar fed software components can be easily ada ied by the programmer. Go four steps. They are: entity the problem, nse ee 2 dete jst net fr ho Se 3 ety masageso Be senha oe ea Create a sequence of messages to the objects that solve the 's we take some important poi woth cp 1; Problem Identiffeation ~ Compute the sum of two numbers 3 printout the result. and everything must be in i cation - Identify objects needed to solve part of C++ while writing code we can use either C Sle or C++ (Object oriented style) or we can go f first number (object) . second number (object). Noble Series |15 jented approach does give the ability to reduce some of the major systems, such as maintenance and code. Here are some of the benefits of s.message is the valuc (aM. object-oriented approach Receiver object and jenance: The primary goal of object-oriented ‘the assurance that the system will enjoy a longer e-receiyer objects fe while having far smaller maintenance costs. Because most of bject-message the processes within the system are encapsulated, the behaviors may be reused and incorporated into new behaviors. Real-World Model Object-oriented system tends to model the real world in a more complete fashion than do traditional methods. Objects are organized into classes of objects, and objects are associated with behaviors. based on objects, rather The Power of Reuse processing. important features of object-oriented programming existing solution to solve new problems, promise to be far more reliable than traditional systems, primarily has been solved using the OOP appro: because new behaviors can be “built” from existing objects. Because objects can be dyn lly called and accessed, new ‘objects may be created at any time. The new objects may inherit rributes from one, or many other objects. Behaviors may be inherited from. eae isses, and novel behaviors may be added is sent to the isan object (Num! + Num2), which ig luded to avoid any procedural languages can be reuse’ for reuse much easier When auser creates anew typeof widget the new object behaves ing new behaviors which are defined to the Difference between Procedural Programming and Object- Oriented Programming (OOP) Object-Oriented Programming (OOP) is different from procedural programming langu: i in OOP is grouped the purest sense, 1oW the system is defined, Theo Noble Series \17 ‘ect Oriented Programmin® Paradigm’? Explain f object oriented programming, ated Programming, Parsdigz igen is a model of 3, What is OD} problems compared 10 OOP uses classes which OOP uses a a level styles of programming that rely on user- | pes to provide a model : — ae fed programming, and generic prograt Oriented Programming Concepts: properties of the different objects that 3. Encapsulation: The process of combining: techaique because it reduces complexity 5. Imberitance: a feature that represents the “is a” relationshi to communicate with each other and with the hardware. 7. Messaging: Message passing isa form of communication in parallel programming and object-oriented programming. 8 Object: a self-contained entity that consists of both data ~ procedures to manipulate the data. 9. Po'ymorphism: A programming language's abi objects differently depending on their data 10. Procedare: a section of a program that performs a specifi task. Q4. What is the difference between C and C++? (DBRAU-12, 13) ‘Ans. Difference between C and C++ are as follows C Programming CH Programming he procedural| C++ is a multi-paradigm 2 paradigm language(procedural as well as object oriented) @BcAze) C Programming © is a function’ driven programming language C does not support overloading, concept C does not support namespaces concept not support exception handling| tured programming support inheritance, polymorphism, data| C language only support Early| binding C uses standard input, output} functions like seanf-and pri C is mostly used to develop system software Noble Series |19 CH Programming C++ is @ object driven programming language CPP supports namespaces concept. C++ supports Exception Handling, C++ is object oriented programming language. CPP supports inheritance, reusability, polymorphism, data. abstracti¢ CPP supports both Early and Late binding (C++ uses input function cin and ‘output function is cout. In ett we use ideas ion file. (C++ is mostly used to modal real life problem to program and use ‘to develop application programs. — C++ program has extension pp There is data abstraction. Not complete data is available to End. user ot << "Hello, World!"; getchO; »ble Series standard O1 we standard, ‘a cin and cout operator in CH? ‘message onto the screen. Noble Series \21 utput Stream (cout) lass and why do we need it when we are talking ‘bout “object oriented” Approach? (DBRAU-2013) output of a program points a ‘and the “insertion” oj #include void main() { cout << “Hella World!” getch(); a + tandard Input Stream (ci instance of istream indard input dev ‘ns. In object-oriented programmin, fthe met ject isa specific instance ofa class; it contains real values instead of lass isa template definition 1e class is one of the defining ideas of object-oriented rogramming, Among the important ideas about classes are: GA class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the super class. Subclasses can also define their own methods and variables that are not part of their super class. : The structure of a class ard its subclasses is called the class hierarchy. s is a specification of the state and behaviour of objects. In ‘ofa system, an object’s state is part of the system state and jour is part of the system behaviour. is specified as a set of attributes. O The behaviour is specified as a dictionary binding messages to methods where a method is a piece of executable code. The instances ofa class are objects. They are all different, but they share the features described by the class. of the message interaction structures defined by the collaborations. Classes (objects) Instance Properties: Belong to the object Functions of class ic uses vary across different programming ns of scoping. In many languages the scope item 2” fed Programming can solve moderately complex variable more flexibility. mn operator? Also define the operators suppor Noble: or Example SA assume variable A holds 10 and variable B holds 20 then: Operator] Description Example ‘Checks if the value of two operands | (A—=B)is not On is equal or not, if yes then condition | true. C++ Supports following type 1. Arithmetic Operators ; a oe ae Logical Operators ns I lecks if the value of two operands | (A != B) is tru Increment and decrement Operators aa is equal or not, if values are not ‘equal then condition becomes true. (Checks if the value of left operand is_| (A > B) is not ‘greater than the value of right operand, | true if yes then condition becomes true. [Checks if the value of left operand is | (A =B) is not, For Example: 4 ‘greater than or equal to the value of | true. Assume variable A holds 10 and variable B holds 20 then: right operand, if yes then condition Operator | Description becomes true: dds Two operands (Checks if the value of left operand is_| (A <=B) is tru Subtracts second less than or equal to the value of right ‘operand, if yes then condition becomes tors (4, &&, |] ): ng logical operators supported by C++ language Called Logical AND operator. | (A&B) is falsd IFboth the operands are non ‘ero then condition becomes true. (A()B) is true Called Logical NOT Operator. | (A && B)is cal true than or equal to Use to reverses the logical state | Less than oF equal to «SL Noble S15 operand. Ifa conditions | ue then. Logical ‘NOT operator | Noble Series |27 | ise operators supported by C: aa aes am H+ larpuage are ised i aim msc kama Ancona (a) Assignment Operators f ienmemd ye following, assignment operators Sup C+ language: Bir Example For Example: Sinary AND Operator copies a | (A & B) wil Operator | Description tif GoreRRaWaEe Pelt Guci | = ‘Simple assignment operator, both operands. ‘Assigns values from right Binary OR Operator copies a side operands to left side bit if it exists in either operand operand Binary XOR Operator copias (@ Increment and decrement Operators 4) the bit it is st in one operand For Example: but not both. ‘Assume variable A holds 10 then: Binary Ones Complement jperator iptic Operator is unary and has the + effect of “flipping” bits. integer value Binary Left Shift Operator. = Decrement operator, decreases ‘The left operands value is integer value by one ‘moved left by the number of (© Bitwise Operators: bits specified by the right Bitwise operator works on bits and perform bit b a ‘The truth tables for & |, and “are as follows: Bier Ree a laa tai left operands value is 0 0 0 moved right by the number of oa bits specified by the right rh fh operand. 10 : Conditional Operators (Ternary Operator) (2): | ‘Assume if A= 60; and B = 13; Now in binary format the : - be as follows: | a | B For example sizeof{a), where retum 4. Y aancee 28 | Noble Series Comma oper re med. The are the various types of access specifiers of base an example for each. ‘Ans. Access specifiers define the access rights for il another access specifier o apse 2 bers declared as Protected are accessible uses A Sequence g a Ee Spates Noble Series 29 Private: // private members go here Public: // public members go here Protected: // protected members go her 2. Encapsulation 3. Generic Classes Abstraction (@BRAU-2013,14,15 CSM201 (DBRAU 20: fare defined as pri ‘The public members of the class can be accessed fromm inside of the ee ee eee nl Noble Series | 31 Properties of the object that + (hewie Encapsulation Object ‘C+ generic classes and functions are ented using templates. ract data type and friend function. peu ae om clrsex(), xyz datal(20), cout<<“n data; datal show; xyz data?; ‘data2=datal; cout<<“\ndata} data} show(); xyzslong> datas(356432L); ou a ap, etch); bject 1 declaring a class and o a fhe syntax for declaring 4 members of a cliss are accessible only from within bers ofthe same class. You cannot access it ou from members of sand also from members of their derived classes, bers are accessible from anywhere where the lefined, you can declare objects of that type. The an object is the same as that for declaring any Access Specifier. Data members, Member Functions (){) ions, which have their declaration ‘and works on the data members of the class, ber functions can be: Access Specifiers: public: void get() 1/ defined inside class definition t couts<"Hello”s ds ) ATS Noble Series |37 pub ag MConstructor ‘NOTE: Consirictors an be defined lefinition or outside class definiti scope resolution (:) operator, ither inside the class ion using class name and ) Q.3. What are the co normal member funct or t constructor? Illustrate the pars the help of copy constructor. (DBRAI {Constructor declared Or 1a copy constructor and how is it attainted (DBRAU-2013, 15 & CSI // Constructor definition a special member function of a 1c create new objects of that class. ave exact same name as the class andi ‘or invoked when object gets created. Constructor do Gs ‘ot have return types, therefore they cannot retumn instance ofits class. A constructor has the same ni no return value. A constructor can have any number of p ‘a class may have any number of overloaded constructors. Definition: Constructors are special class functions which p ini tion of every object. The Compiler calls the Co whenever an object isc members after storage is al Dynarnie Constructor wstructor which doesn't tg =x; cout<>ay ‘cout<<"\nEnter the Second Number:"; cin>>b; } friend class sum; W class sum void add(abe al) .b; cout<<"\nSum="< class A int x; public: 40 { x=0; Hs J cout void main() _ for int i=0;1<100; i+) <<“Hello”<

You might also like