Exp.
No:02 Employee Database Using Classes and Objects
AIM: Given that an employee class contains following members, data members, employee
number, employee name ,basic, DA, IT, net salary and print data members
PROCEDURE:
• Step 1 - Include the required header files (iostream.h, conio.h, and windows.h for colors).
• Step 2 - Create a class (employee) with the following members as public members.
emp_number, emp_name, emp_basic, emp_da, emp_it, and emp_net_sal as data members.
get_emp_details(), find_net_salary() and show_emp_details() as member functions.
• Step 3 - Implement all the member functions with their respective code (Here, we have
used scope resolution operator ::).
• Step 3 - Create a main() method.
• Step 4 - Create an object (emp) of the above class inside the main() method.
• Step 5 - Call the member functions get_emp_details() and show_emp_details().
• Step 6 - returnn 0 to exit form the program execution.
PROGRAM:
#include <windows.h>
#include <iostream>
using namespace std;
class employee
{
int emp_number;
char emp_name[20];
float emp_basic;
float emp_da;
float emp_it;
float emp_net_sal;
public:
void get_emp_details();
float find_net_salary(float basic, float da, float it);
void show_emp_details();
DEPARTMENT OF CSE OOPS USING C++
};
void employee :: get_emp_details()
{
cout<<"\nEnter employee number: ";
cin>>emp_number;
cout<<"\nEnter employee name: ";
cin>>emp_name;
cout<<"\nEnter employee basic: ";
cin>>emp_basic;
cout<<"\nEnter employee DA: ";
cin>>emp_da;
cout<<"\nEnter employee IT: ";
cin>>emp_it;
}
float employee :: find_net_salary(float basic, float da, float it)
{
return (basic+da)-it;
}
void employee :: show_emp_details()
{
cout<<"\n\n**** Details of Employee ****";
cout<<"\nEmployee Name : "<<emp_name;
cout<<"\nEmployee number : "<<emp_number;
cout<<"\nBasic salary : "<<emp_basic;
cout<<"\nEmployee DA : "<<emp_da;
cout<<"\nIncome Tax : "<<emp_it;
cout<<"\nNet Salary : "<<find_net_salary(emp_basic, emp_da, emp_it);
cout<<"\n-------------------------------\n\n";
}
int main()
{
employee emp;
emp.get_emp_details();
emp.show_emp_details();
return 0;
}
Exp.No:03 Function Overloading
Aim
To calculate the area of circle, rectangle and triangle using function
overloading.
Simple Program for Function Overloading Algorithm/Steps:
STEP 1: Start the program.
STEP 2: Declare the class name as fn with data members and member functions.
STEP 3: Read the choice from the user.
STEP 4: Choice=1 then go to the step 5.
STEP 5: The function area() to find area of circle with one integer argument.
STEP 6: Choice=2 then go to the step 7.
STEP 7: The function area() to find area of rectangle with two integer argument.
STEP 8: Choice=3 then go to the step 9.
STEP 9: The function area() to find area of triangle with three arguments, two as
Integer and one as float.
STEP 10: Choice=4 then stop the program.
Simple Program for Function Overloading
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define pi 3.14
classfn {
public:
void area(int); //circle
void area(int, int); //rectangle
void area(float, int, int); //triangle
};
voidfn::area(int a) {
cout<<"Area of Circle:"<< pi * a*a;
}
voidfn::area(int a, int b) {
cout<<"Area of rectangle:"<< a*b;
}
voidfn::area(float t, int a, int b) {
cout<<"Area of triangle:"<< t * a*b;
}
void main() {
intch;
int a, b, r;
clrscr();
fnobj;
cout<<"\n\t\tFunction Overloading";
cout<<"\n1.Area of Circle\n2.Area of Rectangle\n3.Area of Triangle\n4.Exit\
n:?;
cout<< ?Enter your Choice : ";
cin>>ch;
switch (ch) {
case1:
cout<<"Enter Radious of the Circle:";
cin>>r;
obj.area(r);
break;
case2:
cout<<"Enter Sides of the Rectangle:";
cin>> a>>b;
obj.area(a, b);
break;
case3:
cout<<"Enter Sides of the Triangle:";
cin>> a>>b;
obj.area(0.5, a, b);
break;
case4:
exit(0);
}
getch();
}