CLASSES OBJETS PROGRAMMING FUNTAMENTALS USING C HARIKRISHNAN S

CLASSES & OBJETS PROGRAMMING FUNTAMENTALS USING C++ HARIKRISHNAN S

INDRODUCTION • c++ class mechanism allows users to define their own data types that can be used as conveniently as build in types. • Classes are often called user defined types. • Includes defining of class types and creation of objects of classes.

CLASS A class is an extended concept similar to that of structure in C programming language; this class describes the data properties alone. In C++ programming language, a class describes both the properties (data) and behaviors (functions) of objects. Classes are not objects, but they are used to instantiate objects.

CREATING CLASS A class is a user-defined data type that we can use in our program, and it works as an object constructor, or a "blueprint" for creating objects. Example * For example, Create a class called "My. Class": class My. Class { // The class public: // Access specifier int my. Num; // Attribute (int variable) string my. String; // Attribute (string variable) };

CREATE AN OBJECT • In C++, an object is created from a class. We have already created the class named My. Class, so now we can use this to create objects. • To create an object of My. Class, specify the class name, followed by the object name. • To access the class attributes (my. Num and my. String), use the dot syntax (. ) on the object:

Example Create an object called "my. Obj" and access the attributes: • class My. Class { // The class public: // Access specifier int my. Num; // Attribute (int variable) string my. String; // Attribute (string variable) }; int main() { My. Class my. Obj; // Create an object of My. Class // Access attributes and set values my. Obj. my. Num = 15; my. Obj. my. String = "Some text"; // Print attribute values cout << my. Obj. my. Num << "n"; cout << my. Obj. my. String; return 0; }

DATA MEMBERS & MEMBER FUNCTIONS

DATA MEMBER. • A data member may be of any type, including classes already defined, pointers to objects of any type, or even references to objects of any type. Data members may be private or public, but are usually held private so that values may only be changed at the discretion of the class function members.

MEMBER FUNCTIONS. • Member functions are operators and functions that are declared as members of a class. Member functions do not include operators and functions declared with the friend specifier. These are called friends of a class. You can declare a member function as static ; this is called a static member function.

C++ Here is a demo of a c++ programme using class and object

C++ BENEFITS OF OOP'S • Through inheritance, we can eliminate redundant code and extend the use of existing classes which is not possible in procedure oriented approach. • We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch which happens procedure oriented approach. This leads to saving of development time and higher productivity. • The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program. • • • It is possible to have multiple instances of object to co-exist without any interference. • Software complexity can be easily managed. It is possible to map objects in the problem domain to those in the program. It is easy to partition the work in a project based on objects. The data-centered design approach enables us to capture more details of a model in implementable from. Object oriented systems can be easily upgraded from small to large systems. Message passing techniques for communication between objects makes the interface descriptions with external systems much simpler.

BJARNE STROUSTRUP Stroustrup began developing C++ in 1979 (then called "C with Classes"), and, in his own words, "invented C++, wrote its early definitions, and produced its first implementation. . . chose and formulated the design criteria for C++, designed all its major facilities, and was responsible for the processing of extension proposals in the C++ standards committee. "[13] Stroustrup also wrote a textbook for the language,

ALAN KAY Alan Curtis Kay is an American computer scientist. He has been elected a Fellow of the American Academy of Arts and Sciences, the National Academy of Engineering, and the Royal Society of Arts. He is best known for his pioneering work on object-oriented programming and windowing graphical user interface design

THANK YOU SUBMITTED BY, HARIKRISHNAN S, 11285
- Slides: 14