Professional Documents
Culture Documents
Roll No : 032
1. Develop a program on function overloading by overloading
the function called as sum(or add) to perform five different
functionalities.
#include<iostream>
#include<string>
using namespace std;
int add(int,int);
float add(float,float);
double add(double,double);
double add(int,double);
double add(double,int);
string add(string,string);
int main()
{
double o = 12.54, p = 78.62;
int op;
if(op == 1)
{
int x,y;
cout << "Enter the first integer :";
cin >> x;
cout << "Enter the second integer :";
cin >> y;
cout << add(x,y) << "\n";
}
else if(op == 2)
{
double e,t;
cout << "Enter the first double :";
cin >> e;
cout << "Enter the second double :";
cin >> t;
cout << add(e,t) << "\n";
}
else if(op == 3)
{
float o,p;
cout << "Enter the first float :";
cin >> o;
cout << "Enter the second float :";
cin >> p;
cout << add(o,p) << "\n";
}
else if(op == 4)
{
float a;
int b;
cout << "Enter the first integer :";
cin >> b;
cout << "Enter the second double :";
cin >> a;
cout << add(b,a) << "\n";
}
else if(op == 5)
{
float c;
int d;
cout << "Enter the first double :";
cin >> c;
cout << "Enter the second integer :";
cin >> d;
cout << add(c,d) << "\n";
}
else if(op == 6)
{
string a,b;
cout << "Enter the first string :";
cin >> a;
cout << "Enter the second string : ";
cin >> b;
cout << add(a,b);
}
else
cout << "enter valid option";
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int op;
if(op == 1)
{
float r;
cout << "Enter the circle radius : ";
cin >> r;
cout << "THE AREA OF CICLE IS : " << area(r);
}
else if(op == 2)
{
int s;
cout << "Enter the side of square : ";
cin >> s;
cout << "THE AREA OF SQUARE : " << area(s);
}
else if(op == 3)
{
int a,b;
cout << "Enter the width of rectangle : ";
cin >> a;
cout << "Enter the lenght of rectangle :";
cin >> b;
cout << "THE AREA OF RECTANGLE : " << area(a,b);
}
return 0;
}
float area(int a)
{
float A;
A = a*a;
return A;
}
Name : Jaydev Jadav B.
Roll No : 032