ASSIGNMENT2

1. write a program to display a given value,the value will be the parameter received by that display function.
write three overloaded functions so that it can recieve int,char and double type parameter.

#include<iostream>
using namespace std;
void display(int x)
{
    cout<<"the received no is integer:"<<endl;
    cout<<"and the no is:"<<x<<endl;
}

void display(char x)
{
    cout<<"the recieved no is character:"<<endl;
    cout<<"and the no is:"<<x<<endl;
}

void display(double x)
{
    cout<<"the recieved no is double:"<<endl;
    cout<<"and the no is:"<<x<<endl;
}

int main()
{
    display(5);
    display(5.5);
    display('c');
    return 0;
}

2.write a program to multiply two numbers.define two overlaoded functions to add the numbers
of integer type and double type.

#include<iostream>
using namespace std;
void multiply(int x,int y)
{
    cout<<"the multiplication of integer no is:"<<x*y<<endl;
}

void multiply(double x,double y)
{
    cout<<"the multiplication of double no is:"<<x*y<<endl;
}

int main()
{
   
    multiply(5,3);
    multiply(5.5,3.5);
    return 0;
}
3.Write a function add,which will add if its number and concenate if its character,and return the result to the caller function.
(use function overloading)

#include<iostream>
using namespace std;
void add(int x,int y)
{
    cout<<x+y<<endl;
}

void add(char x,char y)
{
    cout<<x<<y<<endl;
}

int main()
{
    add(5,3);
    add('u','k');
    return 0;
}

4.declare a class shape,which contains overloaded member function area() to calculate the area of square and rectangle.

#include<iostream>
using namespace std;

class shape
{
public:
    void area(int x)
    {
        cout<<"The area of square is:"<<x*x<<endl;
    }
   
    void area(int x,int y)
    {
        cout<<"The area of rectangle is:"<<x*y<<endl;
    }
};

int main()
{
    shape ob;
    ob.area(5);
    ob.area(6,7);
    return 0;
}

5.create a function simple interest for which the parameters are principal,time and rate of interest(given by user).use default
argument for principal.

#include<iostream>
using namespace std;

void simple_interest(int r,int t,int p=5000)
{
    cout<<"simple ineterest: "<<(p*r*t)/100<<endl;   
}

int main()
{
    cout<<"without passing the principal value"<<endl;
    simple_interest(8,4);
    cout<<"\nwith passing the principal value "<<endl;
    simple_interest(8,4,4000);
    return 0;
}

6.declare a class bank  which contains a function compound interest where formal parameters are principal,time and rate of interest
which will be passed by the user through a main function.declare the interest rate as constant argument.

#include<iostream>
#include<math.h>
using namespace std;
class bank
{
public:
    void compound_interest(double p,double t,const double r=8)
    {
        double a=p*pow((1+(r/100)),t);
        double ci=a-p;
        cout<< "compound interest: "<<ci<<endl;       
    }    
};

int main()
{
    bank ob;
    ob.compound_interest(5000,5,10);
    return 0;
}

7.create a class employee,which is having data members empno,empname,basicSalary,PF(10 % of the basic salary),TA(user defined)
,DA(2 % of basic salary),Hra(12 % of basic salary).Define one init member method to initialise all the data members.and another member
method to calculate the total  salary of an employee.then a display member method to display the complete information of an
employee

#include<iostream>
#include<stdio.h>
using namespace std;
class employee
{
    int empno;
    char empname[20];
    double salary;
    double pf;
    double ta;
    double da;
    double hra;
    double tsal;
public:
    void init();
    void disp();
   
};

void employee::init()
{
    cout<<"enter the empno :";
    cin>>empno;
    cout<<"enter the employee name:";
    fflush(stdin);
    gets(empname);
    cout<<"enter the salary:";
    cin>>salary;
    pf=(salary*10)/100;
    da=(salary*2)/100;
    hra=(salary*12)/100;
    ta=(salary*4)/100;
    tsal=salary+pf+da+hra+ta;
}

void employee::disp()
{
    cout<<"\nemployee name:"<<empname<<endl;
    cout<<"employee no:"<<empno<<endl;
    cout<<"salary:"<<salary<<endl;
    cout<<"total salary:"<<tsal<<endl;
    cout<<"annual salary:"<<tsal*12<<endl;
}

int main()
{
    employee ob;
    ob.init();
    ob.disp();
    return 0;
}


8.In the above question add a member tax and a method calculate_tax which will calculate the taxable amount for an employee on
his/her total annual income as per the following tax slab:

a. 0         -2,00,000            nil

b.2,00,001        -5,00,000            10%

c.5,00,001        -10,00,000            20%

d.10,00,001    -and above        30%


#include<iostream>
#include<stdio.h>
using namespace std;
class employee
{
    int empno;
    char empname[20];
    double salary;
    double pf;
    double ta;
    double da;
    double hra;
    double tsal;
    int tax;
public:
    void init();
    void disp();
    void calc_tax();
   
};
void employee::calc_tax()
{
    double p=tsal*12;
    if(p>0 && p<=200000)
        tax=0;
    else if(p>200000 && p<500000)
        tax=(p*10)/100;
    else if(p>500000 && p<1000000)
        tax=(p*20)/100;
    else
        tax=(p*30)/100;
}

void employee::init()
{
    cout<<"enter the empno :";
    cin>>empno;
    cout<<"enter the employee name:";
    fflush(stdin);
    gets(empname);
    cout<<"enter the salary:";
    cin>>salary;
    pf=(salary*10)/100;
    da=(salary*2)/100;
    hra=(salary*12)/100;
    ta=(salary*4)/100;
    tsal=salary+pf+da+hra+ta;
}

void employee::disp()
{
    cout<<"employee name:"<<empname<<endl;
    cout<<"employee no:"<<empno<<endl;
    cout<<"salary:"<<salary<<endl;
    cout<<"total salary:"<<tsal<<endl;
    cout<<"annual income:"<<tsal*12<<endl;
    cout<<"tax:"<<tax<<endl;
    cout<<"\n"<<endl;
}

int main()
{
    employee ob[5];

    for(int i=0;i<5;i++)
    {
        ob[i].init();
        ob[i].calc_tax();
    }
    for(int i=0;i<5;i++)
        ob[i].disp();
    return 0;
}

9.Write a program for doing addition and multiplication operation.Use function overloading to perform the operation for different numbers
 of arguments.

#include<iostream>
using namespace std;
void add(int x,int y)
{
    cout<<x+y<<endl;
}

void add(int x,int y,int z)
{
    cout<<x+y+z<<endl;
}

void multiplication(int x,int y)
{
    cout<<x*y<<endl;
}

void multiplication(int x,int y,int z)
{
    cout<<x*y*z<<endl;
}

int main()
{
    add(5,3);
    multiplication(5,3);
    add(5,8,9);
    multiplication(5,8,9);
    return 0;
}

Total Pageviews