I assignmnt(oops)


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

I assignmnt(oops)

  1. 1. 1--THE BENEFITS OF OOP.Object Oriented Programming is amethod of implementation in whichprograms are organised as co-operativecollection of objects each of whichrepresents an instance of someclasses and whose classes are allmembers of hoerarchy of classes unitedthrough the propertycalled inheritance.OOP offers several benefits to theprogram designer and the user. Object-orientationcontributes to the solutions of manyproblem associated with thedevelopment and quality ofsoftware products. The new technologypromises greater programmerproductivity, better qualityof software and lesser maintenancecost. The principal advantages are:1. Through inheritance, we caneliminate redundant code and extendthe use of existing classes.
  2. 2. 2. We can built programs from standardworking modules that communicate withone another ratherthan, having to start writing the codefrom scratch. This leads to saving ofdevelopment timeand higher productivity.3. The principle of data hiding helpsthe programmers to built secureprogram that can’t beinvaded by code in other parts of theprogram.4. It is possible to have multipleobjects to coexist without anyinterference.5. It is possible to map objects inthe problem domain to those objects inthe program.6. It is easy to partition the work ina project based on objects.7. The data-centered design approachenables us to capture more details ofthe model in animplementable form.8. Object-oriented systems can beeasily upgraded from small to largesystem
  3. 3. 9. Message passing technique forcommunication between objects make theinterface descriptionswith external system much simpler.10. Software complexity can be easilymanaged.11. This language helps for softwaredevelopment, which are more reliable.12 .One should not use to check errorcode after each potentially call.13. Some of its application includesdesign issues.14. It is the enhanced form of Clanguage.15. It is statically type language.16. The most important Feature is thatit’s procedural and object orientednature.17. As this is the more developed formof c, it maintains the aspects if clanguage yet it hasthe feature of memory management.18. C++ is much suitable for largeprojects.19. It is one of the fairly efficientlanguages.
  4. 4. 20. It divides the problems intocollection of objects which providesservices and can be usedto solve a particular problem.21. Code re-use (Polymorphism,Generics, Interfaces)22. Code extensibility23. Catch errors at compile timerather than at runtime.24. Reduces large problems to smaller,more manageable ones.25. Fits the way the real world works.It is easy to map a real world problemto a solution inObject Oriented code.2-- write a short note on class andobjects.Object Oriented Programming is amethod of implementation in whichprograms areorganised as co-operative collectionof objects each f which represents aninstance of some
  5. 5. classes and whose classes are allmembers of hoerarchy of classes unitedthrough the propertycalled inheritance.A class is a user defined data-typewhich is a collection of data memberand functions.Class is created in oop to keep ourdata secure which cannot be accessedwithoutpermission.The objects with datastructure(attributes) andbehaviour(operations) are groupedinto a class. All those objectspossessing similar properties aregrouped into the same unit.it can solve real world problems. Thedata members and member functions canbe private orpublic in a class. There can be manymethods in a class which can beaccessed with itspermission to solve real worldproblems. The data members of a classis by default private. The
  6. 6. data members declared in a class inaccessed in a class only and itcannot be accessed outsidethe class. The member functions canalso be accessed with creating anobject which takes apermission from class to access it asper user requirement.syntax of class is as under:class(keyword) classname{data membermember functions or methods};For e.g: Create a class which ad 2numbers.#include<iostream>using namespace std;class add{int n1,n2;public:void setdata(int a,int b){n1=a;
  7. 7. n2=b;}int add(){int sum;sum=n1+n2;return sum;}void display(){cout<<"Addition="<<add();}};Objects is an entity that can storedata and send and receive messages. Itis aninstance of a class.Objects are uniquely identifiable by aname. There can be as many as objectsfor aclass as per the requirement of users.Each objects has its own properties.Different entitiesof a problem are examinedindependently. These entities arechoosen because they have some
  8. 8. physical or conceptual boundaries thatseparate them from rest of theproblem. The entities arerepresented as objects in the program.The goal is to have a clearcorresponding betweenphysical entities in the problmedomain and object in the program. anobject can be a person, aplace, a thing, etc.syntax of object is as under:}objectname;orint main(){classname objectname;}for e.g: create object to access abovemethods of class add.int main(){add a1;
  9. 9. a1.setdata(10,25);a1.add();a1,display();return 0;}3--State difference between methoddefined in the class and outside theclass.Its differences are as follow:The scope resolution operator is usedin method defined outside the classwhere as, inmethod define in the class no need touse scope resolution operator. (::)In method defined outside the class,prototype or function header is to bedeclared inthe class where as, in method definedin the class methods body is also tobe mentioned withits prototype.
  10. 10. The example of method within the classis as under:#include<iostream>using namespace std;class num{int n1,n2,n3;public:void setdata(){cout<<"enter numbers";cin>>n1>>n2>>n3;}void display(){cout<<n1<<n2<<n3;}};int main(){num n;n.setdata();n.display();return 0;}
  11. 11. The example of method outside theclass is as under:#include<iostream>using namespace std;class num{int n1,n2,n3;public:void setdata()void display()};void num::setdata(){cout<<"enter two numbers";cin>>n1>>n2>>n3;}void num::display(){cout<<n1<<n2<<n3;}int main(){num n;n.setdata();n.display();
  12. 12. return 0;}Thus both differ from each others.4-- Justify the following.i} In class, member function cannot beprivate.In a class, class member functions canbe private but of no use, so alwaysitspreferable to keep member functions aspublic so that a user can be able toperform theiroperations or claculations. A class isused to secure our data and classmember functionscannot be accessed without its objectand if they are private then of no usebeacuse they cantbe accessed with class objects also asthey are private so its necessary tokeep class memberfunctions as public access specifier.A class member function should alwaysdefined under
  13. 13. public specifier so that it can beaccessible as and when necessary.for e.g.:#include<iostream>using namespace std;class num{int n1,n2;public:void setdata(int a,int b){ n1=a; n2=b;}void display(){cout<<n1<<n2;}};int main(){num n;n.setdata(10,15);n.display();return 0;
  14. 14. }As above shown in example, a classmember functions should be alwaysunder publicaccess specifier so that it can beaccessed as and when necessary.ii}We can create object at a classdeclaration time.Its false, because a class objectcannot be declared at the time ofclass declaration.The syntax of class declaration is:class(keyword) classname{member variablemember function}While the syntax of object declarationis as follow:An object can be declared in two wayssuch as :-At the end statement of class
  15. 15. }objectname-In main :int main(){classname objectname}So the object cannot be declared atthe class declaration time.5--Short note on scope resolutionoperator.The scope resolution operator (::) inc++ used to define the alreadydeclared in themember functions of the class.C++ supports to the global variablefrom a function,Local variable is todefined in thesame function name.The syntax of the scope resolutionoperator::: globalvariablename
  16. 16. A scope resolution operator (::), canbe used to define the member functionsof a classoutside the class. It shows the scoperesolution operator untangling a messmade by using thesame names for different kinds ofentities base class overridden memberfunction using thescope resolution operator (::)Thescope resolution operator (denoted ::)in C++ is used todefine the already declared memberfunctions of a particular class. Inthe .cpp file one candefine the usual global functions orthe member functions of the class. Todifferentiatebetween the normal functions and themember functions of the class, oneneeds to use the scoperesolution operator (::) in betweenthe class name and the member functionname.Its example is as follow:#include<iostream>
  17. 17. using namespace std;class num{int n1,n2,n3;public:void setdata()void display()};void num::setdata(){cout<<"enter two numbers";cin>>n1>>n2>>n3;}void num::display(){cout<<n1<<n2<<n3;}void num::mul(){ cout<<n1*n2*n3;}int main(){num n;n.setdata();n.display();
  18. 18. n.mul();return 0;}