Заработная плата с векторным массивом для получения суммы валового вознаграждения работника - PullRequest
0 голосов
/ 11 октября 2019

Я хочу создать приложение, которое займет не менее 5 сотрудников, их имена, имена, заработную плату и часы. А затем я должен добавить ставку заработной платы и часы вместе, чтобы показать валовую заработную плату для каждого сотрудника в конце первоначальных запросов. Я застрял на том, как добавить его в вектор, пожалуйста, помогите!

** Вот задание, которое наш инструктор дал нам **

http://itweb.fvtc.edu/ag/?u=3&f=cpp-assignment4

I 'мы добавили вектор и добавили всю необходимую информацию для сотрудника

#include <iostream>
#include <conio.h>
#include <string>
#include <vector>

using namespace std;


struct Employee
{
    int id;
    string firstName;
    string lastName;
    float payRate;
    int hours;

};


int main()
{
    /*========= other way of adding employee information ==========*/

    /*const int NUM_EMPLOYEE = 5;
    Employee employee[NUM_EMPLOYEE];



    for (int i = 0; i < 5; i++)
    {
        cout << "ID of employee " << (i + 1) << ": ";
        cin >> employee[i].id;

        cout << "First Name of employee " << (i + 1) << ": ";
        cin >> employee[i].firstName;

        cout << "Last Name of employee " << (i + 1) << ": ";
        cin >> employee[i].lastName;

        cout << "Pay rate for employee " << (i + 1) << ": ";
        cin >> employee[i].payRate;

        cout << "Hours worked " << (i + 1) << ": ";
        cin >> employee[i].hours;
    }*/

    /*========= End of other way of adding employee information ==========*/

    vector<Employee> employees;

    char Another = 'y';

    while (Another == 'y' || Another == 'Y')
    {
        Employee e;
        cout << "Enter employee ID: \n";
        cin >> e.id;
        cout << "Enter employee first name: \n";
        cin >> e.firstName;
        cout << "Enter employee last name: \n";
        cin >> e.lastName;
        cout << "Enter employee pay rate: \n";
        cin >> e.payRate;
        cout << "Enter employee hours worked: \n";
        cin >> e.hours;
        employees.push_back(e);

        cout << "Another? (y/n): \n";
        cin >> Another;

    }

    float sum = 0;

    vector<Employee>::iterator it = employees.begin();

    for (; it != employees.end(); it++)
    {
        cout << "ID of employee:  \n" << it->id << ": \n" 
            << "Employees name: \n" << it->firstName << " " << it->lastName << ": \n" 
            << "Employee pay rate: \n" << it->payRate << ": \n" 
            << "Employee hours worked: \n" << it->hours << "\n";
    }

    float avg = sum / employees.size();

    Employee e;

    /*cout << " ID of employees: \n" << e.id;
    cout << " Name of employees: \n" << e.firstName << " " << 
 e.lastName;*/
    cout << "Gross pay of employees: \n" << avg;







    _getch();
    return 0;

}

Показать идентификатор, имена и валовую оплату всех сотрудников пользователю

1 Ответ

0 голосов
/ 12 октября 2019
    vector<Employee> employees;

    char Another = 'y';

    while (Another == 'y' || Another == 'Y')
    {
        Employee e;
        cout << "Enter employee ID: \n";
        cin >> e.id;
        cout << "Enter employee first name: \n";
        cin >> e.firstName;
        cout << "Enter employee last name: \n";
        cin >> e.lastName;
        cout << "Enter employee pay rate: \n";
        cin >> e.payRate;
        cout << "Enter employee hours worked: \n";
        cin >> e.hours;
        employees.push_back(e);

        cout << "Another? (y/n): \n";
        cin >> Another;

    }

    float sum = 0;

    vector<Employee>::iterator it = employees.begin();

    cout << "ID" << "\t" << "First Name" << "\t" << "Last Name" << "\t" << "Pay rate" << "\t" << "Hours" << "\t" << "Gross Pay" << "\n" ;

    for (; it != employees.end(); it++)
    {
        float grossPay = it->payRate * it->hours;
        cout << it->id << "\t" << it->firstName << "\t\t" << it->lastName << "\t\t" << it->payRate << "\t\t" 
            << it->hours << "$" << "\t" << grossPay << "\n";
        sum += grossPay;
    }

    cout << "The gross pay for all employee is: " << "$" << sum;


    _getch();
    return 0;

}

//This is what i got so far. But if I want to make the application ask the user to input how many employee they want to enter into the database how do i do that? would it be like this?


int EMPLOYEE_NUM[][]    // ??

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...