Vous êtes sur la page 1sur 9

Objects: Object is the basic unit of object-oriented programming. Objects are identified by its unique name.

An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data.

An Object is a collection of data members and associated member functions also known as methods.

Classes: Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represent a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects becomes functions of the class and is referred to as Methods.
For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.

No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.

Inheritance:

Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.

Data Abstraction: Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details. Data Encapsulation: Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible. Polymorphism: Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways. Overloading: Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an exiting operator or function begins to operate on new data type, or class, it is understood to be overloaded. Reusability: This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.
The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections.

A sample program to understand the basic structure of C++

Sample Code 1.

2.

//program to read employee details and to output the data 3. 4. ////////// code begins here ///////////////////////////// 5. #include <iostream> //&#8594; Preprocessor directive 6. using namespace std;

7.

class employee

//&#8594; Class Declaration

8. {

9. 10. 11.
12.

private: char empname[50]; int empno; public: void getvalue() { cout<<"INPUT Employee Name:"; cin>>empname; cout<<"INPUT Employee Number:"; cin>>empno; } void displayvalue() { cout<<"Employee Name:"<<empname<<endl; cout<<"Employee Number:"<<empno<<endl; }

13. 14. 15. 16.


17.

18.
19.

20.
21.

22. 23. 24. 25. 26. 27. };


28. 30. {

29. main() 31. 32. 33.


employee e1; e1.getvalue(); //&#8594; Creation of Object

e1.displayvalue(); 34. } 35. 36. ///// code ends here ////////////// 37.

Constructors and the operator new

constructor is a member function of the class, with the name of the function being the same as the class name. It specifies how the object should be initialized: class Stack { public: Stack(int sz); // Constructor: initialize variables, allocate space. void Push(int value); // Push an integer, checking for overflow. bool Full(); // Returns TRUE if the stack is full, FALSE otherwise. private:

int size; int top; int* stack; };

// The maximum capacity of the stack. // Index of the lowest unused position. // A pointer to an array that holds the contents.

Stack::Stack(int sz) { size = sz; top = 0; stack = new int[size]; // Let's get an array of integers } To create a new object of type Stack, we write: Stack* s = new Stack(17); The new function takes the place of malloc() in C. It creates (i.e. allocates) the object and then calls the constructorfunction. It is crucial that you always define a constructor for every class you define, and that the constructor initialize every data member of the class. Data allocated with new (such as s) is stored on the heap, and remains after the function returns; heap data must be explicitly disposed of using delete, described below.

Destructors and the operator delete

Destructor is a member function of class.It specifies how the object space should be freed: class Stack { public: Stack(int sz); // Constructor: initialize variables, allocate space. ~Stack(); // Destructor: deallocate space allocated above. void Push(int value); // Push an integer, checking for overflow. bool Full(); // Returns TRUE if the stack is full, FALSE otherwise. private: int size; // The maximum capacity of the stack.

int top; int* stack; };

// Index of the lowest unused position. // A pointer to an array that holds the contents.

Stack::~Stack() { delete [] stack; // delete an array of integers } To deallocate Stack object s we created before by new, we write: delete s; Always delete objects that you created (with new) !

1. Member functions These are functions which are considered part of the object and are declared in the class definition. They are often referred to asmethods of the class. In addition to member functions, a class's behavior is also defined by: constructor for that object: what to do when you create a new object destructor for that object: what to do when you delete an object 2. Private vs. public members A public member of a class is one that can be read or written by anybody, in the case of a data member, or called by anybody, in the case of a member function. It provides an interface with the outside world. A private member can only be read, written, or called by a member function of that class.

Why classes:
(1) it makes it much easier to organize your programs with OO approch (2) the use of private members makes it possible to do information hiding (hiding the information that is likely to change)

C++ Examples class Stack { public: int top; // Index of the top of the stack. int stack[10]; // The elements of the stack. void Push(int value); // Push an integer, checking for overflow. };
void Stack::Push(int value) { ASSERT(top < 10); stack[top++] = value; }

// stack should never overflow

This class has two data members, top and stack, and one member function, Push. The notation class::Push denotes the function member of the class Stack. The function is defined beneath it. In actual usage, the definition of class Stack would typically go in the file stack.h and the definitions of the member functions, like Stack::Push, would go in the file stack.cc. If s is the pointer to a Stack object,we can access the top element as s->top, just as in C. However, we can also call the member function using the syntax: >Push(17); s-

Inside a member function, one may refer to the members of the class by their names alone. The purpose of member functions is to encapsulate the functionality of a type of object along with the data that the object contains. A member function does not take up space in an object of the class. C++ classes are similar to C structures in some ways. C struct is a class that has only public data members

Private members

private members of a class are hidden to all but the member functions of that class. public members are visible and accessible to everybody. Both data and function members can be either public or private. In C++, we suggest all data members of a class should be private. All operations on data should be via that class' member functions. Keeping data private adds to the modularity of the system, since you can redefine how the data members are stored without changing how you access them. In our stack example, if we introduce a Full() function, then we don't need to look at the top or stack members outside of the class. Thus we can rewrite the program as follows: class Stack { public: void Push(int value); // Push an integer, checking for overflow. bool Full(); // Returns TRUE if the stack is full, FALSE otherwise. private: int top; // Index of the top of the stack. int stack[10]; // The elements of the stack. }; bool Stack::Full() { return (top == 10); } Now we can rewrite Push this way: void Stack::Push(int value) { ASSERT(!Full()); stack[top++] = value; }

Before, given a pointer to a Stack object, say s, any part of the program could access s->top, in potentially bad ways. Now, since the top member is private, only a member function, such as Full(), can access it.

C is not object oriented but c++ is object oriented In c we use scanf function as standard input function, while In c++ we use streame cin>> for input. Like this for output In c we use printf function, while in c++ we use cout<< as a output function. in c we use #include<stdio.h>as iclusion file,while in c++ we use #include<iostreame>as inclusion file. C DATA IS NOT SECURED TOP DOWN FOCUS ON PROCEDURES PROGRAMS ARE DECOMPOSED INTO FUNCTIONS allocation is done with malloc statement UNOINS AND ENUMS ARE NOT AVALIABLE DOES NOT PROVIDE DEFAULT ARGUMENTS C++ SECURED BOTTOM-UP FOCUS ON DATA INTO OBJECTS NEW OPERATOR AVALIABLE PROVIDES

Java vs. C++ 1) C++ supports pointers whereas Java does not 2) C++ supports operator overloading multiple inheritance but java does not. 3) Java is platform independent language but c++ is depends upon operating system machine etc. 4) Java uses compiler and interpriter both and in c++ their is only compiler 5) C++ is more nearer to hardware then Java

6) java has primitive data type like Boolean which are not available in c++

Hacking is the process of achieving access to a computer or computer network without legal authorization. It is the most common activity amongst teenagers and young adults. Many hackers are keen to learn about computers and consider hacking as an art. They want to build programs to display their problem solving skills and not to harm others. An ethical hacker is a computer and network expert who attacks a security system on behalf of its owners, seeking vulnerabilities that a malicious hacker could exploit. To test a security system, ethical hackers use the same methods as their less principled counterparts, but report problems instead of taking advantage of them.

My name is shylaja, im from bangalore, my father is a business man, my mother is a house wife, i have one elder sister who is currently studying B.E. I will be very very sincere to watever work given to me. I am basically a hardworker. my strength is my patience and sincerity. I am a software engineering student with fair Knowledge in C,C++ and Java. My strength my confidence,positive thinking,Punctuality, honesty and mostly one is hard working The Human Resources Department of a company deals with Employment, recruitment, and placement Employer/employee relations Compensation, benefits, and insurance Employee assistance Training and development

Vous aimerez peut-être aussi