0% found this document useful (0 votes)
23 views4 pages

18

Uploaded by

atul10179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

18

Uploaded by

atul10179
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

/* Name: Daphal Atul Sanjay

Enrollment No.: 23210270283


Practical Related Questions:
1. Write a C++ Program to interchange the values of two int , float and
char using function overloading.*/

#include <iostream>
using namespace std;

void interchange(int x, int y)


{
int temp = x;
x = y;
y = temp;
}

void interchange(float x, float y)


{
float temp = x;
x = y;
y = temp;
}

void interchange(char x, char y)


{
char temp = x;
x = y;
y = temp;
}

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 sum(int a, int b)


{
return a + b;
}

double sum(double a, double b)


{
return a + b;
}

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;

double area(double radius)


{
return M_PI* radius * radius;
}

double circumference(double radius)


{
return 2* M_PI* radius;
}

double area(double base, double height)


{
return 0.5* base * height;
}

double area(int length, int breadth)


{
return length* breadth;
}

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

Enter your choice: 2


Enter the base and height of the triangle: 2
3
Area of the triangle: 3

Enter your choice: 3


Enter the length and breadth of the rectangle: 2
3
Area of the rectangle: 6*/

You might also like