#include <iostream> using namespace std; int main (){ float pay[10]; int id[10];
ID: 3928122 • Letter: #
Question
#include <iostream>
using namespace std;
int main (){
float pay[10];
int id[10];
int i;
float hours, wage;
for (i=0; i<10; i++){
cout << "Please enter the employee ID: ";
cin >> id[i];
cout << "Please enter the employee's hourly wage: ";
cin >> wage;
cout << "Please enter the hours worked: ";
cin >> hours;
pay[i]=wage*hours;
}
for (i=0; i<10; i++) {
cout << "The wage is " << pay[i] << endl;
}
return 0;}
Modify the program to print out all the data (ID, hours, wage and salary) for 10 employees. Put this data in columns using formatting so everything is neat and easy to read.
Explanation / Answer
Dear Student in this question you have to use a library function called "iomanip" that is input output manipulation in which setw() function is defind setw() is used to set the the number of charater to be used as field width for the next insertion operation.
Following is the complete program.
#include <iostream>
#include <iomanip>
using namespace std;
using std::cout;
using std::setw;
int main ()
{
float pay[10];
int id[10];
int i;
float hours, wage;
for (i=0; i<10; i++)
{
cout << "Please enter the employee ID: ";
cin >> id[i];
cout << "Please enter the employee's hourly wage: ";
cin >> wage;
cout << "Please enter the hours worked: ";
cin >> hours;
pay[i]=wage*hours;
}
cout << setw(10) << left << "id" << setw(10) << left << "wage" << setw(20) << left << "hours" << setw(20) << left << "pay" << endl;
for (i=0; i<10; i++)
{
cout << setw(10) << left << id[i] << setw(10) << left << wage << setw(20) << left << hours << setw(20) << left << pay[i] << endl;
}
return 0;
}
The input which i have given is following-
Please enter the employee ID: 10
Please enter the employee's hourly wage: 50
Please enter the hours worked: 8
Please enter the employee ID: 11
Please enter the employee's hourly wage: 60
Please enter the hours worked: 8
Please enter the employee ID: 13
Please enter the employee's hourly wage: 70
Please enter the hours worked: 8
Please enter the employee ID: 14
Please enter the employee's hourly wage: 80
Please enter the hours worked: 8
Please enter the employee ID: 15
Please enter the employee's hourly wage: 90
Please enter the hours worked: 8
Please enter the employee ID: 16
Please enter the employee's hourly wage: 100
Please enter the hours worked: 8
Please enter the employee ID: 16
Please enter the employee's hourly wage: 110
Please enter the hours worked: 8
Please enter the employee ID: 17
Please enter the employee's hourly wage: 120
Please enter the hours worked: 8
Please enter the employee ID: 18
Please enter the employee's hourly wage: 150
Please enter the hours worked: 8
Please enter the employee ID: 19
Please enter the employee's hourly wage: 150
Please enter the hours worked: 8
The output which you will get is as below-
id wage hours pay
10 150 8 400
11 150 8 480
13 150 8 560
14 150 8 640
15 150 8 720
16 150 8 800
16 150 8 880
17 150 8 960
18 150 8 1200
19 150 8 1200
###Dear student if you are satisfied with the answer please do comment and provide your valuable feedback.###
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.