C++ My code that need to be modified to the bottom: #include #include #include u
ID: 3914256 • Letter: C
Question
C++
My code that need to be modified to the bottom:
#include #include #include using namespace std; class department { private: int DepartmentID; string DepartmentName, DepartmentHeadName; public: void createDepartment(int id) { //Mutator to enter department details DepartmentID = id; fflush(stdin);//Flushes input buffer cout<<"Department Name: "; getline(cin, DepartmentName); cout<<"Head of Department: "; getline(cin, DepartmentHeadName); } int getDepartmentID() { //Accessor to return department ID return DepartmentID; } string getDepartmentName() { //Accessor to return department name return DepartmentName; } }; class employee { private: int EmployeeID, EmployeeAge, EmployeeDepartmentID; string EmployeeName; float EmployeeSalary; public: int getEmployeeID() { //Accessor to return employee ID return EmployeeID; } int getEmployeeDepartmentID() { //Accessor to return employee ID return EmployeeDepartmentID; } float getEmployeeSalary() { //Accessor to return salary cout<<" empslr"; return EmployeeSalary; } void createEmployee(int id) { //Mutator to enter employee details EmployeeID = id; fflush(stdin);//Flushes input buffer cout<<"Employee name: "; getline(cin, EmployeeName); cout<<"Salary: $"; cin>>EmployeeSalary; cout<<"Age: "; cin>>EmployeeAge; } void setEmployeeDepartmentID(int id) { //Mutator to set department id of the employee after validation EmployeeDepartmentID = id; } }; void writeData(department d[], employee e[], int i, int j) { ofstream od("department.dat", ios::binary); ofstream oe("employee.dat", ios::binary); for(int k = i; k <= i; k++) { od.write((char *)&d[k],sizeof(d[k])); } for(int k = j; k <= j; k++) { oe.write((char *)&d[k],sizeof(d[k])); } od.close(); oe.close(); } void inputData(department d[], employee e[], int &i, int &j) { ifstream id("department.dat", ios::binary); ifstream ie("employee.dat", ios::binary); if(id == NULL || ie == NULL) { cout<<"Unable to open file"; return; } int k = 0; while(id.read((char *)&d[k],sizeof(d[k]))) //Department data being read { cout<<" DptID: "<>option; switch(option) { case 1: if(!(i >= 2)) { cout<<"Please enter Department details"; cout<<" Department ID: "; cin>>temp; for(int k = 0; k <= i; k++) { //Checking if department id already exists or not if(temp == d[k].getDepartmentID()) { cout<<"Value must be unique"; flag = 0;//Denotes department id already exists break; } } if(flag) //Department ID is found to be unique d[++i].createDepartment(temp); flag = 1; } else cout<<"The array is full, you can not add any more Departments"; break; case 2: if(!(j >= 4)) { cout<<"Please enter Employee details"; cout<<" Employee ID: "; cin>>temp; for(int k = 0; k <= j; k++) { //Checking if employee id already exists or not if(temp == e[k].getEmployeeID()) { cout<<"Value must be unique"; flag = 0;//Denotes employee id already exists break; } } if(flag) { //Employee ID is found to be unique flag = 0; e[j].createEmployee(temp); cout<<"Enter Department ID: "; cin>>temp; for(int k = 0; k <= i; k++) { //Checking if department id exists or not if(temp == d[k].getDepartmentID()) { flag = 1;//Denotes department id exists break; } } if(flag) //Department ID exists e[++j].setEmployeeDepartmentID(temp); else //Department ID not found cout<<"Department ID not found!"; } flag = 1; } else cout<<"The array is full, you can not add any more Employees"; break; case 3: if(i >= 0 && j >= 0) writeData(d,e,i,j); else //One of the array is empty cout<<"Error!"; break; case 4: inputData(d,e,i,j);break; case 5: displayData(d,e,i,j);break; case 6: exit(0);break; default: cout<<"Please Enter valid choice(1-6): "; } } }
Modify your Midterm Exam Project to: 1.. Store the data in Binary file and access it in Random Access mode. 2.Replace Class with Structure for Employee and Department. 3. Inside each structure, replace all string variables with array of characters. 4. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. Youc an allow the user to edit Employee name, age etc and assign him/her to different department. Similarly department name and department head can be changed. However, do not allow the uesr to Employee ID in Employee file and Department ID in department file. 5. Please note that the data will no longer be stored in the array as it was in the midterm. Instead, it should be written to the file as soon as you collect the data from the user. If you are editing a record, read it from the file,collect new data from the user, store the record back to the file in the same place it was found inside the file. That means, the menu will not have options to save data to file or read data from file. Also, this should provide the ability for user to create unlimited number of employees and departments unlike in Midterm where you allowed only limited number of departments and employees.
How the out put has to be:
Explanation / Answer
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct department {
private:
int DepartmentID;
char* DepartmentName, DepartmentHeadName;
public:
void createDepartment(int id) { //Mutator to enter department details DepartmentID = id;
fflush(stdin);
//Flushes input buffer
cout<<"Department Name: ";
//getline(cin, DepartmentName);
cin >> DepartmentName;
cout << "Head of Department: ";
//getline(cin, DepartmentHeadName);
cin >> DepartmentHeadName;
}
int getDepartmentID() { //Accessor to return department ID
return DepartmentID;
}
char* getDepartmentName() { //Accessor to return department name
return DepartmentName;
}
};
struct employee {
private:
int EmployeeID, EmployeeAge, EmployeeDepartmentID;
char* EmployeeName;
float EmployeeSalary;
public:
int getEmployeeID() { //Accessor to return employee ID
return EmployeeID;
}
int getEmployeeDepartmentID() { //Accessor to return employee ID
return EmployeeDepartmentID;
}
float getEmployeeSalary() { //Accessor to return salary
cout<<" empslr";
return EmployeeSalary;
}
void createEmployee(int id) { //Mutator to enter employee details
EmployeeID = id;
fflush(stdin);
//Flushes input buffer
cout<<"Employee name: ";
//getline(cin, EmployeeName);
cin >> EmployeeName;
cout << "Salary: $";
cin >> EmployeeSalary;
cout << "Age: ";
cin >> EmployeeAge;
}
void setEmployeeDepartmentID(int id) { //Mutator to set department id of the employee after validation
EmployeeDepartmentID = id;
}
};
void writeData(department d[], employee e[], int i, int j) {
ofstream od("department.dat", ios::binary);
ofstream oe("employee.dat", ios::binary);
for (int k = i;k <= i;k++) {
od.write((char *)&d[k], sizeof(d[k]));
}
for (int k = j;k <= j;k++) {
oe.write((char *)&d[k], sizeof(d[k]));
}
od.close();
oe.close();
}
void inputData(department d[], employee e[], int &i, int &j) {
ifstream id("department.dat", ios::binary);
ifstream ie("employee.dat", ios::binary);
if (!id.is_open() || !ie.is_open()) {
cout << "Unable to open file";
return;
}
int k = 0;
while (id.read((char *)&d[k], sizeof(d[k]))) //Department data being read
{
cout << " DptID: ";
int option,temp;
cin >> option;
int flag = 1;
switch (option) {
case 1:
if (!(i >= 2)) {
cout << "Please enter Department details";
cout << " Department ID: ";
cin >> temp;
for (int k = 0;k <= i;k++) { //Checking if department id already exists or not
if(temp == d[k].getDepartmentID()) {
cout<<"Value must be unique";
flag = 0;//Denotes department id already exists
break;
}
}
if (flag) //Department ID is found to be unique
d[++i].createDepartment(temp);
flag = 1;
}
else
cout << "The array is full, you can not add any more Departments";
break;
case 2:
if (!(j >= 4)) {
cout << "Please enter Employee details";
cout << " Employee ID: ";
cin >> temp;
for (int k = 0; k <= j;k++) { //Checking if employee id already exists or not
if(temp == e[k].getEmployeeID()) {
cout<<"Value must be unique";
flag = 0;//Denotes employee id already exists
break;
}
}
if (flag) { //Employee ID is found to be unique
flag = 0;
e[j].createEmployee(temp);
cout << "Enter Department ID: ";
cin >> temp;
for (int k = 0;k <= i;k++) { //Checking if department id exists or not
if(temp == d[k].getDepartmentID()) {
flag = 1;//Denotes department id exists
break;
}
}
if (flag) //Department ID exists
e[++j].setEmployeeDepartmentID(temp);
else //Department ID not found
cout<<"Department ID not found!";
}
flag = 1;
}
else
cout << "The array is full, you can not add any more Employees";
break;
case 3:
if (i >= 0 && j >= 0) writeData(d, e, i, j);
else //One of the array is empty
cout<<"Error!";
break;
case 4: inputData(d, e, i, j);
break;
case 5:
displayData(d, e, i, j);
break;
case 6:
exit(0);
break;
default:
cout << "Please Enter valid choice(1-6): ";
}
}
}
void editData(department d[], employee e[], int &i, int &j) {
}
void displayData(department d[], employee e[], int &i, int &j) {
}
i am in middle of this.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.