Question: I need to find out why I keep getting this error in the Ubuntu terminal whenever I compile the program and I need the program

I need to find out why I keep getting this error in the Ubuntu terminal whenever I compile the program and I need the program fixed. The error reads like this:

terminate called after throwing an instance of 'std::out_of_range'

what (): vector :: _M_range_check: __n (which is 0) >= this->size() (which is )

Aborted (core dumped)

This is what I have so far.

#include

#include

#include

#include

using namespace std;

//void separateAndSave(vector &employeeN, vector

//string companyName;

//fstream file;

//string name;

//int id;

//string company;

//float total;

//}

void readData(vector &employees){

float tmp = employees().totalPay();

int counter = 0;

ifstream input_file;

input_file.open("input.txt");

if (input_file) {

string line;

while (tmp < employees[counter].totalPay()){

tmp = employees[counter].totalPay();

line = employees[counter].totalPay();

cout << line << ' ';

}

input_file.close();

}

}

void getCompanies(vector &employees, vector &companyNames){

for (unsigned int i = 0; i < employees.size(); i++)

{ cout << employees[i].getCompanyName() << ' ' ; }

}

void printHighestPaid(vector &employees){

int highest = 0;

int index = 0;

for (unsigned int i = 0; i < employees.size(); i++) {

if (highest < employees.at(i).totalPay()){

highest = employees.at(i).totalPay();

index = i;

}

}

cout << "Highest Paid: " << employees.at(index).fullName() << endl;

cout << " Employee ID: " << employees.at(index).getEmployeeId() << endl;

cout << " Employer " << employees.at(index).getCompanyName() << endl;

cout << " Total Pay: " << highest << endl;

}

//loop to push company name.... etc..

int main(){

//string fName;

//string lName;

//string fullname;

//string employee;

//string companyName;

//int worker = 6;

//float pay;

//Person employees;

vector employees;

vector companyNames;

// employees.push_back();

readData(employees);

getCompanies(employees, companyNames);

printHighestPaid(employees);

}

I also need help implementing a function called separateAndSave that does the following to a text file called "input.txt"

It also needs to have a function called separateAndSave must write the payroll information to multiple text files - one for each company. Each file should be named after the company (e.g. Boeing.txt) and contain only the employees from that company. Within the file, the data should be formatted by selecting reasonable column widths for output. The float output should be truncated to 2 decimal places. The column widths do not have to match exactly. Simply pick a reasonable number of characters for each (20-30 for names, etc). The output should also have the total pay for each company. NOTE: both vectors need to be passed to this function by reference.

Thanks in advance.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!