0% found this document useful (0 votes)
46 views

C++ Basic Practicals

The document describes an employee data program that stores information like HRA, DA, income, provident fund, gross pay, net pay, and designation for multiple employees. It takes input from the user, calculates values using functions, and displays the data in a table. The program uses structures to store employee information and defines functions for input, calculation, and display. It takes the number of employees as input and loops through to get name, designation, and basic pay and calculate other values like DA, HRA, tax, provident fund, gross pay, and net pay.

Uploaded by

Zohaib Hamdule
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

C++ Basic Practicals

The document describes an employee data program that stores information like HRA, DA, income, provident fund, gross pay, net pay, and designation for multiple employees. It takes input from the user, calculates values using functions, and displays the data in a table. The program uses structures to store employee information and defines functions for input, calculation, and display. It takes the number of employees as input and loops through to get name, designation, and basic pay and calculate other values like DA, HRA, tax, provident fund, gross pay, and net pay.

Uploaded by

Zohaib Hamdule
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Employee Data

A program to store information of employees (HRA, DA, INCOME, PROVIDENT FUND, GROSS PAY, NET PAY and
DESIGNATION) and input, caluculate and display information of all employees in a tabular for using user defined
function.

Documentation
 ‘#’ Header files
1) <iostream.h>
cin – To input the values
cout – To output the values
2) <conio.h>
getch() – To accept a character
3) <iomanip.h>
setw() – To set reserve a certain width for the output.

 Variables
int n – stores the number of employees.
emp[] – variable of user defined data type employee. Stores the information of n number of
employee.

 Structure
employe : Stores all information about an employe. Has the following elements:-
int bp – Array of Basic Pay of all Employees
int da – Array of Dearness Allowance of all Employees
int hra – Array of House Rent Allowance of all Employees
int pf – Array of Provident Fund of all Employees
int tax – Array of Income Tax of all Employees
int gp – Array of Gross Pay of all Employees
int np – Array of Net Pay of all Employees
char name – stores the names of all employees (2D array)
char desig – stores the designation of all employee (2D array)

 Functions
input();
Gets input for names, designation and basicpay of n numer of employees, and stores them in the
arrays listed in the arguments.

calc();
Calculates Dearness Allowance, House Rent Allowance, Income Tax, Provident Fund, Grosspay,
Netpay for n number of employees by taking basic pay from the global variable of user defined data
type emp, and stores them in the elements of respective employe.

Practical 24 Page 51
Source code
/*A program to store information of employees (HRA, DA, INCOME, PROVIDENT FUND
GROSS PAY, NET PAY and DESIGNATION) and input, caluculate and display
information of all employees in a tabular for using user defined function.
*/

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdio.h>

struct employee
{
char name[25];
char desig[20];
float bp, np, gp, hra, da,pf, tax;

} emp[100];

int n;

void input()
{for(int i=0; i<n; i++)
{
cout<<"Enter the name, designation and basic pay of employee #"<<(i+1)<<endl;
gets(emp[i].name);
gets(emp[i].desig);
cin>>emp[i].bp;
clrscr();
}
}

void calc()
{for (int i =0; i<n; i++)
{
//DA
if(emp[i].bp<=3500) emp[i].da = 0.75*emp[i].bp;
else if((emp[i].bp >3500)&&(emp[i].bp <=6000)) emp[i].da = 0.6*emp[i].bp;
else emp[i].da = 0.25*emp[i].bp;

//HRA
if(emp[i].bp<=2500) emp[i].hra = 300;
else if((emp[i].bp >2500)&&(emp[i].bp <=5000)) emp[i].hra = 500;
else emp[i].hra = 750;

//GP
emp[i].gp = emp[i].bp + emp[i].da + emp[i].hra;

//PF & TAX


emp[i].pf = 0.1*emp[i].bp;
emp[i].tax = 0.15*emp[i].bp;

Practical 1 Page 52
//NP
emp[i].np = emp[i].gp - (emp[i].tax + emp[i].pf);
}
}

void display()
{
cout<<"EMPLOYEE DATA :-\n\n";

cout<<setw(25)<<"NAME"
<<setw(20)<<"DESIGNATION"
<<setw(15)<<"DAILY ALLWNCE"
<<setw(12)<<"HR ALLWNCE"
<<setw(11)<<"GROSS PAY"
<<setw(15)<<"PRVIDENT FUND"
<<setw(11)<<"TAX"
<<setw(11)<<"NET PAY"
<<endl;

for(int i=0;i<n;i++)
{cout<<setw(25)<<emp[i].name
<<setw(20)<<emp[i].desig
<<setw(15)<<emp[i].da
<<setw(12)<<emp[i].hra
<<setw(11)<<emp[i].gp
<<setw(15)<<emp[i].pf
<<setw(11)<<emp[i].tax
<<setw(11)<<emp[i].np
<<endl;
}
}

void main()
{
cout<<"Enter the number of employees\n";
cin>>n;
clrscr();

input();
calc();
display();
getch();
}

Practical 24 Page 53
Output

Practical 24 Page 54
Practical 24 Page 55

You might also like