Monday, August 5, 2019

Features of C++ in programming

Features of C++ in programming Ans1. Unique features of C++ : Encapsulation: It is the process of combining data and functions into a single unit called class. Using the method of encapsulation, the programmer cannot directly access the data rather data is accessible through the functions present inside the class. It led to the important concept of data hiding. Abstraction: It is one of the most powerful and vital features provided by object-oriented C++ programming language. The main idea behind data abstraction is to give a clear separation between properties of datatype and the associated implementation details. Polymorphism: It is the ability to use an operator or function in different ways. Poly, referring to many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Inheritance: It is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived classes. C++ better than C: Stronger typing: the type system in C++ is stronger than in C. This prevents many common programming errors coupled with the next very important feature, the stronger type system even manages not be an inconvenience. A Bigger standard library: C++ allows the full use of the standard library. It includes the Standard Template Library. Parameterized types: the template keyword allows the programmer to write generic implementations of algorithms. Data and methods to edit the data act as one entity i.e. by the usage of classes. Limiting scope of data i.e. by using private/public variables. Constructors and destructors for defining default behaviour of entities. Ques2. Demonstrate the use of Inline Functions and Function Overloading. Ans2. An Inline function is a function that is expanded in line when it is invoked. This kind of function is used to save the memory space which becomes appreciable when a function is likely to be called a number of times. It is used to eliminate the cost of calls to small functions. Normally, a function call transfers the control from the calling program to the function and after the execution of the program returns the control back to the calling program after the function call but in inline function, when the program is compiled, the code present in the function body is replaced in place of the function call. Syntax: inline datatype function_name(arguments) { function body } Example: #include #include inline float mul(float x, float y) { return (x*y); } inline double div(double p, double q) { return (p/q); } int main() { clrscr(); float a= 12.345; float b= 9.82; cout

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.