You are on page 1of 8

WEEK -5

>>write a c++ program to find area of a rectangle using function overloading

>>write a c++ program to calculate net income of the employee given ba,hra,it,basic using function
overloading.

>>calculate the simple interest using function overloading,given principle,rate of interest and time.

>>perform the above three using constructor overloading.

//1.

#include<iostream>

using namespace std;

void area_of_rectangle(int l,int b){

cout<<"Area of rectangle is:"<<l*b<<endl;

void area_of_rectangle(double l,double b)

cout<<"Area of rectangle is:"<<l*b<<endl;

int main(){

area_of_rectangle(2,3);

area_of_rectangle(2.5,4.5);

return 0;

#2.

#include<iostream>

using namespace std;

class Employee{
private:

float basic,da,hra,it,n;

public:

Employee(){

cout<<"\n"<<"Enter basic salary:";

cin>>basic;

Employee(float b){

basic=b;

void display(){

da=basic*20/100;

hra=basic*5/100;

it=basic*2/100;

n=basic+da+hra-it;

cout<<"\n"<<"Net salary:"<<n;

};

int main(){

Employee obj;

obj.display();

Employee o(10000);
o.display();

#Output:

#3.

#include<iostream>

using namespace std;

class Employee{

private:

float basic,da,hra,it,n;

public:

void Salary(){

cout<<"\n"<<"Enter basic salary:";

cin>>basic;

}
void Salary(float b){

basic=b;

void display(){

da=basic*20/100;

hra=basic*5/100;

it=basic*2/100;

n=basic+da+hra-it;

cout<<"\n"<<"Net salary:"<<n;

};

int main(){

Employee obj;

obj.Salary();

obj.display();

Employee o;

o.Salary(10000);

o.display();

#output:
#4.

#include<iostream>

using namespace std;

class Interest{

private:

float si,p,t,r;

public:

Interest(){

cout<<endl<<"Enter principle amount:";

cin>>p;

cout<<endl<<"Enter the time period in months:";

cin>>t;

cout<<endl<<"Enter the rate of interest:";

cin>>r;
cout<<endl<<"Simple Interest is:"<<(p*t*r)/100;

Interest(float pr,float time,float rate ){

p=pr;

t=time;

r=rate;

cout<<endl<<"Simple Interest is:"<<(p*t*r)/100;

};

int main(){

Interest obj1;

Interest obj2(10000,5,2);

#output
#6.

#include<iostream>

using namespace std;

class Interest{

private:

float si,p,t,r;

public:

SimpleInterest(){

cout<<endl<<"Enter principle amount:";

cin>>p;

cout<<endl<<"Enter the time period in months:";

cin>>t;

cout<<endl<<"Enter the rate of interest:";

cin>>r;

cout<<endl<<"Simple Interest is:"<<(p*t*r)/100;

SimpleInterest(float pr,float time,float rate ){

p=pr;

t=time;

r=rate;

cout<<endl<<"Simple Interest is:"<<(p*t*r)/100;

};

int main(){
Interest obj1;

obj1.SimpleInterest();

Interest obj2;

obj2.SimpleInterest(10000,5,2);

return 0;

#output:

ssss

You might also like