You are on page 1of 7

Name : Jaydev Jadav B.

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;

cout << "......SELECT THE OPTION........" << "\n";


cout << " 1 : sum of integer "<< "\n";
cout << " 2 : sum of double "<< "\n";
cout << " 3 : sum of float "<< "\n";
cout << " 4 : sum of integer or double "<< "\n";
cout << " 5 : sum of double and integer "<< "\n";
cout << " 6 : sum of two string "<< "\n";

cout << "Enter the option :";


cin >> 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;
}

int add(int a,int b)


{
int c;
c = a + b;
return c;
}

float add(float a,float b)


{
float c;
c = a + b;
return c;
}

double add(double a,double b)


{
double c;
c = a + b;
return c;
}

double add(int a,double b)


{
double c;
c = a + b;
return c;
}

double add(double a,int b)


{
double c;
c = a + b;
return c;
}

string add(string s1,string s2)


{
string s;
s = s1+ s2;
return s;
}
2. Develop a program on function overloading by overloading
the function called as area to calculate the area of circle,
square and rectangle.

#include<iostream>
using namespace std;

float area(float, float PI = 3.1415926);


float area(int);
int area(int,int);

int main()
{
int op;

cout << "..........SELECT THE OPTION.........."<< "\n";


cout << " 1 : AREA OF CICLE" << "\n";
cout << " 2 : AREA OF SQUARE" << "\n";
cout << " 3 : AREA OF RECTANGLE" << "\n";

cout << "ENTER THE OPTION : " << "\n";


cin >> 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(float a,float b)


{
float A;
A = b*a*a;
return A;
}

int area(int a,int b)


{
float A;
A = a*b;
return A;
}

float area(int a)
{
float A;
A = a*a;
return A;
}
Name : Jaydev Jadav B.
Roll No : 032

You might also like