Write a program that keeps an employee database in a random-access file. Impleme
ID: 3530681 • Letter: W
Question
Write a program that keeps an employee database in a random-access file. Implement functions for adding and removing employees. You need not keep employees in sorted order. To remove an employee, just fill the entire record with spaces. When adding an employee, try to add it into one of those empty spots first before appending it to the end of the file.Explanation / Answer
#include "stdafx.h" #include #include #include #include #include "ccc_empl.h" using namespace std; const int NEWLINE_LENGTH = 2; const int RECORD_SIZE = 30 + 10 + NEWLINE_LENGTH; /** converts a string to a floating-point value @param s a string representing a floating-point value @return the equivalent floating-point value */ double string_to_double(string s) { istringstream instr(s); double x; instr >> x; return x; } /* reads an employee record from the input file @param e the employee @param in the file to read from */ Employee read_employee(istream& in) { string line; getline(in, line); string input_name = line.substr(0, 30); double input_salary = string_to_double(line.substr(30, 10)); Employee e(input_name, input_salary); return e; } /* gets input for an Employee object @param input_name the name of the employee @param input_salary the salary of the employee @param e the Employee object @return returns the Employee object */ Employee input_employee() { string input_name; cout input_salary; Employee e(input_name, input_salary); return e; } /** adds an employee record to a file @param e the employee record to write @param out the file to write to */ void add_employee(Employee e, ostream& out) { outRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.