Presentation is loading. Please wait.

Presentation is loading. Please wait.

The C++ programming language

Similar presentations


Presentation on theme: "The C++ programming language"— Presentation transcript:

1 The C++ programming language
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./0. The C++ programming language The basics of object oriented programming in C++ language The way leading to development of C++ The object oriented view of the world Methodologies of software development before object oriented approach The characteristics of the object oriented approach of C++ The class type Referencing to the members of the class The other method of the definition of member functions

2 The way leading to development of C++
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./1. The way leading to development of C++ Simula-67, , Kristen Nygaard and Ole-Johan Dahl They introduced the class and inheritance notions for simulation of real world, for modelling the objects of it. Smalltalk-80, 1980, Xerox' Palo Alto Research Center (PARC) A true object oriented language. C++, 1983, Bell Laboratories, Bjarne Stroustrup Elimination of drawbacks of C, adding to it object oriented properties. 1985, Bjarne Stroustrup: "The C++ Programming Language” 1997, ANSI standard It evolves from the introduction and new concepts had been built in it.

3 The object oriented view of the world
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./2. The object oriented view of the world count names[ ] SetCount() GetCount() SetElement() GetElement() List class instance numbers[] NumbersFromMarks() SetElement() GetElement() Average() groupNo SetGroupNo() GetGroupNo() Group Marks repetitionNo[] SetElement() GetElement() GK201 GK301 MarksOfExam subject date AmountOfFails() TestResults MOE2004 MOE2005 TestGK201 TestGK301

4 Modelling the world on the base of object oriented methodology
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./3. Modelling the world on the base of object oriented methodology The world is a system of real and abstract objects that cooperate and take effect on each other. The objects have two well distinguishable parts: the surface – interface – that is applied to communicate to outside world and the interior that means the essence of it. When the reality is modelled the simplified model of the real objects is applied which gives the common features of set of similar objects collecting them to a class, type. The class realises the functionality of instances, and provides data structures to store the unique properties of them to make possible to discriminate. The methodology of object oriented programming (OOP) gives a tool to abstraction of objects of reality, the program units and their relationship are come into existence as a result of the usage of OOP methodology. An object is responsible for the work of functions and the representation of all the characteristics that can be assigned to it in a given abstraction but only for these.

5 Methodologies of software development before object oriented approach
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./4. Methodologies of software development before object oriented approach The need for development of large, complicated program systems motivated the evolution of programming languages. The program development process was aided by the methodology of modular programming in the beginning. The modules that could be programmed relatively independent manner aided the team-work, changeability and to a certain level the data hiding. Typical languages are: Fortran, C, Modula-2. The structured programming connected to name of Dijkstra united more new principles: to the principle of modularity it connected the ideas of progression from the simple to complex, the successive refinement, the hierarchic structure and the data hiding and introduced the theorem of successive series of abstract computers. Languages that realise the ideas the best manner are Pascal and Delphi, they use encapsulated blocks. Deficiencies: The data handling procedures were separated from data structures. The reuse and easy modification of program code were not possible. Accomplishing of certain tasks - e.g. handling strings, dynamic data structures as easy as handling numeric data - was impossible.

6 The characteristics of the object oriented approach of C++
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./5. The characteristics of the object oriented approach of C++ Data and data handling subprograms are in one unit (encapsulation) The data that characterise the object and the functions that realise the functionality of it are united into a new data structure, the object immuring and saving the inner parts of the object that are irrelevant for the outer world. The same properties of similar objects are used to describe the class of the real objects while by the specific properties - data values - of them they can be distinguished as instances. Inheritance of class properties to subclasses, instances Inheritance means appearance of the data members and functions of classes in the descendant class or instance. The descendant classes can have newer properties: data members and functions (methods) over the properties inherited from the ancestors. The descendant class can inherit from more than one ancestor class. The classes form a class-hierarchy by means of ancestor-descendant connections.

7 The characteristics of the object oriented approach of C++, contin.
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./6. The characteristics of the object oriented approach of C++, contin. Different work of functions that have same name (polymorphism) Classes on the different level of hierarchy may need more or less different capabilities from functions having same name and intended for basically the same task. These needs will be satisfied with different function bodies. In such a case redefinition of the virtual function of the ancestor class is performed. The flexibility of C++ that can be reached by redefining the task of operators can be very impressive. E.g. it is possible to use the * multiplicative operator for multiplying two matrices. This Operator overloading is very parameter-signature dependant similarly to the namesake-functions mentioned earlier.

8 Department of Information Engineering INFORMATION TECHNOLOGY dr
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./7. The class type The class type evolved from the struct type of C language. The class realises the encapsulation of data members and functions. Let us define the List class having data members and functions that were given in the earlier figure as an example! class List {private : int count; char names[300][25]; public : void SetCount(int countIn){count= countIn;} // count in int GetCount ( ){ return count;} void SetElement (int i, char* nameIn) {strcpy(names[ i ], nameIn);} void GetElement (int i, char* nameOut ){strcpy(nameOut, names[ i ]);} }; List listVariable; //definition of an instance of a List class

9 Referencing to the members of the class
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./8. Referencing to the members of the class The earlier example is special considering that the all member function were defined inline manner. In such a case the inline keyword can be left. Let us assign values to elements of the listVariable ! listVariable. SetCount(20); //Can store 20 names listVariable. SetElement( 0, "Roger Moore" ) ; listVariable. SetElement( 1, "Telly Savalas" ) ; // Entering further names similarly // Let us print out the count of elements and the second name! printf("There are %d names in the list.", listVariable . GetCount( ) ); char nameOut [25]; listVariable. GetElement( 1, nameOut ) ; puts(nameOut );

10 The other method of the definition of member functions
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 27./9. The other method of the definition of member functions Inline functions are expedient to define short, one line length functions only. If the member function is longer the usual declaration - definition pair necessary: class List {private : int count; char names[300][25]; public : void SetCount (int countIn); // declaration, a prototipe int GetCount ( ){ return count;} void SetElement(int i, char* nameIn) {strcpy(names[ i ], nameIn);} void GetElement(int i, char* nameOut ){strcpy(nameOut , names[ i ]);} }; void List :: SetCount(int countIn) // definition {count = countIn;}


Download ppt "The C++ programming language"

Similar presentations


Ads by Google