Question: Write a program to implement a stack for the same data and show its implementation. Here is the structure and class definitions you will need

Write a program to implement a stack for the same data and show its implementation. Here is the structure and class definitions you will need for this problem.

struct StackItem

{

string fname;

string lname;

double salary;

StackItem *next;

};

class Stack

{

private:

StackItem *top;

bool isempty;

public:

Stack()

{

top=NULL;

isempty=true;

}

void push(StackItem *item);

void pop();

};

Write definitions for the push and pop functions. Use the following main function to test your code.

int main()

{

ifstream fin;

fin.open("HW3Data.dat");

Stack my_Stack;

string fname, lname;

double salary;

StackItem *item=new StackItem;

while(fin>>fname>>lname>>salary)

{

item->fname=fname;

item->lname=lname;

item->salary=salary;

my_Stack.push(item);

}

for (int i=0;i<9;++i)

my_Stack.pop();

return 0;

}

You must get the following output.

John Harris 50000

Lisa Smith 75000.5

Adam Johnson 68500.1

Sheila Smith 150000

Tristen Major 75800.8

Yannic Lennart 58000.6

Lorena Emil 43000

Tereza Santeri 48000

Stack is empty. Nothing to remove.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!