18
18
18
#include <iostream>
using namespace std;
int main()
{
int a = 10, b = 20;
float c = 3.14, d = 2.718;
char e = 'A', f = 'B';
cout << "Before interchanging:\n";
cout <<"a= " << a <<", b= " << b << endl;
cout << "c= "<< c <<", d= "<< d << endl;
cout << "e= "<< e <<", f= "<< f << endl;
interchange(a, b);
interchange(c, d);
interchange(e, f);
cout << "\nAfter interchanging:\n";
cout <<"a= "<< a <<", b= "<< b << endl;
cout << "c= "<< c <<", d= "<< d << endl;
cout << "e= "<< e <<", f= "<< f << endl;
return 0;
}
/*Output:
Before interchanging:
a= 10, b= 20
c= 3.14, d= 2.718
e= A, f= B
After interchanging:
a= 10, b= 20
c= 3.14, d= 2.718
e= A, f= B*/
/* Name: Daphal Atul Sanjay
Enrollment No.: 23210270283
2. Write a C++ Program that find the sum of two int and double number
using function overloading.*/
#include <iostream>
using namespace std;
int main()
{
int x = 5, y = 10;
double m = 3.14, n = 2.718;
int intSum = sum(x, y);
double doubleSum = sum(m, n);
cout << "Sum of integers: " << intSum << endl;
cout << "Sum of doubles: " << doubleSum << endl;
return 0;
}
/*Output:
Sum of integers: 15
Sum of doubles: 5.858*/
/* Name: Daphal Atul Sanjay
Enrollment No.: 23210270283
3. Write C++ program to find the area of various geometrical shapes by
Function overloading. (eg.Area of circle, circumference of circle etc…)*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int choice, length, breadth;
double radius, base, height;
cout << "Choose the shape:\n";
cout << "1. Circle\n";
cout << "2. Triangle\n";
cout << "3. Rectangle\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "Enter the radius of the circle: ";
cin >> radius;
cout << "Area of the circle: " << area(radius) << endl;
cout << "Circumference of the circle: " << circumference(radius) <<
endl;
break;
case 2:
cout << "Enter the base and height of the triangle: ";
cin >> base >> height;
cout << "Area of the triangle: " << area(base, height) << endl;
break;
case 3:
cout << "Enter the length and breadth of the rectangle: ";
cin >> length >> breadth;
cout << "Area of the rectangle: " << area(length, breadth) << endl;
break;
default:
cout << "Invalid choice\n";
}
return 0;
}
/*Output:
Choose the shape:
1. Circle
2. Triangle
3. Rectangle
Enter your choice: 1
Enter the radius of the circle: 3
Area of the circle: 28.2743
Circumference of the circle: 18.8496