Program to attain polymorphism through Function Overloading :-
#include<iostream.h>
#include<conio.h>
void sum(int a,int b)
{
cout<<"\nSum of the numbers is : "<<(a+b);
}
int sum(int a, int b, int c)
{
return(a+b+c);
}
void main()
{
int a,b,c,x;
menu:
cout<<"\nEnter number of terms you want to add (2/3) : ";
cin>>x;
if(x==2)
{
cout<<"\nEnter the terms to be added : ";
cin>>a>>b;
sum(a,b);
}
if(x==3)
{
cout<<"\nEnter the terms to be added : ";
cin>>a>>b>>c;
cout<<"\nSum of the terms is : "<<sum(a,b,c);
}
goto menu;
getch();
}
No comments:
Post a Comment