>> basic; cout << "\n Enter D.A : "; cin >> da; cout << "\n Enter H.R.A: "; cin >> hra; gross = basic+da+hra; // sum of basic, da and hra gpf = (basic+da) * . ; // % 0f basic and da tax = gross * . ; // % of gross pay np = gross - (gpf+tax); //netpay = earnings - deductions cout << setw( ) << "Basic Pay : " << setw( )<< basic<< endl; cout << setw( ) << "Dearness Allowance : "<< setw( )<<da<< endl; cout<<setw( )<<"House Rent Allowance : "<<setw( )<< hra<<endl; cout << setw( ) << "Gross Pay : " << setw( ) << gross << endl; cout << setw( ) << "G.P.F : " << setw( ) << gpf << endl; cout << setw( ) << "Income Tax : " << setw( )<< tax << endl; cout << setw( ) << "Net Pay : " << setw( ) << np << endl; Illustration . : Program to Calculate Net Salary The output will be, Enter Basic Pay: 12000 Enter D.A : Enter H.R.A : Basic Pay : 12000 Dearness Allowance : House Rent Allowance : Gross Pay : 14700 G.P.F : Income Tax : Net Pay : 11905 (HOT: Try to make multiple output statements as a single cout statement) In the above program, every output statement has two setw( ) manipulators; first setw ( ) creates a filed with spaces and second setw( ) creates another field with spaces.
When you Chapter Page - - represent a value to these fields, it will show the value within the field from right to left. Field with space width New line modifier Data to accommodate in Field Data to accommodate in Field Field with space width cout<<setw( )<<"Basic Pay:"<<setw( )<<basic<<endl; In field1 and field , the string “Basic Pay: ” and the value of basic pay are shown as given in Figure . below. -------------------------------- Basic pay: Field with space width Field with space width ---------------12000 Figure .
setw( ) function setprecision ( ) This is used to display numbers with fractions in