Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

3. Comment on how diversity and equality should be managed.

Answered: 1 week ago

Question

describe the legislation that addresses workplace equality

Answered: 1 week ago