This is an assignment that I am working on. I am having trouble getting my program to open the file that I specified. I would also like feedback and suggestions on things that I should maybe change a little. Only in my first year of computer science.
I think the problem is here. The file that is supposed to be opened is "employees.txt".
void payroll::read_employee_data(string file_name)
{
ifstream inFile;
inFile.open(file_name);
if (!inFile)
{
cout << "Unable to read the file\n";
exit(1);
}
inFile >> total_employees; // the first number is total number of employees;
inFile >> check_number;
names = new string[total_employees];
hourly_wages = new float[total_employees];
employee_ids = new int[total_employees];
hours_worked = new int[total_employees];
for (int i = 0 ; i < total_employees ; i++)
{
inFile >> names[i] >> employee_ids[i] >> hourly_wages[i] >> hours_worked[i];
}
inFile.close();
}
I feel like I am on the right track with the store_employee_data function. If there is anything wrong please let me know
void payroll::store_employee_data()
{
ofstream outFile;
outFile.open(payroll_file);
outFile << total_employees << '\n';
outFile << check_number << '\n';
for (int i = 0 ; i < total_employees ; i++)
{
outFile << names[i] << endl <<
employee_ids[i] << endl <<
hourly_wages[i] << endl <<
hours_worked[i] << endl;
}
outFile.close();
}
I also need help with the print function. Am I going in the right direction with this?
void payroll::print_employee_info(int employee_id)
{
cout << "Please enter the employee ID: ";
cin >> employee_id;
for (int i = 0; i < total_employees; i++) {
cout << "Printing information for employee " << employee_id << endl;
cout << "Employee Name: " << names[i] << endl;
cout << "Hourly Wages: " << hourly_wages[i] << endl;
cout << "Hours Worked: " << hours_worked[i] << endl;
}
}
Aucun commentaire:
Enregistrer un commentaire