Advert

Overloading Unary Operators

Last edited by . Total of no comments in the discussion.

Unary operators are the ones that operate on one operand, one such operator is the unary minus (-) operator which is used to change the sign of the operand it acts upon. This operator works well with basic data types such as int, float, etc.. In this section we will see how to overload this operator so that it can work the same way for user defined data types as it does for basic data types, i.e. change the sign of the operand. The unary minus operator function does not Read More

Share on:

Inline Function

Last edited by . Total of 1 comment in the discussion.

One of the main objectives of using functions in a program is to save some memory space, which becomes appreciable when a function is likely to be called many times. However, every time a function is called, it takes a lot of extra time in executing a series of instructions for task such as jumping to the function, saving register, pushing arguments into the stack, and returning to the calling function. When a function is small, a substantial percentage of execution time may be spent in such overheads. One solution Read More

Share on:

Heaps

Last edited by . Total of 1 comment in the discussion.

A heap is a binary tree that satisfies the following properties: Shape property Order property By the shape property, we mean that a heap must be a complete binary tree. A complete binary tree has all its levels filled, except possibly for the last, where the leaves must be located as far to the left as possible. By the order property, we mean that for every node in the heap, the value stored in that node is greater than or equal to the value in each of its children. A Read More

Share on:

Recursion

Last edited by . Total of 1 comment in the discussion.

Recursion is an ability of a program to call itself, either directly or indirectly. Its a programming technique that naturally implements the divide and conquers programming approach. It does the task of calling itself. To do this, it must reduce its size upon every call; else, the process will become infinite. Type of Recursion Direct Recursion Indirect Recursion Example: To compute factorial of a number The above program works as follows, fact(5) = {if(5= =1) is false thus return 5* fact (4)} fact(4) = {if(4= =1) is false thus return Read More

Share on:

Address Calculation Sort

Last edited by . Total of no comments in the discussion.

In this method, a function fn() is applied to each key. The result of this function determines into which of the several sub-files the record is to be placed. The function should have the property that x <= y, fn (x) <= fn (y). Such a function is called order preserving. Thus all of the records in one sub-file will have keys that are less than or equal to the keys of the records in another sub-file. An item is placed into a sub-file in correct sequence by using any Read More

Share on:

Sorting

Last edited by . Total of 2 comments in the discussion.

Sorting is the process of arranging elements in some logical order. Sorting methods are classified into the following categories: External sorting: This deals with sorting of data stored in external files. This method is used when the volume of data is very large and cannot be held in a computer’s RAM. Internal sorting: This deals with sorting of data held in the RAM of a computer. Sorting Methods The following are links to tutorials on some of the most popular sorting methods: Bubble sort Bucket sort Insertion sort Merge sort Read More

Share on:

Friend Function

Last edited by . Total of no comments in the discussion.

The private data members of a class cannot be accessed by functions that are not a part of the class. The access to such members can only be given to the functions by specifying the function as friend of the class whose data structures are required by the function. In simple words, we can say that a friend function has an advantage of having an access to the private data members of the friend class. A function can be specified as a friend of a class by including its prototype Read More

Share on:

if Statement

Last edited by . Total of no comments in the discussion.

An if/else statement tests a particular condition, if the condition evaluates to true, a course-of-action is followed i.e. a statement or a set of statements is executed. Otherwise another set of instructions are executed (the else block). Such statements are called program control statements that control the flow of execution in a program. Normally, the statements are executed sequentially as written in the program. This is known as normal flow of control. But sometimes, the flow of control of a program has to be altered depending upon certain conditions. The Read More

Share on:

Arrays

Last edited by . Total of no comments in the discussion.

An array is a collection of C or C++ data elements or objects of the same type. Individual elements of an array are referenced using one or more integer indices. A one-dimensional array is defined with a statement such as double vector[50]. This defines (and allocates space for) 50 variables of type double that are contiguously located in storage. This means that 50 different values can be stored without having to initialize 50 different variables, each one with a different identifier. Instead an array can store 50 different values of Read More

Share on:

this Pointer

Last edited by . Total of no comments in the discussion.

On defining a class, the member functions are created and placed in the memory space only once i.e., only one copy of member functions are maintained, that is shared by all the objects of the class. Memory space for the data members is allocated separately for each object. This has an associated problem. If only one instance of member functions exist, how does the compiler come to know which object's data member is to be manipulated? For example, if member-function3 is capable of changing the value of data-member2 and the Read More

Share on: