Answer to Question #51289 in C++ for joney

Question #51289
1- define an employee class that has the following info:
name (as string) , ID (int)
2- ask the user to enter the number of employees then define a stack of employees and read the employees' data in the stack from keyboard
3- display the data from the stack on screen
1
Expert's answer
2015-03-13T03:51:15-0400
#include <iostream>
#include <string>
#include <stack>
using namespace std;
class Employee
{
public:
string name;
int ID;
Employee(string n, int m)
{
name = n;
ID = m;
}
};
int main()
{
int quantity;
string InName;
int InID;
cout << "Please enter the number of employees: ";
cin >> quantity;
std::stack <string> NameStack;
std::stack <int> IDStack;
for (int i = 0; i < quantity; i++)
{
cout << "Please enter the name of employee: ";
cin >> InName;
cout << "Please enter the ID of employee: ";
cin >> InID;
Employee *LastIn = new Employee(InName, InID);
NameStack.push(InName);
IDStack.push(InID);
}
cout << "Popping out elements...\n";
int i = 1;
while (!NameStack.empty())
{
cout << "Employee # " << i << "\n";
std::cout << ' ' << NameStack.top();
NameStack.pop();
std::cout << ' ' << IDStack.top();
IDStack.pop();
cout << '\n';
i++;
}
cout << '\n';
system&#40;"pause"&#41;;
return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS