Question #269421

Create a structure called employee that contains two members: an employee number (type int) and

the employee’s salary (in dollars; type float). Ask the user to fill in this data for three employees,

store it in three variables of type struct employee, and then display the information for each

employee.


Expert's answer

#include <iostream>
#include <iomanip>
using namespace std;

struct employee {
    int id;
    float salary;
};

void ReadEmployee(employee& e) {
    cout << "Enter ID: ";
    cin >> e.id;
    cout << "Enter salary: ";
    cin >> e.salary;
}

void PrintEmployee(const employee& e) {
    cout << "ID: " << e.id << ";  ";
    cout <<"Salary: " << fixed << setprecision(2) 
         << "$" << e.salary << endl;
}

int main()
{
    employee emp1, emp2, emp3;

    cout << "Enter data for the first employee:" << endl;
    ReadEmployee(emp1);
    cout << "Enter data for the second employee:" << endl;
    ReadEmployee(emp2);
    cout << "Enter data for the third employee:" << endl;
    ReadEmployee(emp3);

    cout << endl << "The data you have entered" << endl;
    cout << "The first employee  ";
    PrintEmployee(emp1);
    cout << "The second employee ";
    PrintEmployee(emp2);
    cout << "The third employee  ";
    PrintEmployee(emp3);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS