Advert

Virtual Functions

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

Dynamic polymorphism allows programmers to write code using functions applied to objects of the base class without worrying about how those functions will actually be defined by derived classes. For instance, programmers might call functions on a Shape object that computes its area or perimeter, without concerning themselves with the actual (derived) type of the object, whether it is a Rectangle, Square or Circle. An essential requirement to take advantage of polymorphism in C++ is that there should be a way by which it is possible to refer to objects Read More

Share on:

Binary Tree – Searching a Node

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

An element in a binary search tree can be searched very quickly. A search operation on binary tree is similar to applying binary search technique to a sorted linear array. The element to be searched will be first compared with root node. If it matches with the root node then the search terminates. Otherwise search is continued in the left sub tree if the element is less then the root or in the right sub tree if the element is greater then the root. Suppose we try to find a Read More

Share on:

Type Conversion – Basic to Class Type

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

The conversion from basic to user defined data types can be done using constructors. Consider the following constructor: .cf { font-family: Lucida Console; font-size: 9pt; color: black; background: white; } .cl { margin: 0px; } .cb1 { color: green; } .cb2 { color: blue; } .cb3 { color: maroon; }   String :: String(char *a) { length = strlen(a); s = new char[length+1]; strcpy(s,a); }   The above constructor definition is used to construct a String type object from a char * type variable. The String class has two data Read More

Share on:

File Input/Output

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

In C++, file input/output services are implemented through a component header file available C++ standard library. This header file is fstream.h . In C++, a file, at its lowest level, is interpreted simply as a sequence, or stream, of bytes. One aspect of the file I/O library manages the transfer of these bytes. At this level, the concept of a data type is absent. On the other hand, file, at the user level, consists of a sequence of possibly intermixed data types – characters, arithmetic values, class objects etc. A Read More

Share on:

Queues

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

A queue is a line of persons waiting for their turn at some service counter. The service counter can be a ticketing window of a cinema hall, a railway station, etc. Depending on the type of service provided by the service counter and number of persons interested in service, there could be queues of varying lengths. The service at the service counter is on the first come first serve (FCFS) basis, i.e., in order of their arrival in the queue. Suppose that at a service counter, t1 units of time Read More

Share on:

Exception Handling

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

Exceptions are of two kinds, namely, synchronous exceptions and asynchronous exceptions. Errors such as "out-of-range index" and "over-flow" belong to the synchronous type exceptions. The errors that are caused by events beyond the control of the program (such as keyboard interrupts) are called asynchronous exceptions. The proposed exception handling mechanism in C++ is designed to handle only synchronous exceptions. The purpose of the exception handling mechanism is to provide means to detect and report an exceptional circumstance or condition, so that appropriate action can be taken against it. The mechanism Read More

Share on:

Structures

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

Structure is a collection of variables referenced under a common name. Sometimes, some logically related elements need to be treated under one single unit. For instance, the elements that store student information (e.g., rollnumber, name, class, marks and grade) need to be processed together under one roof. Defining a structure: struct tag-name { Member1 ; Member2 ; Member3 ; } ; struct is a required keyword to define a structure. tag-name is the name that identifies the structure. member1, member2 and member3 are the members of the structure. Complex data Read More

Share on:

Classes

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

A class is an approach to bind the data, describing the entity or an object, and its associated functions together. In C++, a class creates a data-type that is used to create objects of that particular type. Class represents a group of similar objects. Example: class account { private: int accoutno; char type; float balance; public: float deposite(float amount) { balance += amount; return balance; } float withdraw(float amount) { balance -= amount; return balance; } }; In the above example, the data describing an account object (i.e. accountno, type Read More

Share on:

Iterations

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

An Iteration involves repeating some portion of a program, a specified number of time or until a particular condition is satisfied. This repetitive operation in C and C++ is achieved through for, while and do–while loop. How does a for loop work? A for loop is the easiest iteration loop to understand the C and C++ loops. All the loop elements are gathered at one place unlike the other loops, where, the loop elements are scattered all over the loop body. Syntax: for( initialization ; condition ; increment or decrement Read More

Share on:

Functions

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

A function is a named unit of a group of program statements. This unit can be invoked from other parts of the program. A programmer can solve a simple problem in C++ with a single function. Difficult and complex problems can be decomposed into sub-problems, each of which can be either coded directly or further decomposed. Decomposing difficult problems, until they are directly code-able as single C++ functions, is a software engineering method of stepwise refinement. These functions are combined into other functions and are ultimately used in main() to Read More

Share on: