Problem: Design an employee class that stores the following members: employee id
ID: 3838125 • Letter: P
Question
Problem: Design an employee class that stores the following members: employee id number Idnum: employee name Name: Salary: employee salary Get employee gets info of the employee Use constructor and destructor, overloading operator and any other methods that you need. Create templates for a dynamic stack that can hold objects of the class described above along with any other data types. The program should have a loop that asks the user if he or she wishes to add or drop an employee. At any stage, user should able to display the stack contents. When the user finishes the program, it should display the final contents of the stack. Test your program for set of 5 names. 2nd Part: Rewrite the above problem for a dynamic queue template and test it.Explanation / Answer
PROGRAM CODE:
#include <iostream>
using namespace std;
class Employee
{
private:
int idnum;
string name;
double salary;
public:
Employee(int id, string n, double s)
{
idnum = id;
name = n;
salary = s;
}
string getEmployee()
{
return "Name: " + name + " ID #: " + idnum + " Salary: " + salary;
}
friend ostream& operator<<(ostream& out, Employee &e)
{
out<<getEmployee()<<endl;
return out;
}
};
int main() {
Stack<Employee> stack;
Queue<Employee> queue;
int choice;
cout<<"1. Stack Processing 2. Queue Processing Enter your choice ";
cin>>choice;
while(true)
{
cout<<"1. Enter new employee 2. Delete employee 3. View all employees 4. Quit ";
cout<<"Please make a selection <1, 2, 3, or 4>: ";
int option;
cin>>option;
if(option == 1)
{
string name;
int id;
double sal;
cout<<"You selected to add an employee to the Stack list...."<<endl<<endl;
cout<<"Please enter the following information: ";
cout<<"Name: ";
cin>>name;
cout<<" ID #: ";
cin>>id;
cout<<" Salary: ";
cin>>sal;
Employee e1(id, name,sal);
if(choice == 1)
stack.push(e1);
else queue.push(e1);
}
else if(option == 2)
{
int id;
cout<<"You selected to delete an employee from the Stack list...."<<endl<<endl;
if(choice == 1)
stack.pop();
else queue.pop();
}
else if(option == 3)
{
if(choice == 1)
{
Stack<Employee> subStack;
while(!stack.empty())
{
cout<<stack.top();
subStack.push(stack.top());
stack.pop();
}
while(!subStack.empty())
{
stack.push(subStack.top());
subStack.pop();
}
}
else
{
Queue<Employee> sub;
while(!stack.empty())
{
cout<<stack.top();
sub.push(stack.top());
stack.pop();
}
while(!sub.empty())
{
stack.push(sub.top());
sub.pop();
}
}
}
else break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.