Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify these two programs to create a stack to store a data object called account, which has three fields: account_number(int),name(string), and balance (double). #include #include

Modify these two programs to create a stack to store a data object called account, which has three fields: account_number(int),name(string), and balance (double).

#include

#include

using namespace std;

class node

{

public:

int account_number;

string name;

double balance;

node * next;

public:

node(int v, string n, double b);

};

node::node(int v, string n, double b)

{

this->account_number = v;

this->name = n;

this->balance = b;

this->next = NULL;

}

class Account_Stack

{

private:

node * top;

public:

Account_Stack();

~Account_Stack();

bool isEmpty();

void push(node * n);

node * pop();

};

Account_Stack::Account_Stack()

{

top = NULL;

}

Account_Stack::~Account_Stack()

{

node * temp = top;

while(top != NULL)

{

top = top->next;

delete temp;

temp = top;

}

}

bool Account_Stack::isEmpty()

{

if(top==NULL) return true;

else return false;

}

void Account_Stack::push(node * n)

{

// your code goes here

// push n into the stack

}

node * Account_Stack::pop()

{

if(isEmpty()==false)

{

// your code goes here

// pop (and return) the top node out of the stack

}

else return NULL;

}

int main()

{

Account_Stack instac;

node * n1 = new node(2002, "Janet Smith", 100.99);

node * n2 = new node(1001, "Alex Bush", 99.88);

node * n3 = new node(3003, "John Rosa", 5.55);

instac.push(n1);

instac.push(n2);

instac.push(n3);

node * temp = instac.pop();

while(temp != NULL)

{

cout << temp->name << endl;

temp = instac.pop();

}

return 1;

}

/*

// after a successful implementation, running this program

// the following result will be shown

John Rosa

Alex Bush

Janet Smith

*/

Second Prg:

#include

#include

using namespace std;

class node

{

public:

int account_number;

string name;

double balance;

public:

node(int v, string n, double b);

};

node::node(int v, string n, double b)

{

this->account_number = v;

this->name = n;

this->balance = b;

}

class Account_Stack

{

private:

node ** mystack; //mystack is an array of pointers to node

int size;

int current_index;

public:

Account_Stack(int size);

~Account_Stack(int size);

bool isFull();

bool isEmpty();

void push(node * n);

node * pop();

};

Account_Stack::Account_Stack(int size)

{

//your code goes here

//allocate space for array mystack, which s an array of pointers (to

node)

this->size = size;

current_index = 0;

}

Account_Stack::~Account_Stack()

{

delete [] mystack;

}

bool Account_Stack::isFull()

{

if(current_index==size) return true;

else return false;

}

bool Account_Stack::isEmpty()

{

if(current_index==0) return true;

else return false;

}

void Account_Stack::push(node * n)

{

if(isFull()==false)

{

// your code goes here

// push n into the stack

}

}

node * Account_Stack::pop()

{

if(isEmpty()==false)

{

// your code goes here

// pop (and return) the top node out of the stack

}

else return NULL;

}

int main()

{

Account_Stack instac(50);

node * n1 = new node(2002, "Janet Smith", 100.99);

node * n2 = new node(1001, "Alex Bush", 99.88);

node * n3 = new node(3003, "John Rosa", 5.55);

instac.push(n1);

instac.push(n2);

instac.push(n3);

cout << instac.pop()->name << endl;

cout << instac.pop()->name << endl;

cout << instac.pop()->name << endl;

return 1;

}

/*

// after a successful implementation, running this program

// the following result will be shown

John Rosa

Alex Bush

Janet Smith

*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago

Question

Examine various types of executive compensation plans.

Answered: 1 week ago

Question

1. What is the meaning and definition of banks ?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago