Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prof. Bhushan Trivedi Director GLS Institute of Computer Technology

Similar presentations


Presentation on theme: "Prof. Bhushan Trivedi Director GLS Institute of Computer Technology"— Presentation transcript:

1 Prof. Bhushan Trivedi Director GLS Institute of Computer Technology
Programming with ANSI C ++ A Step-by-Step Approach Prof. Bhushan Trivedi Director GLS Institute of Computer Technology

2 Introduction to Object-Oriented Programming and C ++
Chapter 1 Introduction to Object-Oriented Programming and C ++

3 Agenda Limitations of C The Object Orientation
C++ and the Object Orientation Is C++ a completely object oriented language? The Classes and Objects

4 Agenda Differences between C and C++ Philosophical differences
Syntactical differences Capability to provide Object Based and Object Oriented programming both The Exception based design of code

5 Agenda Introduction of template as generic programming element
Introduction to the C++ Object Mode Variations of C++ The Applications of C++

6 The strength of C very powerful and proven.
survived for more then two decades efficient and compact programs C programs executables produce most compact object code

7 The strength of C C is being used in small and medium size programs to a great extent. There is a large class of programmers just know one language, The C.

8 The strength of C Operating systems like Linux and Windows, Databases like Oracle, Network programs like TCP/IP all of them have large (if not all!) part of them written in C. (Though significant part of them is written in C++ as well

9 Limitations of C Problems are apparent while attempting large programs
Very large C programs loose a ‘Global View’ Very difficult to remember every part of the program Problem with the design

10 Limitations of C Problem with the inability of the language to express
Intermediate solution is to make the program modular Modules are not totally independent Efficient teamwork is impossible without global vision

11 The Remedy Ability to have a global view using abstractions
Relieved from the burden of handling a large program View as a program with few abstractions Can view the entire program together Can properly reason if a part of it to be debugged and modified.

12 Solution in the design We may need to add new features in the programming language (here the C) to suit very large programs (which C++ does). We may even require changing the style of programming (which C++ does not do, we have to do it)

13 Solution by the design We may need to change the process of viewing the problem itself The software engineering process

14 OB and OO programming New designs of programming
Object Based (less flexible but more efficient) Object Oriented (more flexible but less efficient)

15 OB and OO programming Programming is to provide computer-based solutions to real world problems Entities, attributes; what they do? Visualizing and programming the problem in global way

16 OB and OO programming Need for providing abstractions (class) for all the entities involved in the process. OB or OO programming preserves the global view even when program grows

17 The philosophy Designed for providing both Object Based and Object Oriented programming Keeping backward compatibility with C keeping efficiency levels of C The object-oriented model is not imposed on the developer like Java Reusability advantage using STL

18 The Classes and Objects
C++ introduces a new element, called class; which is an extension to struct, and provides us the facility to store actions in form of functions within the entities themselves. Variable of type class is known as object

19 The Classes and Objects
The data and function members of a class The operations by and on the objects The thin class design vs Abstract Data Type design Class is a sketch from where actual objects are derived

20 The member functions The non member function are also possible!
StudentPrintDetails(Lara),StudentPrintDetails(Mahesh) and StudentPrintDetails(Moti) Lara.PrintDetails() (allowed) and Moti.PrintDetails() (not allowed) The objects of the class only can operate on the functions owned by them

21 Difference between C and C++: Philosophical differences
The C++ is not just Extended C, the program design changes radically The principle of information hiding Public and private division The inheritance advantage MFC(OO) and STL(OB) examples Similarity of user defined types with built-in

22 The Constructor example
class student { int roll_no; … student() // this is a construction function, bearing same name as a class { roll_no = 0; } }; student st1;

23 Operator overloading Assume Complex to be a class defined earlier
Complex C1, C2, C3; C1.SetValues(2,3);//i.e. 2+3i C2. SetValues(3,4); //i.e. 3+4i

24 Operator overloading Now we can write following C3 = C1 + C2;
This shows the operator + overloaded for class Complex

25 The Syntactical Differences: the comment //
/*This itself is c like comment, while following is a C++ like comment*/ if (a>b) // checking for a greater then b printf (“A is greater!); if (a>b) /* checking for a > b!*/ printf(“a is bigger!”); IS NOT REPLACABLE!

26 The IO Operators cout << “a is greater”;
cin >> StringVariable We do not need to provide data type with cin or cout (like %d, %s etc) We do not need to append & operator in front of variable like scanf while reading a variable value

27 Other Differences Return types are different
Default return type is void and not int Compiling under different compilers is different Exception based design Templates as type-less way of writing code. Type is an argument to be passed to templates at the time of definition

28 The C++ Object Model How the program is compiled to object code is designed by this model This is not part of the standard! So every compiler may prefer to do it deems fit It is important to know how object model works to understand the working of a program The prime emphasis is on efficiency and not flexibility

29 Variations of C++ The C++ originally designed by Bjarne Staroustrup in 1979(“C with classes”) The incremental operator ++ was added in 1983 to the ‘C’ Intermediate incompatible versions ANSI / ISO standardization committee provided an ANSI/ISO C++ standard looking at all these changes in 97

30 Applications of C++ Operating systems
Middle tire in Microsoft Tech applications Computer Graphics Programming Network devices VOIP (Voice over IP) Web search engines RDBMS, ERP and CRM products base part


Download ppt "Prof. Bhushan Trivedi Director GLS Institute of Computer Technology"

Similar presentations


Ads by Google