+ All Categories
Home > Technology > I assignmnt(oops)

I assignmnt(oops)

Date post: 02-Nov-2014
Category:
Upload: jay-patel
View: 611 times
Download: 0 times
Share this document with a friend
Description:
 
Popular Tags:
21
1--THE BENEFITS OF OOP. Object Oriented Programming is a method of implementation in which programs are organised as co-operative collection of objects each of which represents an instance of some classes and whose classes are all members of hoerarchy of classes united through the property called inheritance. OOP offers several benefits to the program designer and the user. Object- orientation contributes to the solutions of many problem associated with the development and quality of software products. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are:
Transcript
Page 1: I assignmnt(oops)

1--THE BENEFITS OF OOP.Object Oriented Programming is a method of implementation in which programs are organised as co-operative collection of objects each of which represents an instance of some classes and whose classes are all members of hoerarchy of classes united through the property called inheritance.

OOP offers several benefits to the program designer and the user. Object-orientation contributes to the solutions of many problem associated with the development and quality of software products. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are:

1. Through inheritance, we can eliminate redundant code and extend the use of existing classes.

Page 2: I assignmnt(oops)

2. We can built programs from standard working modules that communicate with one another rather than, having to start writing the code from scratch. This leads to saving of development time and higher productivity.3. The principle of data hiding helps the programmers to built secure program that can’t be invaded by code in other parts of the program.4. It is possible to have multiple objects to coexist without any interference.5. It is possible to map objects in the problem domain to those objects in the program.6. It is easy to partition the work in a project based on objects.7. The data-centered design approach enables us to capture more details of the model in an implementable form.8. Object-oriented systems can be easily upgraded from small to large system

Page 3: I assignmnt(oops)

9. Message passing technique for communication between objects make the interface descriptions with external system much simpler.10. Software complexity can be easily managed.11. This language helps for software development, which are more reliable.12 .One should not use to check error code after each potentially call.13. Some of its application includes design issues.14. It is the enhanced form of C language.15. It is statically type language.16. The most important Feature is that it’s procedural and object oriented nature.17. As this is the more developed form of c, it maintains the aspects if c language yet it has the feature of memory management.18. C++ is much suitable for large projects.19. It is one of the fairly efficient languages.

Page 4: I assignmnt(oops)

20. It divides the problems into collection of objects which provides services and can be used to solve a particular problem.

21. Code re-use (Polymorphism, Generics, Interfaces)22. Code extensibility23. Catch errors at compile time rather 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 problem to a solution in Object Oriented code.

2-- write a short note on class and objects.

Object Oriented Programming is a method of implementation in which programs are organised as co-operative collection of objects each f which represents an instance of some

Page 5: I assignmnt(oops)

classes and whose classes are all members of hoerarchy of classes united through the property called inheritance.

A class is a user defined data-type which is a collection of data member and functions.

Class is created in oop to keep our data secure which cannot be accessed without permission.The objects with data structure(attributes) and behaviour(operations) are grouped into a class. All those objects possessing similar properties are grouped into the same unit.it can solve real world problems. The data members and member functions can be private or public in a class. There can be many methods in a class which can be accessed with its permission to solve real world problems. The data members of a class is by default private. The

Page 6: I assignmnt(oops)

data members declared in a class in accessed in a class only and it cannot be accessed outside the class. The member functions can also be accessed with creating an object which takes a permission from class to access it as per user requirement.

syntax of class is as under:

class(keyword) classname{data membermember functions or methods};

For e.g: Create a class which ad 2 numbers.#include<iostream>using namespace std;class add{int n1,n2;public:void setdata(int a,int b){n1=a;

Page 7: I assignmnt(oops)

n2=b;}int add(){int sum;sum=n1+n2;return sum;}void display(){cout<<"Addition="<<add();}};Objects is an entity that can store data and send and receive messages. It is an instance of a class.

Objects are uniquely identifiable by a name. There can be as many as objects for a class as per the requirement of users. Each objects has its own properties. Different entities of a problem are examined independently. These entities are choosen because they have some

Page 8: I assignmnt(oops)

physical or conceptual boundaries that separate them from rest of the problem. The entities are represented as objects in the program. The goal is to have a clear corresponding between physical entities in the problme domain and object in the program. an object can be a person, a place, a thing, etc.

syntax of object is as under:

}objectname;

orint main(){classname objectname;}

for e.g: create object to access above methods of class add.

int main(){add a1;

Page 9: I assignmnt(oops)

a1.setdata(10,25);a1.add();a1,display();return 0;}

3--State difference between method defined in the class and outside the class.

Its differences are as follow:

The scope resolution operator is used in method defined outside the class where as, in method define in the class no need to use scope resolution operator. (::)

In method defined outside the class, prototype or function header is to be declared in the class where as, in method defined in the class method's body is also to be mentioned with its prototype.

Page 10: I assignmnt(oops)

The example of method within the class is 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;}

Page 11: I assignmnt(oops)

The example of method outside the class 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();

Page 12: I assignmnt(oops)

return 0;}

Thus both differ from each others.

4-- Justify the following.

i} In class, member function cannot be private.

In a class, class member functions can be private but of no use, so always its preferable to keep member functions as public so that a user can be able to perform their operations or claculations. A class is used to secure our data and class member functions cannot be accessed without its object and if they are private then of no use beacuse they can't be accessed with class objects also as they are private so its necessary to keep class member functions as public access specifier. A class member function should always defined under

Page 13: I assignmnt(oops)

public specifier so that it can be accessible 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;

Page 14: I assignmnt(oops)

}

As above shown in example, a class member functions should be always under public access specifier so that it can be accessed as and when necessary.

ii}We can create object at a class declaration time.

Its false, because a class object cannot be declared at the time of class declaration.The syntax of class declaration is:class(keyword) classname{member variablemember function}

While the syntax of object declaration is as follow:

An object can be declared in two ways such as :-At the end statement of class

Page 15: I assignmnt(oops)

}objectname

-In main :int main(){classname objectname}So the object cannot be declared at the class declaration time.

5--Short note on scope resolution operator.

The scope resolution operator (::) in c++ used to define the already declared in the member functions of the class.

C++ supports to the global variable from a function,Local variable is to defined in the same function name.

The syntax of the scope resolution operator::: globalvariablename

Page 16: I assignmnt(oops)

A scope resolution operator (::), can be used to define the member functions of a class outside the class. It shows the scope resolution operator untangling a mess made by using the same names for different kinds of entities base class overridden member function using the scope resolution operator (::)The scope resolution operator (denoted ::) in C++ is used to define the already declared member functions of a particular class. In the .cpp file one can define the usual global functions or the member functions of the class. To differentiate between the normal functions and the member functions of the class, one needs to use the scope resolution operator (::) in between the class name and the member function name.

Its example is as follow:

#include<iostream>

Page 17: I assignmnt(oops)

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();

Page 18: I assignmnt(oops)

n.mul();return 0;}


Recommended