Create a class with the following: private attributes *Structure to represent an
ID: 3627218 • Letter: C
Question
Create a class with the following:private attributes
*Structure to represent an Employee with first name, last name, and hourly wage.
*An array of these structures (max of 50)
*A filename for reading/writing the employees from/to the file
*A file handle for writing to the file.
*A file handle for reading from the file.
private member functions (place the actual code for these in the .cpp file,
not the .h file)
*Save the employees to the file
*Load the employees from the file
*Select employee from a list
public member functions
*default constructor that initializes the filename attribute, any counters and
calls the member function to load the employees from file.
*deconstructor that cleans up any dynamic memory allocated (if used) and calls
the member function to save the employees to the file
*member function to add an employee to the array
*member function to remove an employee from the array (must call select member
function to choose the employee to remove)
*member function to display all the employees
*member function to display the selected employee(must call select member
function to choose the employee to remove)
Main program:
This program will control acces to the employee class. You will need to define
an instanciation of the class to perform the tasks in the menu below:
************************************
* Employee Program *
************************************
1. Display all Employees
2. Display a Single Employees
3. Add an Employee
4. Delete an Employee
5. Exit
***********************************
Required turn in products (replace class with the name of the class created):
UML documentation for the class
class.h
class.cpp
project.cpp
Explanation / Answer
Class Employee
{
Char *firstname;
Chrar*lastname;
int hwages;
public:
Employee(); //Default constructor
DisplayEmployee();
DisplaySingle();
AddEmployee();
DeleteEmployee();
}
Employee::DisplaySingle(char name )
{
ifstream fin("Employee.txt");
while(!fin.eof())
{
fin>>firstname;
if(strcmp(firstname,name)
cout<<firstname<<lastname<<hwages;
}
fin.close();
}
Employee::AddEmployee()
{
ifstream fin("Employee.txt",ios::app)
cout<<"Enter first name"
cin>>fname;
fin>>fname;
cout<<"Enter lastname";
cin>>lname
fin>>lname;
cout<<"Enter wages";
cin>>hwages;
fin>>hwages
fin.close();
}
Employee::DeleteEmployee(int p)
{
for(int i=p-1;i<count;i++)
{
e[i].firstname=e[i+1].firstname;
e[i].lastname=e[i+1].lastname;
e[i].hwages=e[i+1].hwages;
}
count--;
}
int main()
{
Employee e[8];
Do
{
cout<<”Employee Details”<<endl;
cout<<”**************************”
cout<<”1.Display All Employees”<<endl;
cout<<”2.Display a single employee”<<endl;
cout<<”3.Add an Employee”<<endl;
cout<<”4.Delte an Employee”<<endl;
cout<<”5.exit”<<endl;
cout<<”Enter Your Choice”<<endl;
cin>>choice
switch(choice)
{
Case 1:for(int i=0;i<8;i++)
e[i].DisplayEmployee();
Break;
Case 2: Cout<<"Enter employee first name ";
char *fname
cin>>fname;
e.DisplaySingle(name);
break;
Case 3:cout<<"Enter firstname";
char *fname;
cin>>fname;
e.AddEmployee(fname);
Break;
Case 4:cout<<"Enter position";
int pos;
cin>>pos;
e.DeleteEmployee(pos)
break;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.