C++ Programming

1. Computer Programming 2. History of Prog.Language 3. Introduction to C++ 4. OOPS 5. Features of C++ 6. Starting Turbo C++ 7. C++ Tokens 8. Basic requirment of C++ 9. Comments 10. My First Program in C++ 11. Line Break 12. C++ Escape Sequence 13. Constants or Literals 14. Variable in C++ 15. Data Types in C++ 16. Range of data types in C++ 17. Declare Variables 18. Reserved Key Words 19. cout<< 20. Chained & Embedded state 21. Prog.to print sum of 2 nos 22. cin>> 23. Prg.to print sum & average 24. Area & Perimeter of Rectangle 25. Area Circumference of Circle 26. Prg.for Simple Calculator 27. Operatos in C++ 28. Ex. Of Operators 29. Swap two numbers 30. Hierarchy of Operators 31. if( ) statement 32. Prg.to check +ve,-ve or zero 33. if..else statement 34. Prg.to check Odd or Even 35. Prg.to print larger of 2 nos 36. Prg.to print largest of 3 nos 37. Prg.to check divisibility 38. Prg.to check print range 39. for. . . loop statement 40. prg.to print series of nos 41. Prg.to check divisibility 42. prg.to print sum of series 43. Prg.to print Pyramid 44. prg.for Factorial 45. prg.to fill screen 46. prg.for largest/smallest no 47. prg.to print reverse no 48. prg.to add each digit 49. prg.for sum of factorial 50. prg.for fibonacci series 51. prg.to check Prime nos 52. prg. Prime no from 1 to 100 53. prg.Specified Prime nos 54. while( ) statement 55. do. . While statement 56. goto statement 57. break & continue statement 58. switch case statement 59. Array in C++ 60. print reverse order using array 61. Ascending/Descending order 62. prg.to search no in Array 63. Double Dimension Array 64. String in C++ 65. String with spaces in C++ 66. prg.to print string in reverse 67. prg.to count A,E,I,O,U vowel 68. Function( ) in C++ 69. Function program examples 70. General Purpose Programs 71. Loan & EMI calculation prg. 72. Table print prg. 73. Leap year program 74. lower to UPPER case prg. 75. Age Distribution prg. 76. Bank note calculation prg. 77. Simple Interest prg. 78. Compound Interest prg. 79. Simple Depreciation prg. 80. Reducing bal.Depreciation prg. 81. Marksheet prg. 82. Income Tax prg. 83. Time calculator prg. 84. Distance converter prg. 85. Volume Air Calculation prg. 86. Time to fill Water Tank prg. 87. Salary Calculation prg. 88. Total Sale Calculation prg. 89. Male/Female percentage prg. 90. Library Rent prg. 91. Office Expence prg. 92. Total Salary Calculation prg. 93. Profit or Loss prg. 94. Total Profit/Loss prg. 95. Convert Amt to Word. 96. ASCII Table 97. C++ Operators 98. C & C++ Reserved Keyword 99. C & C++ Pre-Define Function 100. C++ Interview Part1 101. C++ Interview Part2 102. C++ Interview Part3 103. C++ Interview Part4 104. C++ Interview Part5 105. C++ Interview Part6 106. C++ Interview Part7 107. C++ Interview Part8 108. C++ Interview Part9 109. C++ Interview Part10 110. C++ Interview Part11 111. C++ Interview Part11
Pr.Pg Next Pg

OOPS (Object Oriented Programming)

  • Object Oriented Programming paradigm is playing an increasingly significant role in the design and implementation of software systems.

  • This was a new feature which was added in C++, when it was upgraded from c.

  • OOPS is a programming feature that uses object as their interaction to design application and computer programming.

  • It includes various programming techniques such as en-capsulisation, modularity, polymorphism and inheritance. All these techniques were not used till late 80s, but as of now many new programming language supports OOPS.

  • OOPS was developed as a part to attempt developing in discrete units of programming logic and reusability in software.

  • The Simula programming language was 1st to introduce concept underlined OOPS such as Object classes, Sub-classes, Virtual methods, Garbage collections and discrete event simulations as a subset of ALGOL.

  • The ideas of Simila influenced many later languages such as Smalltalk, derivatives of LISP, Object Pascal and C++.

  • It simplifies the development of large and complex software systems and helps in the production of software which is modular, easily understandable, reusable and adaptable to changes .OOP is designed around the data being operated upon as opposed to the operations themselves. OOPS treats the data as objects i.e. it decomposes the data.

  • It is built on the foundation laid by the structured programming concepts and data abstraction.

  • The fundamental change in OOP is that a program is designed around the data being operated upon rather than the operation themselves.

  • That is it treats data as the critical element in the program development and does not allow it to flow freely around the program.

  • It ties data more closely to the functions that operate on it and protects it from the accidental modification from outside function.

  • Flexibility is gained by changing or replacing modules without disturbing other parts of the code.

 

