Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help completing this code. Thank you Understand, modify, and test this program based on the following requirements. Add and implement the following method

I need help completing this code.

Thank you

Understand, modify, and test this program based on the following requirements.

Add and implement the following method in class Account_List. This method will create an instance of node and insert it to the linkedlist in increasing order of account number.

void insert_in_order_account(int v, string n, double b)

Add and implement the following method in class Account_List. This method will create an instance of node and insert it to the linkedlist in decreasing order of account balance.

void insert_in_order_balance(int v, string n, double b)

Add and implement the following method in class Account_List. This method will delete the account (node) in the linkedlist that has the same name as the parameter.

void remove(string name)

Add and implement the following method in class Account_List. This method will sort the accounts (nodes) in the linkedlist by increasing order of account number. In this method, you need to use the insertion sort algorithm we talked in class.

void insertion_sort_by_account()

Test your program using the following code:

int main()

{

Account_List List;

List.insert_in_order_account(2002, "Janet Smith", 100.99);

List.insert_in_order_account(1001, "Alex Bush", 99.88);

List.insert_in_order_account(3003, "John Rosa", 5.55);

cout << "List is in increasing order of account number ";

List.list_all();

cout <

List.remove("Janet Smith");

List.remove("Alex Bush");

cout << "Two nodes are removed ";

List.list_all();

cout <

List.insert_in_order_balance(2002, "Janet Smith", 100.99);

List.insert_in_order_balance(1001, "Alex Bush", 99.88);

cout << "List is in decreasing order of balance ";

List.list_all();

cout <

List.insertion_sort_by_account();

cout << "List is in increasing order of account number ";

List.list_all();

cout <

return 1;

}

The result should be:

List is in increasing order of account number

1001 Alex Bush 99.88

2002 Janet Smith 100.99

3003 John Rosa 5.55

Two nodes are removed

3003 John Rosa 5.55

List is in decreasing order of balance

2002 Janet Smith 100.99

1001 Alex Bush 99.88

3003 John Rosa 5.55

List is in increasing order of account number

1001 Alex Bush 99.88

2002 Janet Smith 100.99

3003 John Rosa 5.55

Understand, Modify, Test this Code

#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_List

{

private:

node * head;

public:

Account_List();

~Account_List();

void insert_to_head(int v, string n, double b);

void list_all();

bool search(string name);

};

Account_List::Account_List()

{

head = NULL;

}

Account_List::~Account_List()

{

while(head != NULL)

{

node * temp = head;

head = head->next;

delete temp;

}

}

void Account_List::insert_to_head(int v, string n, double b)

{

node * temp = new node(v, n, b);

temp->next = head;

head = temp;

}

void Account_List::list_all()

{

node * temp= head;

while(temp!=NULL)

{

cout << temp->account_number << "\t" << temp->name <<

"\t" << temp->balance << endl;

temp = temp->next;

}

}

bool Account_List::search(string name)

{

node * temp= head;

while(temp!=NULL)

{

if(temp->name.compare(name)==0) return true;

else temp = temp->next;

}

return false;

}

int main()

{

Account_List List;

List.insert_to_head(2002, "Janet Smith", 100.99);

List.insert_to_head(1001, "Alex Bush", 99.88);

List.insert_to_head(3003, "John Rosa", 5.55);

List.list_all();

if(List.search("Alex Bush")==true) cout << "Found Alex ";

else cout << "Cound not find Alex ";

if(List.search("Bush Alex")==true) cout << "Found Bush ";

else cout << "Cound not Bush ";

return 1;

}

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

More Books

Students also viewed these Databases questions