EXERCISE - 4

A) Write a program illustrate function overloading.
B) Write a program illustrate the use of default arguments for simple interest function.

A) AIM: Write a program illustrate function overloading.
SOURCE CODE:
#include <iostream>
using namespace std;
void display(int);
void display(float);
void display(int, float);
int main()
{
    int a = 5;
    float b = 5.5;
    display(a);
    display(b);
    display(a, b);
    return 0;
}
void display(int var)
{
    cout<< "Integer number: " <<var<<endl;
}
void display(float var)
{
    cout<< "Float number: " <<var<<endl;
}
void display(int var1, float var2)
{
    cout<< "Integer number: " << var1;
    cout<< " and float number:" << var2;
}
OUTPUT:
Integer number: 5
Float number: 5.5
Integer number: 5 and float number:5.5
B) AIM: Write a program illustrate the use of default arguments for simple interest function.
SOURCE CODE:
#include<iostream>
using namespace std;
float interest(float p, int n, float r=0.2);
int main()
{
    float amount, principal;
    int time;
    cout<<"Enter principal amount:";
    cin>>principal;
    cout<<"\nEnter time: ";
    cin>>time;
    amount=interest(principal, time);
    cout<<"\nThe amount is:"<<amount;
}
float interest(float p, int n,float r)
{
    return (p*r*n);
}
OUTPUT:
Enter principal amount:30000
Enter time: 3
The amount is:18000