Owner: Learning Computer Programming URL:http://learning-computer-programming.blogspot.com Join Date: Tue, 12 Jun 2007 04:07:38 -0500 Rating:0 Site Description: I post articles, tips, tricks, techniques, algorithms etc. related to C++ Programming. Many of the things that I discuss also applies to other programming languages. Site statistics:Click here
Algebra of Matrices (2D Arrays) 2007-06-26 00:58:00 In the programming sense, Matrices are Two Dimensional or 2D arrays. Just as
Matrices have rows and columns, similarly 2D arrays too have rows and columns.
There are many mathematical operations like addition, subtraction, multiplication
etc. which can be performed on matrices, and therefore to 2D arrays also. In
this article, we will be discussing about the addition and subtraction of two
2D arrays (Matrices).
Addition of two Matrices (2D arrays)
For addition of two matrices both the matrices must have the same dimension.
Ex. if matrice one has the dimension p x q then matrice two must have the dimension
p x q.
In the addition process, each of the element of the first matrice is added
to the corresponding element of the second matrice and result is stored in the
third matrice having the same dimension (i.e. p x q). Below is the algorithm
for adding two matrices.
Algorithm for adding two Matrices
Suppose,
Two 2D arrays to be mat1 [p][q] and mat2 [p][q] having p rows and q columns
re
Simple Problems in C++ Part IV 2007-07-01 07:38:00 Take a break and have a look at these problems!
Problem 1: Write a Program in C++ to print the following pattern.
Example:
**********
********
******
****
**
Solution:
// Example Program in C++
// to print a pattern
// that looks like a reverse
// pyramid of '*'
#include<iostream.h>
void main(void)
{
int i,j,k;
for(i=0;i<=10;i++)
{
for(j=5;j<i+5;j++)
cout<<" ";
for(j=5;j>i;j--)
cout<<"*";
for(j=5;j>i;j--)
cout<<"*";
cout<<endl;
}
}
Problem 2: Write a program in C++ to find the row sum and column sum
of a two dimensional array.
Example:
1 2 3 = 6
4 5 6 = 15
7 8 9 = 24
12 15 18
Solution:
// Example Program in c++ to find the
// row sum and column sum of a 2
// dimensional array
#include<iostream.h>
void main(void)
{
int arr[3][3]={1,2,3,4,5,6,7,8,9};
int row_sum[3], col_sum[3];
int i,j;
for(i=0;i<3;i++ Read more:Simple
Insertion and Deletion of elements in a Sorted Array 2007-07-01 01:37:00 In the article Insertion
and Deletion of elements
in an Array
, we saw how data is inserted and
deleted in an unsorted array. In that case, we needed two information, the element
as well as the position, for insertion while for deletion we needed the position.
In the case of sorted arrays insertion and deletion takes pace in a slightly
different way.
The following example will clarify this:
Suppose we have the following array:
arr[5]={1,2,3,4,5}
And, we need to insert the element 6, so where it should be inserted? We can’t
insert it at any place because then the array might not remain sorted. Therefore,
we let the program to automatically calculate the position suitable for the
new element, so that the array remains sorted even after insertion.
Now, arr[5]={1,2,3,4,6}
Now, suppose we wish to delete the element 6, in this case we don’t use
the position for deletion because we don’t know where the element was
placed by the program, so rather than referencing the position for deletio Read more:Sorted
Data Structures: Introduction to Stacks 2007-06-30 08:30:00 In the previous article, we saw how data is inserted and deleted in an array.
In that case we could insert data at any place throughout the array. However,
there are situations when we only need to add and retrieve data form the ends
of the array. Stacks are one of the examples of this.
Stacks are data structures in which data could be added and retrieved only
from one end (also known as the TOP of the stack). Suppose we insert 5, 6, 9
to the stack consecutively then while retrieving the first one to be retrieved
will be 9 then 6 and then 5. That is why stacks are also known as Last-In-First-Out
(or LIFO) structure.
A few terms regarding stacks:
Stack: Stack is a user-defined data structure. It is most
commonly represented by linked-lists and arrays. In this article, we will
be representing stacks with arrays.
Push: Adding data to the stack is known as pushing.
Pop: Retrieving data from the stack is known as popping.
Let us have look at this process with the help of an example. Read more:Structures
, Introduction
Insertion and Deletion of elements in an Array 2007-06-30 00:57:00 Suppose you are storing temperature data for a few months and you forgot to
store the temperature of a particular day (say 5th day) then you need to INSERT
that temperature after the 4th element of the array and in the other case if
you accidentally stored duplicate data then you need to DELETE the duplicate
element.
Apart from these simple examples, there are many other uses of insertion and
deletion
The array to which the element is to be inserted or deleted can be of two types
unordered (unsorted) and ordered (sorted). Here we will be discussing about
the insertion and deletion of element in an unordered or unsorted array.
For insertion in these types of arrays, we need to have two information, the
element to be inserted and the position to which it will be inserted. For deletion,
we only need the position.
Suppose we have the following array:
arr[5]={5,7,2,1,3}
And we need to insert the element 6 at the 2nd position, after insertion:
arr[5]={5,6,7,2,1}
Notice how the last element o Read more:elements
, Array
Data Structures: Introduction to Queues 2007-07-04 08:43:00 Queue is a linear data structure in which data can be added to one end and
retrieved from the other. Just like the queue of the real world, the data that
goes first into the queue is the first one to be retrieved. That is why queues
are sometimes called as First-In-First-Out data structure.
In case of queues, we saw that data is inserted both from one end but in case
of Queues; data is added to one end (known as REAR) and retrieved from the other
end (known as FRONT).
The data first added is the first one to be retrieved while in case of queues
the data last added is the first one to be retrieved.
A few points regarding Queues:
Queues: It is a linear data structure; linked lists and
arrays can represent it. Although representing queues with arrays have its
shortcomings but due to simplicity, we will be representing queues with
arrays in this article.
Rear: A variable stores the index number in the array
at which the new data will be added (in the queue).
Front: It is a variable Read more:Structures
, Introduction
Introduction to C++ Preprocessor Directives 2007-07-03 07:51:00 As the name suggest, C++ Preprocessor is an integrated program in C++ that
preprocesses every program we write before compilation.
Preprocessor commands or directives are special functions that are executed
or processed before the compilation of the program.
Although we can write program without the knowledge of preprocessor directives
but why underutilize features when we have them?
Every preprocessor directive starts with a # symbol. While
we can have them anywhere in the program but they are almost always used at
the starting of the program before any function is defined.
Knowingly or unknowingly, we have been using one preprocessor directive. It
is the #include directive, which is most commonly used to include
header files in the program.
While there are many types of preprocessor directives, here we will only be
discussing about Macro Expansion directives and that also in the simplest sense!
Macro Expansion Directives
Have a look at the code below:
#define MAX 10
cout<<M Read more:Introduction
Merging One Dimensional Arrays 2007-07-10 01:08:00 Merging of two arrays means to form one big array from two small arrays, which
has element from both the arrays linearly.
Ex. if we have the following two arrays:
array1 [5] = {1,2,3,4,5}
array2 [5] = {6,7,8,9,10}
and we merge these two arrays to form an array merge_array, then it would have
these elements:
merge_array [5] ={1,2,3,4,5,6,7,8,9,10}
So, from this example we understand that the array which will hold the merged
elements should have a dimension equal to the sum of the dimensions of the two
discrete arrays.
It is no big deal to merge two arrays, we just need to sum up the dimension
of the arrays, and then allocate an array having that dimension.
Below is the example program that illustrates this.
Please go through the program to understand every bit of it. It is accompanied
with enough comments to make everything clear. While two arrays has been merged
here, you can easily modify it to merge as many arrays as you wish.
// -- Array Merging --
// -- Read more:Merging
Computer Programming: An Article for Beginners 2007-07-09 01:07:00 -Article
of the Month
You might have read many so-called “the art of computer programming an” and
many “how to …” on computer programming, but this one is different. It doesn't’t
deals with the technical details of programming rather it deals with what is
more important to beginners. This article would help beginners who are having
a tough time with programming to get to the right track.
It is also for newcomers who want to start programming and want to choose the
right programming language. It is not just another guide to learn computer programming;
it helps you to minimize your confusions while learning computer programming.
It is not an article which talks about the history or something like that,
it is a practical guide. This article is written keeping in mind what the beginner’s
confusions are and how to minimize them.
Careers in ComputerProgramming
As a professional having a degree from any reputed institution you have a good
chance of making a career in compute Read more:Computer Programming
Sorting Two-Dimensional Arrays 2007-07-08 00:56:00 Do you know how a 2D array is stored in the memory while the memory is only
one-dimensional?
The answer is simple, all the arrays are stored linearly in the memory, be
it 2D array or 3D, only the representation is such that to make it easy to reference.
Therefore, if a two-dimensional array has the following elements:
1 2 3
4 5 6
7 8 9
in the memory, it will be like this:
1 2 3 4 5 6 7 8 9
just because memory is linear, and cannot have dimensions. It is the language
that represents 2 D arrays as such while in the memory it is always linear.
This property of 2D arrays will be used to sort them, because sorting linear
data is much easier.
We don’t need much discussion on this, so here is the example program,
please read the comments where all things are elaborated
// --Sorting
Program--
// -------------------
// Example Program to sort
// 2D array using linear
// representation of the array
#include<iostream.h>
#define MAX 3
void main(void
Introduction to Recursive Functions 2007-07-14 01:28:00 Recursion is a process of defining something in terms of itself. Function recursion
therefore means to define a function in terms of itself, in other words a function
that calls itself inside its body is known as recursive functions.
Example:
void func (something)
{
something…
something…
func(something);
}
Notice how the function func () is calling itself!
Why use recursive Functions
?
In most cases recursive functions can be replaced by iterative statements,
then why use recursive functions?
Here are a few points that justify its use:
Recursive functions make the code easier and simpler to understand.
There are certain algorithms that could be very easily implemented using
recursion but are pretty much difficult to implement using iterative or
other non-recursive methods.
Some of the people tend to think recursively, so their thoughts can be
better implemented using recursion.
Below is a Read more:Introduction
Pointers to Function 2007-07-13 00:50:00 Function Pointers
is a rather confusing yet powerful feature of C++ programming
language. Even if you have programming for a while I bet you have seen nothing
like it, simply because they aren't’t needed in everyday programming.
Their most common use is in writing compilers and interpreters.
The main theory behind function pointers is, just like the contents of a variable
can be accessed by a pointer, much the same way functions can also be invoked
(called) by referencing it by a pointer to that function.
Although variables and functions are two separate identities, both of these
are stored at some memory address which can be pointed (and hence accessed)
by a pointer.
Going in detail of the working of function pointers will only confuse you so
we skip that for now and move on to a simple example program.
The function defined in the program is made as simple as possible to reduce
confusions. Please note that the program only illustrates how function pointe
Your Questions my Answers 2007-07-11 01:48:00 [I have started this new section in which I will answer your questions publicly.
Therefore, if you are having any confusions or problems, you can e-mails me at
one.arvind@gmail.com. Please note that…
read
more]
Problem: I want to sort each row of a matrix in ascending order,
after which I need to display another matrix whose elements are the column indices
of the elements of the original matrix with respect to the corresponding elements
of the sorted matrix. Please give a program to do so.
eg.
Original matrix={
{9,4,2},
{7,3,8}
};
Sorted Matrix= {
{2,4,9},
{3,7,8}
};
Column Index= {
{2,1,0},
{1,0,2}
};
Dominic [*], Student, Nigeria
[* Last Name Deleted on Request]
Solution: Nice question Dominic, here is the solution. I will
not discuss anything here as I have included enough comments in the program
itself.
// C++ progra
Ask Your Questions 2007-07-11 01:38:00 Few days back when I was going through my inbox, I saw a few e-mails of peoples
asking for solutions to their problems. Some of questions were so generic that
it could come up in anybody’s mind. So I thought of answering a few generic
questions publicly so that it could benefit others also.
Therefore, if you are having any confusions or problems, you can e-mails me
at one.arvind@gmail.com
Please note that only selected questions will be answered here; all the others
will be answered by e-mail (as many as possible).
After writing this the number of e-mails will definitely increase, so please
be patient as it may take a little while before I could answer them.
The questions will be published along with your Name, Country and e-mail
address (if only you wish it to be published), so please include them with your
e-mail.
Don’t hesitate
E-mail me at: one.arvind@gmail.com
Good-Bye!
[NOTE: Before you ask, please use the search feature of this blog,
who knows if the answer to your problem
Merging Two-Dimensional Arrays (Matrices) 2007-07-16 04:54:00 In the article Merging
One Dimensional Arrays, we discussed how to merge one-dimensional
arrays, in this article we will be discussing about the merging of two-dimensional
arrays. Merging as you know is the process of combining two similar things.
In the context of arrays, it means to form a big array from two smaller arrays
which has all the elements from both the arrays.
In case of one-dimensional arrays there is only one way in which two arrays
can be merged but in case of two-dimensional arrays there are two ways.
Suppose, we have the following two 2d arrays (matrices):
mat1={
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}
and
mat2={
{10, 11, 12},
{13, 14, 15},
{16, 17, 18}
}
then they can be merged in the following two ways:
merge_row={
{1, 2, 3, 10, 11, 12},
{4, 5, 6, 13, 14, 15},
{7, 8, 9, 16, 17, 18}
}
merge_col={
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
Introduction to Linked Lists Part II 2007-07-16 02:02:00 In the previous article Introduction
to Linked Lists
, we introduced the basic concept of linked list. To
make the program (an the article) as simple as possible, we discussed only the
addition and display of nodes in the linked list although necessary we didn't’t
discussed the deletion of node in that article.
In this article we will be discussing about the deletion of nodes from linked
lists.
Deletion of node (elements) from a linked list
The node to be deleted can be represented by many ways but here we will be
representing it by its info. So if we have the following linked list
And we want to delete node1 then we will express it by its info part (i.e. 10).
The main theory behind deletion of nodes is pretty simple. We need to make
the link pointer of the node before the target node (to be deleted) to point
at the node after the target node. Suppose if we wish to delete node having
info as 10 from the above linked list then it will be accomplish
Introduction to Linked Lists 2007-07-15 01:49:00 We have been using arrays to store similar data linearly. While arrays are
simple to understand and easy to implement in common situations, they do suffer
from some drawbacks which are listed below:
Arrays have fixed dimensions, even if we dynamically allocate the dimension
it remains constant throughout. So there is a limit to the number of elements
it can store.
Operations such as insertion and deletion are pretty much difficult to
implement and increases the overhead because these operations require elements
in the array to be physically shifted.
Linked lists overcome these drawbacks and are commonly used to store linear
data.
Actually elements of linked lists (called as nodes) store two information,
data and the link (pointer) pointing to the next elements (node).
The elements (nodes) are linked sequentially with the help of link pointers.
So we can say that linked lists are collection of nodes which have data and
are linked sequentially so that all the nodes or elements are Read more:Introduction
, Lists
Macros with Arguments 2007-07-18 08:05:00 Have a look at the following code:
#include<iostream.h>
#define MAX 10
void main(void)
{
for(int i=1;i<=MAX;i++)
cout<<i<<endl;
}
Above we have used the type of macro expansion that we learnt in the article
Introduction to C++ Preprocessor Directives
Do you know that just like functions we can have arguments in the macros too!
The following code shows how:
#include<iostream.h>
// this is how macros with
// arguments are defined
// NOTE: THERE SHOULD NOT BE
// ANY SPACE BETWEEN THE
// MACRO TEMPLATE (i.e. AREA)
// AND THE PARANTHESIS
// CONTAINING THE ARGUMENTS
// (i.e. (x))
#define AREA(x) (x*x)
void main(void)
{
// calling a macro
// is almost similar
// to calling a function
cout<<AREA(10);
}
It is that simple! However, keep one thing in mind as stated in the comments
not to put any space between the macro template and the braces containing the
argument.
#define AREA(x)
Hurray! My 50th Post 2007-07-18 08:02:00 I am so glad to inform you all that this is my 50th post
on this blog. In the span of 57 days this blog has grew in terms of both content
and readership.
I won’t take much of your time saying it out loud
but I want to thank all of my readers and subscribers for their valuable co-operation!
Thanking You
Arvind Gupta
Introduction to Basic Encryption and Decryption 2007-07-18 01:34:00 Encryption is a familiar sounding word which means to convert readable data
in such a form that it becomes un-understandable or un-meaningful. It is employed
almost everywhere where any confidential data is needed to be kept or transferred.
Encryption goes hand in hand with decryption which means to convert un-meaningful
encrypted data to its original meaningful form.
Here in this article we are going to design two functions, one for encryption
and other for decryption, to illustrate the basic concept of encryption and
decryption.
Please note that the example program provided in this article is for illustrative
purpose only, there are a few limitations in the program which limits its practical
use.
How encryption and decryption works?
The main concept behind encryption is to convert the readable data into something
which looks un-meaningful to us. It could be achieved in various ways but the
simplest one is to change the ASCII code of the data.
Ex.
#include Read more:Introduction
, Basic
, Encryption
Changing the case (lower, upper) of Strings 2007-07-17 07:25:00 In this article, we will be designing two functions to change the case of strings.
One would change a string from lower case to upper case while the other would
do the opposite.
Although we have pre-defined functions for doing this in a header file, but
this article is for those who dare to know how all these operations are done
internally.
Changing
the case: How is it done?
The main theory lies in the way C++ treats character constants and strings.
Have a look at the following code:
#include<iostream.h>
void main(void)
{
char first='A';
char second=65;
cout<<first;
cout<<endl;
cout<<second;
cout<<endl;
}
whose output is:
A
A
Press any key to continue
This is because ‘A’ and its ASCII code 65 are equivalent to the
compiler and in c++ we can manipulate it in whatever way we like.
Now look at the following code:
#include<iostream.h>
void main(void)
{
char arr[4]="ABC";
char arr2[4]={65,66,67};
Increase your Programming Skills II 2007-07-21 07:46:00 This is the continuation of the last article… Increase
your ProgrammingSkills
Solve the problems listed here to gain programming skills.
Problem #5:
// Problem or Question in C++
// --------------------------
// Problem related to pointers
// for increasing programming
// skills
#include<iostream.h>
void main()
{
char ch1[]="Programming";
char ch2[]="Skills";
char *s1=ch1;
char *s2=ch2;
while(*s1++=*s2++);
cout<<ch1;
}
Problem #6:
// Problem or Question in C++
// --------------------------
// Problem related to pointers
// for increasing programming
// skills
#include<iostream.h>
void main()
{
int i, *j;
i=1;
j=&i;
cout<<i**j*i+*j;
}
Problem #7:
// Problem related to pointers
#include<iostream.h>
void main()
{
int ar[]={1,2,3,4,5};
char *p;
p=(char *)ar;
cout<<*((int *)p+3);
}
Problem #8:
// Problem related to po
Increase your Programming Skills I 2007-07-21 07:42:00 Here I have listed some selected problems or questions related to pointers
in C++. Solve them to increase your programming skills.
Problem #1:
// Problem or Question in C++
// --------------------------
// Problem related to pointers
// for increasing programming
// skills
#include<iostream.h>
void main()
{
char ch[]="I_Like_C++";
cout<<*&*&ch;
}
Problem #2:
// Problem or Question in C++
// --------------------------
// Problem related to pointers
// for increasing programming
// skills
#include<iostream.h>
void main()
{
int i,*p,**q,***r;
i=10;
p=&i;
q=&p;
r=&q;
cout<<i<<*p<<**q<<***r;
}
Problem #3:
// problem related to pointers
#include<iostream.h>
void main()
{
char ch[]="ProgrammingSkills
";
char *s=ch;
cout<<s+++3;
}
Problem #4:
// Problem related to pointers
#include<iostream.h>
void
Introduction to Linked Stacks 2007-07-20 01:47:00 In the article Data
Structures: Introduction
to Stacks, we saw that there was one major
disadvantage of representing stacks using arrays- the stack like the array could
have a limited number of elements, while stacks should be able to grow up to
any number of elements. Besides this there were other disadvantages too.
In one of the other article about Linked
Lists, we noticed one useful property of linked lists that they can
grow up to any size to accommodate for the addition of elements and it efficiently
uses the memory too.
So if we combine both of this to from a linked version of the stack then it
won’t have the shortcomings that the array version had.
This is what this article is all about.
pushing and popping
As you know that addition of elements to the stack is known as pushing while
retrieval is known as popping.
The process of pushing and popping in case of linked version of stack is slightly
different from the array version. The following g
Introduction to Linked Lists III 2007-07-23 08:46:00 In the article Introduction
to Linked Lists
, we introduced the concept of linked list, the example
program was programmed to be able to add and display the elements in the linked
list. In reality only addition of elements to the linked list is not enough
to take the most out of linked list; we should be able to do other operations
such as insertion, deletion of elements etc.
This article would teach you to do such operation (insertion, addition, deletion
etc).
The program itself is quite big and has enough comments so I won’t discuss
anything here; rather I leave it up to you to understand all the operations
yourself!
// -- Linked Lists --
// ------------------
// Example program to illustrate
// addition, insertion, deletion
// and display of nodes in the
// linked list
#include<iostream.h>
// node class, this will
// represent the nodes or elements
// of the linked list
class node
{
public:
int info;
node *li
Introduction to Linked Queues 2007-07-23 01:39:00 In one of the article Introduction
to Linked Stacks, I said that representing data structures such as
Stacks and Queues as arrays had one major problem that it can’t have more
than a predefined number of elements. To overcome this we used linked lists
to represent stacks. In this article we’ll use linked lists to represent
queues.
Below are some graphics that illustrate the addition and retrieval of elements
to and from the linked queue.
FIG.: Addition of data to the linked queue
FIG.: Retrieval of elements from the linked
queue
I don’t think there is anything more that needs to be discussed, so let’s
have a look at the example program:
// -- Linked Queues --
// C++ Example Program to
// illustrate the representation
// of queues as linked lists
#include<iostream.h>
// node class, this will
// represent the nodes or elements
// of the linked queues
class node
{
public:
int info;
node *link;
};
// declare global objects
no
Increase your Programming Skills III 2007-07-22 00:48:00 Here I have listed some questions related to strings in c++, solve them to
increase your programming skills.
Problem #1:
// Problem related to strings
#include<iostream.h>
void main(void)
{
char ch[]="ProgrammingSkills
";
int i=0;
cout<<ch[++i];
cout<<ch[i++];
cout<<i++[ch];
cout<<++i[ch];
}
Problem #2:
// Problems related to strings
#include<iostream.h>
void main(void)
{
char ch[]="Programming Skills";
char *s="Programming Skills";
cout<<sizeof(ch)<<sizeof(s);
cout<<sizeof(*ch)<<sizeof(*s);
}
Problem #3:
// Problems related to strings
#include<iostream.h>
void main(void)
{
int n[]={4,3,2,1,0};
for(int i=0;i<5;i++)
cout<<n[n[i]];
}
Problem #4:
// Problems related to strings
#include<iostream.h>
void main(void)
{
int n[]={11,10,9,8,7,6,5,4,3,2,1,0};
char ch[]="C++ Language&q
How String Functions (strinh.h) Work? 2007-07-26 08:57:00 In the previous article String
Manipulation Functions
(string.h), we had a look at some of the commonly
used string manipulation functions. There is no denying the fact that those
functions are useful but have you ever wondered how those functions actually
work or what is the algorithm behind their working?
If yes then read on…
In this article I am going to present you with our own version of the string
manipulation functions that we had discussed, namely strlen(), strcpy(),
strcat() and strcmp(). Our versions will do the same thing as done
by the original functions but surely they would teach us a lot!
Let's have a look at them one-by-one:
mystrlen
// mystrlen- function
#include<iostream.h>
int mystrlen(const char *);
void main(void)
{
char ch[]="This is great!";
cout<<"Length:"<<mystrlen(ch);
}
int mystrlen(const char *str)
{
int len=0;
while(str[len]!=' ')
len++;
return len;
}
mystrcpy
// mystrcpy- function
#inclu
String Manipulation Functions (string.h) 2007-07-24 08:33:00 This article discusses about the classic string manipulation functions defined
in the string.h header file.
From quite a while peoples have been asking me to write an article on the standard
library string manipulation functions. These functions are defined in the string.h
header file, so you must include it to use them.
There are dozens of string functions in the string.h header
file and thus it is difficult to list them all. So rather than listing them
all I would be discussing in detail about only few commonly used string manipulation
functions along with an example program illustrating how each function is used.
strlen:
Prototype: int strlen(const char *string);
This function takes the base address of the string as the argument and returns
the number of characters in it (including spaces).
// strlen() string manipulation
// function
#include<iostream.h>
#include<string.h>
void main(void)
{
char ch[]="String Manipulation
" Read more:Functions
What is Polymorphism? 2007-07-28 08:37:00 Polymorphism means to have one interface for different methods or functions.
It is the ability through which we can do different operations (by calling different
functions) from the same interface.
In C++ functions and operators can be made to be polymorphic, but in this article
we’ll only be discussing about polymorphic functions.
There can be two types of polymorphism which are discussed below:
Compile-Time Polymorphism: When we have two or more polymorphic function (overloaded
functions) and the call to a particular function is resolved (or known) at the
compile-time, it is called compile-time polymorphism.
The following example program illustrates this. Please read the comments for
further information.
// program to demonstrate
// compile-time polymorphism
#include<iostream.h>
// -- FUNCTION PROTOTYPES --
// -- OVERLOADED FUNCTIONS --
void func(int);
void func(char *);
// -- ENDS --
void main()
{
/