Practical Program Exercise 1 Gross Salary for 11th Computer Science
setw ( )
- setw manipulator sets the width of the field assigned for the output.
- The field width determines the minimum number of characters to be written in output.
- In the below program, every output statement has two setw( ) manipulators; first setw (25) creates a filed with 25 spaces and second setw(10) creates another field with 10 spaces.
- When you represent a value to these fields
CS1 – GROSS SALARY
QUESTION:
Write a C++ program to input basic salary of an employee and calculate its Gross salary according to following:
Basic Salary <25000 : HRA = 20%, DA = 80%
Basic Salary >= 25000 : HRA = 25%, DA = 90%
Basic Salary >= 40000 : HRA = 30%, DA = 95%
AIM:
To write a C++ program to input basic salary of an employee and calculate its Gross salary.
CODING:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float basic, gross, da, hra;
cout<<“Enter the Basic Pay of an Employee:”;
cin>>basic;
if(basic<25000)
{
da=basic*80/100;
hra=basic*20/100;
}
else if(basic>=25000 && basic<40000)
{
da=basic*90/100;
hra=basic*25/100;
}
else if(basic>=40000)
{
da=basic*95/100;
hra=basic*30/100;
}
gross=basic+hra+da;
cout<<setw(25)<<“Basic Pay:”<<setw(10)<<basic<<endl;
cout<<setw(25)<<“Dearness Allowance:”<<setw(10)<<da<<endl;
cout<<setw(25)<<“House Rent Allowance:”<<setw(10)<<hra<<endl;
cout<<setw(25)<<“”<<setw(10)<<“———-“<<endl;
cout<<setw(25)<<“Gross Salary”<<setw(10)<<gross<<endl;
cout<<setw(25)<<“”<<setw(10)<<“———-“<<endl;
return 0;
}
OUTPUT:
Enter the Basic Pay of an Employee:25000
Basic Pay: 25000
Dearness Allowance: 22500
House Rent Allowance: 6250
———-
Gross Salary: 53750
———-
RESULT:
The Output was verified successfully