Features of OOPS

The features of object oriented programming are described in connotation.

Encapsulation

  • It is a mechanism that associates the code and the data it manipulates into a single unit and keeps them safe from external interference and misuse.

  • In C++ this is supported by a construct called class.

  • An instance of class is known as an object which represents a real world entity.

 

Data Abstraction

  • The technique of creating new data types that are well suited to an application to be programmed is known as data abstraction.

  • It provides the ability to create user defined data types, for modeling a real world object. The class is a construct in C++ for creating user defined data types called abstract data types (ADTs).

  • Data abstraction can be achieved by the use of access specifiers.

 

Single Inheritance

  • It allows the extension and reuse of existing code without having to rewrite the code from scratch.

  • Inheritance involves the creation of new classes from the existing codes (base classes), thus enabling the creation of a hierarchy of classes that simulate the class and subclass concept of the real world.

  • The new derived class inherits the class members of the base class and also adds its own.

 

Multiple Inheritances

  • This also allows the extension and reuse of existing code without having to rewrite the code from scratch.

  • Here we can derive class from more than one base class and is known as multiple inheritance.

  • Instance of classes with multiple inheritance have instance variables for each of the inherited base classes.

  • C++ supports multiple inheritances.

  • JAVA does not support multiple inheritances.

 

Delegation

  • It is an alternative to class inheritance.

  • Delegation is a way of making oject composition as powerful as inheritance.

  • In delegation, two objects are involved in handling a request.

  • A receiving object delegates operations to its delegate.

  • This is analogous to the child classes sending requests to the parent classes.

  • This approach takes a view that an object can be a collection of many objects and the relationship is called the has-a relationship or containership.

 

Genericity

  • It is a technique for defining generic software components that have more than one interpretation depending on the data type of parameters.

  • It allows the declaration of data items without specifying their exact data type

  • Such unknown data types (Generic Data Type) are resolved at the time of their usages (Function call) bases on the data type of parameters.

  • In C++ Genericity is realized through function templates a class templates.

  • For example, a sort function can be parameterized y the type of elements it sorts.

 

Polymorphism

  • The word Polymorphism is derived from Greek word (Poly = many and Morphism = Forms), means many forms.

  • This is an important features that allows a same name to be used for many than one related purpose.

  • It allows a single name/operator to be associated with different operations depending on the type of data passed to it.

  • By using concept of polymorphism, we can define new operation for the operators (=, +). These operators may have to do many operations, which is the concept of polymorphism.

  • In C++, it is achieved by

  1. Function Overloading,

  2. Operator Overloading and

  3. Dynamic Binding.

 

Persistence

  • The phenomenon where the object (Data) outlives the program execution time and exist between executions of a program is known as persistence.

  • When you execute any program in C++, the life of data exist only upto program execution.

  • Data persistence is not supported in C++.

  • However developer can built function and features to write data using file stream in program and save data in secondary memory i.e. hard disk and so on.

  • Latest DBMS and RDBMS system supports data persistence.

 

Message Passing

  • It is additional feature supported by C++.

  • It is nothing but sending and receiving of information by the objects same as people exchange information.

  • It is the process of invoking an operation on an object.

  • It require Creating classes that define objects and its behavior, creating objects from class definitions and finally establishing communication among objects.

  • In response to a message, the corresponding method is executed in the object

 

Extensibility

  • It is a feature which allows the extension of the functionality of the existing software components.

  • In C++ this is achieved through abstract classes and inheritance.

Evolution of C++

  • The best feature of C and the key ideas of "Simula-67" are used to develop a new programming language called "C with classes" for effective event driven simulation.

  • The best features of "C with Classes" and the key idea of "Algol 68" incorporated to derive a new language called C++.

  • The following figure shows the evolution of C++.

 


Structured programming approach v/s OOPS

 

Structured Programming

OOPS

Emphasis is on the algorithm rather than the data

Emphasis is on the data.

Programs are divided into individual procedures that perform discrete tasks

Programs are divided into classes. The real time entities are represented by an instance of the class known as object.

As far as possible the procedures are independent of each other. Procedures have their own local data and processing logic.

Data and associated operations are unified into a single unit, thus the objects are grouped with common attributes, operations and semantics.

Follows top down approach

Follows bottom up approach

Maintenance of a large software system is tedious and costly.

Maintenance of a large software system is comparatively less tedious and inexpensive.

The data moves throughout the program. The scope of the data is throughout the program.

The scope of the data can be limited with the use of access specifiers.

Relationships can be created just for similar data types.

Relationships can be created between similar yet distinct data types.

Structure languages are not object oriented.

Object Oriented language are also structured language.

Structure Programming Language

ALGOL, Pascal, Ada, PL/1,

Popular OOPS Language

C++, JAVA, Charm++, Small Talk

 

Pr.Pg border                                              Next Pg